diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java index a69a76e793fd..1490b125121d 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java @@ -275,7 +275,7 @@ private void invalidateSchemaCacheOfOldLeaders( requestIndex.get(), dataNodeLocation); // set req final TConsensusGroupId consensusGroupId = entry.getKey(); - final String database = getPartitionManager().getRegionStorageGroup(consensusGroupId); + final String database = getPartitionManager().getRegionDatabase(consensusGroupId); invalidateSchemaCacheRequestHandler.putRequest(requestIndex.get(), database); requestIndex.incrementAndGet(); }); diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java index 29562e1350c3..bcaaa17b963e 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java @@ -1194,8 +1194,8 @@ public GetSeriesSlotListResp getSeriesSlotList(TGetSeriesSlotListReq req) { * @param regionId regionId * @return database name */ - public String getRegionStorageGroup(TConsensusGroupId regionId) { - return partitionInfo.getRegionStorageGroup(regionId); + public String getRegionDatabase(TConsensusGroupId regionId) { + return partitionInfo.getRegionDatabase(regionId); } /** diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionMetrics.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionMetrics.java index 798c38e1c296..38e64dbd2f7a 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionMetrics.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionMetrics.java @@ -345,8 +345,8 @@ private static void bindDatabasePartitionMetricsWhenUpdate( try { return manager.getRegionGroupCount(database, TConsensusGroupType.SchemaRegion); } catch (DatabaseNotExistsException e) { - LOGGER.warn("Error when counting SchemaRegionGroups in Database: {}", database, e); - return -1; + LOGGER.info("Error when counting SchemaRegionGroups in Database: {}", database, e); + return 0; } }, Tag.NAME.toString(), @@ -361,8 +361,8 @@ private static void bindDatabasePartitionMetricsWhenUpdate( try { return manager.getRegionGroupCount(database, TConsensusGroupType.DataRegion); } catch (DatabaseNotExistsException e) { - LOGGER.warn("Error when counting DataRegionGroups in Database: {}", database, e); - return -1; + LOGGER.info("Error when counting DataRegionGroups in Database: {}", database, e); + return 0; } }, Tag.NAME.toString(), diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/PipeLeaderChangeHandler.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/PipeLeaderChangeHandler.java index 284779fcb039..9121ba3caa44 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/PipeLeaderChangeHandler.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/PipeLeaderChangeHandler.java @@ -83,7 +83,7 @@ public void onConsensusGroupStatisticsChanged(ConsensusGroupStatisticsChangeEven .forEach( (regionGroupId, pair) -> { final String databaseName = - configManager.getPartitionManager().getRegionStorageGroup(regionGroupId); + configManager.getPartitionManager().getRegionDatabase(regionGroupId); // Pipe only collect user's data, filter metric database here. // DatabaseName may be null for config region group if (Objects.isNull(databaseName) diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java index a6ee20ea4d7f..85a427cfab9a 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java @@ -273,7 +273,7 @@ public List getRegionMaintainEntryList() { } /** - * Thread-safely pre-delete the specific StorageGroup. + * Thread-safely pre-delete the specific database. * * @param preDeleteDatabasePlan PreDeleteStorageGroupPlan * @return {@link TSStatusCode#SUCCESS_STATUS} @@ -281,8 +281,8 @@ public List getRegionMaintainEntryList() { public TSStatus preDeleteDatabase(PreDeleteDatabasePlan preDeleteDatabasePlan) { final PreDeleteDatabasePlan.PreDeleteType preDeleteType = preDeleteDatabasePlan.getPreDeleteType(); - final String storageGroup = preDeleteDatabasePlan.getStorageGroup(); - DatabasePartitionTable databasePartitionTable = databasePartitionTables.get(storageGroup); + final String database = preDeleteDatabasePlan.getStorageGroup(); + DatabasePartitionTable databasePartitionTable = databasePartitionTables.get(database); if (databasePartitionTable == null) { return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()); } @@ -305,12 +305,12 @@ public boolean isDatabasePreDeleted(String database) { } /** - * Thread-safely delete StorageGroup. + * Thread-safely delete database. * - * @param plan DeleteStorageGroupPlan + * @param plan DeleteDatabasePlan */ public void deleteDatabase(DeleteDatabasePlan plan) { - // Clean the StorageGroupTable cache + // Clean the databaseTable cache databasePartitionTables.remove(plan.getName()); } @@ -325,24 +325,24 @@ public DataSet getSchemaPartition(GetSchemaPartitionPlan plan) { // TODO: Replace this map with new SchemaPartition Map schemaPartition = new ConcurrentHashMap<>(); - if (plan.getPartitionSlotsMap().size() == 0) { + if (plan.getPartitionSlotsMap().isEmpty()) { // Return all SchemaPartitions when the queried PartitionSlots are empty databasePartitionTables.forEach( - (storageGroup, databasePartitionTable) -> { + (database, databasePartitionTable) -> { if (databasePartitionTable.isNotPreDeleted()) { - schemaPartition.put(storageGroup, new SchemaPartitionTable()); + schemaPartition.put(database, new SchemaPartitionTable()); databasePartitionTable.getSchemaPartition( - new ArrayList<>(), schemaPartition.get(storageGroup)); + new ArrayList<>(), schemaPartition.get(database)); - if (schemaPartition.get(storageGroup).getSchemaPartitionMap().isEmpty()) { + if (schemaPartition.get(database).getSchemaPartitionMap().isEmpty()) { // Remove empty Map - schemaPartition.remove(storageGroup); + schemaPartition.remove(database); } } }); } else { - // Return the SchemaPartition for each StorageGroup + // Return the SchemaPartition for each database plan.getPartitionSlotsMap() .forEach( (database, partitionSlots) -> { @@ -506,16 +506,16 @@ public DataSet getSchemaNodeManagementPartition(List matchedDatabases) { matchedDatabases.stream() .filter(this::isDatabaseExisted) .forEach( - storageGroup -> { - schemaPartitionMap.put(storageGroup, new SchemaPartitionTable()); + database -> { + schemaPartitionMap.put(database, new SchemaPartitionTable()); databasePartitionTables - .get(storageGroup) - .getSchemaPartition(new ArrayList<>(), schemaPartitionMap.get(storageGroup)); + .get(database) + .getSchemaPartition(new ArrayList<>(), schemaPartitionMap.get(database)); - if (schemaPartitionMap.get(storageGroup).getSchemaPartitionMap().isEmpty()) { + if (schemaPartitionMap.get(database).getSchemaPartitionMap().isEmpty()) { // Remove empty Map - schemaPartitionMap.remove(storageGroup); + schemaPartitionMap.remove(database); } }); @@ -534,10 +534,10 @@ public DataSet getRegionInfoList(GetRegionInfoListPlan regionsInfoPlan) { return regionResp; } TShowRegionReq showRegionReq = regionsInfoPlan.getShowRegionReq(); - final List storageGroups = showRegionReq != null ? showRegionReq.getDatabases() : null; + final List databases = showRegionReq != null ? showRegionReq.getDatabases() : null; databasePartitionTables.forEach( - (storageGroup, databasePartitionTable) -> { - if (storageGroups != null && !storageGroups.contains(storageGroup)) { + (database, databasePartitionTable) -> { + if (databases != null && !databases.contains(database)) { return; } regionInfoList.addAll(databasePartitionTable.getRegionInfoList(regionsInfoPlan)); @@ -602,7 +602,7 @@ public TSStatus removeRegionLocation(RemoveRegionLocationPlan req) { * @param regionId regionId * @return database name */ - public String getRegionStorageGroup(TConsensusGroupId regionId) { + public String getRegionDatabase(TConsensusGroupId regionId) { Optional sgPartitionTableOptional = databasePartitionTables.values().stream() .filter(s -> s.containRegionGroup(regionId)) @@ -617,9 +617,9 @@ public String getRegionStorageGroup(TConsensusGroupId regionId) { /** * Only Leader use this interface. Filter unassigned SchemaPartitionSlots. * - * @param partitionSlotsMap Map> - * @return Map>, SchemaPartitionSlots that is not - * assigned in partitionSlotsMap + * @param partitionSlotsMap Map> + * @return Map>, SchemaPartitionSlots that is not assigned in + * partitionSlotsMap */ public Map> filterUnassignedSchemaPartitionSlots( Map> partitionSlotsMap) { @@ -642,9 +642,9 @@ public Map> filterUnassignedSchemaPartitionSl /** * Only Leader use this interface. Filter unassigned SchemaPartitionSlots * - * @param partitionSlotsMap Map> - * @return Map>, DataPartitionSlots - * that is not assigned in partitionSlotsMap + * @param partitionSlotsMap Map> + * @return Map>, DataPartitionSlots that is not + * assigned in partitionSlotsMap */ public Map> filterUnassignedDataPartitionSlots( Map> partitionSlotsMap) { @@ -806,8 +806,8 @@ public int countDataNodeScatterWidth( * * @param database DatabaseName * @param type SchemaRegion or DataRegion - * @return Number of Regions currently owned by the specific StorageGroup - * @throws DatabaseNotExistsException When the specific StorageGroup doesn't exist + * @return Number of Regions currently owned by the specific database + * @throws DatabaseNotExistsException When the specific database doesn't exist */ public int getRegionGroupCount(String database, TConsensusGroupType type) throws DatabaseNotExistsException { @@ -865,7 +865,9 @@ public List getAllRegionGroupIds(String database, TConsensusG * @return The assigned SeriesPartitionSlots count */ public int getAssignedSeriesPartitionSlotsCount(String database) { - return databasePartitionTables.get(database).getAssignedSeriesPartitionSlotsCount(); + return Optional.ofNullable(databasePartitionTables.get(database)) + .map(DatabasePartitionTable::getAssignedSeriesPartitionSlotsCount) + .orElse(0); } /** @@ -877,13 +879,15 @@ public int getAssignedSeriesPartitionSlotsCount(String database) { * @return The assigned TimePartitionSlots count */ public long getAssignedTimePartitionSlotsCount(String database) { - return databasePartitionTables.get(database).getTimeSlotCount(); + return Optional.ofNullable(databasePartitionTables.get(database)) + .map(DatabasePartitionTable::getTimeSlotCount) + .orElse(0L); } /** - * Get the DataNodes who contain the specific StorageGroup's Schema or Data. + * Get the DataNodes who contain the specific database's Schema or Data. * - * @param database The specific StorageGroup's name + * @param database The specific database's name * @param type SchemaRegion or DataRegion * @return Set {@literal <}TDataNodeLocation{@literal >}, the related DataNodes */ @@ -897,7 +901,7 @@ public Set getDatabaseRelatedDataNodes( * * @param database DatabaseName * @param type SchemaRegion or DataRegion - * @return The StorageGroup's Running or Available Regions that sorted by the number of allocated + * @return The database's Running or Available Regions that sorted by the number of allocated * slots */ public List> getRegionGroupSlotsCounter( @@ -955,12 +959,12 @@ public boolean processTakeSnapshot(File snapshotDir) throws TException, IOExcept // serialize nextRegionGroupId ReadWriteIOUtils.write(nextRegionGroupId.get(), bufferedOutputStream); - // serialize StorageGroupPartitionTable + // serialize databasePartitionTable ReadWriteIOUtils.write(databasePartitionTables.size(), bufferedOutputStream); - for (Map.Entry storageGroupPartitionTableEntry : + for (Map.Entry databasePartitionTableEntry : databasePartitionTables.entrySet()) { - ReadWriteIOUtils.write(storageGroupPartitionTableEntry.getKey(), bufferedOutputStream); - storageGroupPartitionTableEntry.getValue().serialize(bufferedOutputStream, protocol); + ReadWriteIOUtils.write(databasePartitionTableEntry.getKey(), bufferedOutputStream); + databasePartitionTableEntry.getValue().serialize(bufferedOutputStream, protocol); } // serialize regionCleanList @@ -1012,17 +1016,16 @@ public void processLoadSnapshot(final File snapshotDir) throws TException, IOExc // start to restore nextRegionGroupId.set(ReadWriteIOUtils.readInt(fileInputStream)); - // restore StorageGroupPartitionTable + // restore databasePartitionTable int length = ReadWriteIOUtils.readInt(fileInputStream); for (int i = 0; i < length; i++) { - final String storageGroup = ReadWriteIOUtils.readString(fileInputStream); - if (storageGroup == null) { - throw new IOException("Failed to load snapshot because get null StorageGroup name"); + final String database = ReadWriteIOUtils.readString(fileInputStream); + if (database == null) { + throw new IOException("Failed to load snapshot because get null database name"); } - final DatabasePartitionTable databasePartitionTable = - new DatabasePartitionTable(storageGroup); + final DatabasePartitionTable databasePartitionTable = new DatabasePartitionTable(database); databasePartitionTable.deserialize(fileInputStream, protocol); - databasePartitionTables.put(storageGroup, databasePartitionTable); + databasePartitionTables.put(database, databasePartitionTable); } // restore deletedRegionSet diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RegionMaintainHandler.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RegionMaintainHandler.java index dca6fac949e4..7ed0925f1493 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RegionMaintainHandler.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RegionMaintainHandler.java @@ -157,8 +157,8 @@ public TSStatus createNewRegionPeer(TConsensusGroupId regionId, TDataNodeLocatio currentPeerNodes = Collections.emptyList(); } - String storageGroup = configManager.getPartitionManager().getRegionStorageGroup(regionId); - TCreatePeerReq req = new TCreatePeerReq(regionId, currentPeerNodes, storageGroup); + String database = configManager.getPartitionManager().getRegionDatabase(regionId); + TCreatePeerReq req = new TCreatePeerReq(regionId, currentPeerNodes, database); status = (TSStatus) diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java index ccdd0e76b312..8b6aceb9c300 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java @@ -144,7 +144,7 @@ public void executeFromCalculateInfoForTask(ConfigNodeProcedureEnv env) { .forEach( (regionGroupId, regionLeaderNodeId) -> { final String databaseName = - env.getConfigManager().getPartitionManager().getRegionStorageGroup(regionGroupId); + env.getConfigManager().getPartitionManager().getRegionDatabase(regionGroupId); final PipeTaskMeta currentPipeTaskMeta = currentConsensusGroupId2PipeTaskMeta.get(regionGroupId.getId()); if (databaseName != null diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/CreatePipeProcedureV2.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/CreatePipeProcedureV2.java index b744ef50d6f9..c552191a856c 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/CreatePipeProcedureV2.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/CreatePipeProcedureV2.java @@ -180,9 +180,7 @@ public void executeFromCalculateInfoForTask(ConfigNodeProcedureEnv env) { .forEach( (regionGroupId, regionLeaderNodeId) -> { final String databaseName = - env.getConfigManager() - .getPartitionManager() - .getRegionStorageGroup(regionGroupId); + env.getConfigManager().getPartitionManager().getRegionDatabase(regionGroupId); if (databaseName != null && !databaseName.equals(SchemaConstant.SYSTEM_DATABASE) && !databaseName.startsWith(SchemaConstant.SYSTEM_DATABASE + ".")) {