Skip to content

Commit 4a76dfb

Browse files
Fix ConfigNode Partition Metric NPE bug apache#14144
Signed-off-by: OneSizeFitQuorum <[email protected]>
1 parent 43ed865 commit 4a76dfb

File tree

8 files changed

+62
-61
lines changed

8 files changed

+62
-61
lines changed

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private void invalidateSchemaCacheOfOldLeaders(
275275
requestIndex.get(), dataNodeLocation);
276276
// set req
277277
final TConsensusGroupId consensusGroupId = entry.getKey();
278-
final String database = getPartitionManager().getRegionStorageGroup(consensusGroupId);
278+
final String database = getPartitionManager().getRegionDatabase(consensusGroupId);
279279
invalidateSchemaCacheRequestHandler.putRequest(requestIndex.get(), database);
280280
requestIndex.incrementAndGet();
281281
});

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,8 @@ public GetSeriesSlotListResp getSeriesSlotList(TGetSeriesSlotListReq req) {
11941194
* @param regionId regionId
11951195
* @return database name
11961196
*/
1197-
public String getRegionStorageGroup(TConsensusGroupId regionId) {
1198-
return partitionInfo.getRegionStorageGroup(regionId);
1197+
public String getRegionDatabase(TConsensusGroupId regionId) {
1198+
return partitionInfo.getRegionDatabase(regionId);
11991199
}
12001200

12011201
/**

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionMetrics.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ private static void bindDatabasePartitionMetricsWhenUpdate(
345345
try {
346346
return manager.getRegionGroupCount(database, TConsensusGroupType.SchemaRegion);
347347
} catch (DatabaseNotExistsException e) {
348-
LOGGER.warn("Error when counting SchemaRegionGroups in Database: {}", database, e);
349-
return -1;
348+
LOGGER.info("Error when counting SchemaRegionGroups in Database: {}", database, e);
349+
return 0;
350350
}
351351
},
352352
Tag.NAME.toString(),
@@ -361,8 +361,8 @@ private static void bindDatabasePartitionMetricsWhenUpdate(
361361
try {
362362
return manager.getRegionGroupCount(database, TConsensusGroupType.DataRegion);
363363
} catch (DatabaseNotExistsException e) {
364-
LOGGER.warn("Error when counting DataRegionGroups in Database: {}", database, e);
365-
return -1;
364+
LOGGER.info("Error when counting DataRegionGroups in Database: {}", database, e);
365+
return 0;
366366
}
367367
},
368368
Tag.NAME.toString(),

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/PipeLeaderChangeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void onConsensusGroupStatisticsChanged(ConsensusGroupStatisticsChangeEven
8383
.forEach(
8484
(regionGroupId, pair) -> {
8585
final String databaseName =
86-
configManager.getPartitionManager().getRegionStorageGroup(regionGroupId);
86+
configManager.getPartitionManager().getRegionDatabase(regionGroupId);
8787
// Pipe only collect user's data, filter metric database here.
8888
// DatabaseName may be null for config region group
8989
if (Objects.isNull(databaseName)

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,16 @@ public List<RegionMaintainTask> getRegionMaintainEntryList() {
273273
}
274274

275275
/**
276-
* Thread-safely pre-delete the specific StorageGroup.
276+
* Thread-safely pre-delete the specific database.
277277
*
278278
* @param preDeleteDatabasePlan PreDeleteStorageGroupPlan
279279
* @return {@link TSStatusCode#SUCCESS_STATUS}
280280
*/
281281
public TSStatus preDeleteDatabase(PreDeleteDatabasePlan preDeleteDatabasePlan) {
282282
final PreDeleteDatabasePlan.PreDeleteType preDeleteType =
283283
preDeleteDatabasePlan.getPreDeleteType();
284-
final String storageGroup = preDeleteDatabasePlan.getStorageGroup();
285-
DatabasePartitionTable databasePartitionTable = databasePartitionTables.get(storageGroup);
284+
final String database = preDeleteDatabasePlan.getStorageGroup();
285+
DatabasePartitionTable databasePartitionTable = databasePartitionTables.get(database);
286286
if (databasePartitionTable == null) {
287287
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
288288
}
@@ -305,12 +305,12 @@ public boolean isDatabasePreDeleted(String database) {
305305
}
306306

307307
/**
308-
* Thread-safely delete StorageGroup.
308+
* Thread-safely delete database.
309309
*
310-
* @param plan DeleteStorageGroupPlan
310+
* @param plan DeleteDatabasePlan
311311
*/
312312
public void deleteDatabase(DeleteDatabasePlan plan) {
313-
// Clean the StorageGroupTable cache
313+
// Clean the databaseTable cache
314314
databasePartitionTables.remove(plan.getName());
315315
}
316316

@@ -325,24 +325,24 @@ public DataSet getSchemaPartition(GetSchemaPartitionPlan plan) {
325325
// TODO: Replace this map with new SchemaPartition
326326
Map<String, SchemaPartitionTable> schemaPartition = new ConcurrentHashMap<>();
327327

328-
if (plan.getPartitionSlotsMap().size() == 0) {
328+
if (plan.getPartitionSlotsMap().isEmpty()) {
329329
// Return all SchemaPartitions when the queried PartitionSlots are empty
330330
databasePartitionTables.forEach(
331-
(storageGroup, databasePartitionTable) -> {
331+
(database, databasePartitionTable) -> {
332332
if (databasePartitionTable.isNotPreDeleted()) {
333-
schemaPartition.put(storageGroup, new SchemaPartitionTable());
333+
schemaPartition.put(database, new SchemaPartitionTable());
334334

335335
databasePartitionTable.getSchemaPartition(
336-
new ArrayList<>(), schemaPartition.get(storageGroup));
336+
new ArrayList<>(), schemaPartition.get(database));
337337

338-
if (schemaPartition.get(storageGroup).getSchemaPartitionMap().isEmpty()) {
338+
if (schemaPartition.get(database).getSchemaPartitionMap().isEmpty()) {
339339
// Remove empty Map
340-
schemaPartition.remove(storageGroup);
340+
schemaPartition.remove(database);
341341
}
342342
}
343343
});
344344
} else {
345-
// Return the SchemaPartition for each StorageGroup
345+
// Return the SchemaPartition for each database
346346
plan.getPartitionSlotsMap()
347347
.forEach(
348348
(database, partitionSlots) -> {
@@ -506,16 +506,16 @@ public DataSet getSchemaNodeManagementPartition(List<String> matchedDatabases) {
506506
matchedDatabases.stream()
507507
.filter(this::isDatabaseExisted)
508508
.forEach(
509-
storageGroup -> {
510-
schemaPartitionMap.put(storageGroup, new SchemaPartitionTable());
509+
database -> {
510+
schemaPartitionMap.put(database, new SchemaPartitionTable());
511511

512512
databasePartitionTables
513-
.get(storageGroup)
514-
.getSchemaPartition(new ArrayList<>(), schemaPartitionMap.get(storageGroup));
513+
.get(database)
514+
.getSchemaPartition(new ArrayList<>(), schemaPartitionMap.get(database));
515515

516-
if (schemaPartitionMap.get(storageGroup).getSchemaPartitionMap().isEmpty()) {
516+
if (schemaPartitionMap.get(database).getSchemaPartitionMap().isEmpty()) {
517517
// Remove empty Map
518-
schemaPartitionMap.remove(storageGroup);
518+
schemaPartitionMap.remove(database);
519519
}
520520
});
521521

@@ -534,10 +534,10 @@ public DataSet getRegionInfoList(GetRegionInfoListPlan regionsInfoPlan) {
534534
return regionResp;
535535
}
536536
TShowRegionReq showRegionReq = regionsInfoPlan.getShowRegionReq();
537-
final List<String> storageGroups = showRegionReq != null ? showRegionReq.getDatabases() : null;
537+
final List<String> databases = showRegionReq != null ? showRegionReq.getDatabases() : null;
538538
databasePartitionTables.forEach(
539-
(storageGroup, databasePartitionTable) -> {
540-
if (storageGroups != null && !storageGroups.contains(storageGroup)) {
539+
(database, databasePartitionTable) -> {
540+
if (databases != null && !databases.contains(database)) {
541541
return;
542542
}
543543
regionInfoList.addAll(databasePartitionTable.getRegionInfoList(regionsInfoPlan));
@@ -602,7 +602,7 @@ public TSStatus removeRegionLocation(RemoveRegionLocationPlan req) {
602602
* @param regionId regionId
603603
* @return database name
604604
*/
605-
public String getRegionStorageGroup(TConsensusGroupId regionId) {
605+
public String getRegionDatabase(TConsensusGroupId regionId) {
606606
Optional<DatabasePartitionTable> sgPartitionTableOptional =
607607
databasePartitionTables.values().stream()
608608
.filter(s -> s.containRegionGroup(regionId))
@@ -617,9 +617,9 @@ public String getRegionStorageGroup(TConsensusGroupId regionId) {
617617
/**
618618
* Only Leader use this interface. Filter unassigned SchemaPartitionSlots.
619619
*
620-
* @param partitionSlotsMap Map<StorageGroupName, List<TSeriesPartitionSlot>>
621-
* @return Map<StorageGroupName, List<TSeriesPartitionSlot>>, SchemaPartitionSlots that is not
622-
* assigned in partitionSlotsMap
620+
* @param partitionSlotsMap Map<database, List<TSeriesPartitionSlot>>
621+
* @return Map<database, List<TSeriesPartitionSlot>>, SchemaPartitionSlots that is not assigned in
622+
* partitionSlotsMap
623623
*/
624624
public Map<String, List<TSeriesPartitionSlot>> filterUnassignedSchemaPartitionSlots(
625625
Map<String, List<TSeriesPartitionSlot>> partitionSlotsMap) {
@@ -642,9 +642,9 @@ public Map<String, List<TSeriesPartitionSlot>> filterUnassignedSchemaPartitionSl
642642
/**
643643
* Only Leader use this interface. Filter unassigned SchemaPartitionSlots
644644
*
645-
* @param partitionSlotsMap Map<StorageGroupName, Map<TSeriesPartitionSlot, TTimeSlotList>>
646-
* @return Map<StorageGroupName, Map<TSeriesPartitionSlot, TTimeSlotList>>, DataPartitionSlots
647-
* that is not assigned in partitionSlotsMap
645+
* @param partitionSlotsMap Map<database, Map<TSeriesPartitionSlot, TTimeSlotList>>
646+
* @return Map<database, Map<TSeriesPartitionSlot, TTimeSlotList>>, DataPartitionSlots that is not
647+
* assigned in partitionSlotsMap
648648
*/
649649
public Map<String, Map<TSeriesPartitionSlot, TTimeSlotList>> filterUnassignedDataPartitionSlots(
650650
Map<String, Map<TSeriesPartitionSlot, TTimeSlotList>> partitionSlotsMap) {
@@ -806,8 +806,8 @@ public int countDataNodeScatterWidth(
806806
*
807807
* @param database DatabaseName
808808
* @param type SchemaRegion or DataRegion
809-
* @return Number of Regions currently owned by the specific StorageGroup
810-
* @throws DatabaseNotExistsException When the specific StorageGroup doesn't exist
809+
* @return Number of Regions currently owned by the specific database
810+
* @throws DatabaseNotExistsException When the specific database doesn't exist
811811
*/
812812
public int getRegionGroupCount(String database, TConsensusGroupType type)
813813
throws DatabaseNotExistsException {
@@ -865,7 +865,9 @@ public List<TConsensusGroupId> getAllRegionGroupIds(String database, TConsensusG
865865
* @return The assigned SeriesPartitionSlots count
866866
*/
867867
public int getAssignedSeriesPartitionSlotsCount(String database) {
868-
return databasePartitionTables.get(database).getAssignedSeriesPartitionSlotsCount();
868+
return Optional.ofNullable(databasePartitionTables.get(database))
869+
.map(DatabasePartitionTable::getAssignedSeriesPartitionSlotsCount)
870+
.orElse(0);
869871
}
870872

871873
/**
@@ -877,13 +879,15 @@ public int getAssignedSeriesPartitionSlotsCount(String database) {
877879
* @return The assigned TimePartitionSlots count
878880
*/
879881
public long getAssignedTimePartitionSlotsCount(String database) {
880-
return databasePartitionTables.get(database).getTimeSlotCount();
882+
return Optional.ofNullable(databasePartitionTables.get(database))
883+
.map(DatabasePartitionTable::getTimeSlotCount)
884+
.orElse(0L);
881885
}
882886

883887
/**
884-
* Get the DataNodes who contain the specific StorageGroup's Schema or Data.
888+
* Get the DataNodes who contain the specific database's Schema or Data.
885889
*
886-
* @param database The specific StorageGroup's name
890+
* @param database The specific database's name
887891
* @param type SchemaRegion or DataRegion
888892
* @return Set {@literal <}TDataNodeLocation{@literal >}, the related DataNodes
889893
*/
@@ -897,7 +901,7 @@ public Set<TDataNodeLocation> getDatabaseRelatedDataNodes(
897901
*
898902
* @param database DatabaseName
899903
* @param type SchemaRegion or DataRegion
900-
* @return The StorageGroup's Running or Available Regions that sorted by the number of allocated
904+
* @return The database's Running or Available Regions that sorted by the number of allocated
901905
* slots
902906
*/
903907
public List<Pair<Long, TConsensusGroupId>> getRegionGroupSlotsCounter(
@@ -955,12 +959,12 @@ public boolean processTakeSnapshot(File snapshotDir) throws TException, IOExcept
955959
// serialize nextRegionGroupId
956960
ReadWriteIOUtils.write(nextRegionGroupId.get(), bufferedOutputStream);
957961

958-
// serialize StorageGroupPartitionTable
962+
// serialize databasePartitionTable
959963
ReadWriteIOUtils.write(databasePartitionTables.size(), bufferedOutputStream);
960-
for (Map.Entry<String, DatabasePartitionTable> storageGroupPartitionTableEntry :
964+
for (Map.Entry<String, DatabasePartitionTable> databasePartitionTableEntry :
961965
databasePartitionTables.entrySet()) {
962-
ReadWriteIOUtils.write(storageGroupPartitionTableEntry.getKey(), bufferedOutputStream);
963-
storageGroupPartitionTableEntry.getValue().serialize(bufferedOutputStream, protocol);
966+
ReadWriteIOUtils.write(databasePartitionTableEntry.getKey(), bufferedOutputStream);
967+
databasePartitionTableEntry.getValue().serialize(bufferedOutputStream, protocol);
964968
}
965969

966970
// serialize regionCleanList
@@ -1012,17 +1016,16 @@ public void processLoadSnapshot(final File snapshotDir) throws TException, IOExc
10121016
// start to restore
10131017
nextRegionGroupId.set(ReadWriteIOUtils.readInt(fileInputStream));
10141018

1015-
// restore StorageGroupPartitionTable
1019+
// restore databasePartitionTable
10161020
int length = ReadWriteIOUtils.readInt(fileInputStream);
10171021
for (int i = 0; i < length; i++) {
1018-
final String storageGroup = ReadWriteIOUtils.readString(fileInputStream);
1019-
if (storageGroup == null) {
1020-
throw new IOException("Failed to load snapshot because get null StorageGroup name");
1022+
final String database = ReadWriteIOUtils.readString(fileInputStream);
1023+
if (database == null) {
1024+
throw new IOException("Failed to load snapshot because get null database name");
10211025
}
1022-
final DatabasePartitionTable databasePartitionTable =
1023-
new DatabasePartitionTable(storageGroup);
1026+
final DatabasePartitionTable databasePartitionTable = new DatabasePartitionTable(database);
10241027
databasePartitionTable.deserialize(fileInputStream, protocol);
1025-
databasePartitionTables.put(storageGroup, databasePartitionTable);
1028+
databasePartitionTables.put(database, databasePartitionTable);
10261029
}
10271030

10281031
// restore deletedRegionSet

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RegionMaintainHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public TSStatus createNewRegionPeer(TConsensusGroupId regionId, TDataNodeLocatio
157157
currentPeerNodes = Collections.emptyList();
158158
}
159159

160-
String storageGroup = configManager.getPartitionManager().getRegionStorageGroup(regionId);
161-
TCreatePeerReq req = new TCreatePeerReq(regionId, currentPeerNodes, storageGroup);
160+
String database = configManager.getPartitionManager().getRegionDatabase(regionId);
161+
TCreatePeerReq req = new TCreatePeerReq(regionId, currentPeerNodes, database);
162162

163163
status =
164164
(TSStatus)

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void executeFromCalculateInfoForTask(ConfigNodeProcedureEnv env) {
144144
.forEach(
145145
(regionGroupId, regionLeaderNodeId) -> {
146146
final String databaseName =
147-
env.getConfigManager().getPartitionManager().getRegionStorageGroup(regionGroupId);
147+
env.getConfigManager().getPartitionManager().getRegionDatabase(regionGroupId);
148148
final PipeTaskMeta currentPipeTaskMeta =
149149
currentConsensusGroupId2PipeTaskMeta.get(regionGroupId.getId());
150150
if (databaseName != null

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/CreatePipeProcedureV2.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ public void executeFromCalculateInfoForTask(ConfigNodeProcedureEnv env) {
180180
.forEach(
181181
(regionGroupId, regionLeaderNodeId) -> {
182182
final String databaseName =
183-
env.getConfigManager()
184-
.getPartitionManager()
185-
.getRegionStorageGroup(regionGroupId);
183+
env.getConfigManager().getPartitionManager().getRegionDatabase(regionGroupId);
186184
if (databaseName != null
187185
&& !databaseName.equals(SchemaConstant.SYSTEM_DATABASE)
188186
&& !databaseName.startsWith(SchemaConstant.SYSTEM_DATABASE + ".")) {

0 commit comments

Comments
 (0)