This is an automated email from the ASF dual-hosted git repository.

yongzao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 67accf77f9 fix exception caused by pre deleted db (#9151)
67accf77f9 is described below

commit 67accf77f92c1b2456ec316cd7f7cb9284722606
Author: Marcos_Zyk <[email protected]>
AuthorDate: Mon Feb 27 18:23:15 2023 +0800

    fix exception caused by pre deleted db (#9151)
---
 .../confignode/manager/ClusterSchemaManager.java   | 50 ++++++++++++++--------
 .../manager/partition/PartitionManager.java        |  4 ++
 .../persistence/partition/PartitionInfo.java       | 26 +++++------
 3 files changed, 48 insertions(+), 32 deletions(-)

diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
index 717a1ca88b..1d949a621e 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
@@ -380,38 +380,51 @@ public class ClusterSchemaManager {
    */
   public synchronized void adjustMaxRegionGroupNum() {
     // Get all StorageGroupSchemas
-    Map<String, TDatabaseSchema> storageGroupSchemaMap =
+    Map<String, TDatabaseSchema> databaseSchemaMap =
         getMatchedDatabaseSchemasByName(getDatabaseNames());
-    if (storageGroupSchemaMap.size() == 0) {
+    if (databaseSchemaMap.size() == 0) {
       // Skip when there are no StorageGroups
       return;
     }
 
     int dataNodeNum = getNodeManager().getRegisteredDataNodeCount();
     int totalCpuCoreNum = getNodeManager().getTotalCpuCoreCount();
-    int storageGroupNum = storageGroupSchemaMap.size();
+    int databaseNum = databaseSchemaMap.size();
+
+    for (TDatabaseSchema databaseSchema : databaseSchemaMap.values()) {
+      if (!getPartitionManager().isDatabaseExisted(databaseSchema.getName())) {
+        // filter the pre deleted database
+        databaseNum--;
+      }
+    }
 
     AdjustMaxRegionGroupNumPlan adjustMaxRegionGroupNumPlan = new 
AdjustMaxRegionGroupNumPlan();
-    for (TDatabaseSchema storageGroupSchema : storageGroupSchemaMap.values()) {
+    for (TDatabaseSchema databaseSchema : databaseSchemaMap.values()) {
       try {
         // Adjust maxSchemaRegionGroupNum for each StorageGroup.
         // All StorageGroups share the DataNodes equally.
         // The allocated SchemaRegionGroups will not be shrunk.
-        int allocatedSchemaRegionGroupCount =
-            getPartitionManager()
-                .getRegionGroupCount(
-                    storageGroupSchema.getName(), 
TConsensusGroupType.SchemaRegion);
+        int allocatedSchemaRegionGroupCount;
+        try {
+          allocatedSchemaRegionGroupCount =
+              getPartitionManager()
+                  .getRegionGroupCount(databaseSchema.getName(), 
TConsensusGroupType.SchemaRegion);
+        } catch (DatabaseNotExistsException e) {
+          // ignore the pre deleted database
+          continue;
+        }
+
         int maxSchemaRegionGroupNum =
             calcMaxRegionGroupNum(
-                storageGroupSchema.getMinSchemaRegionGroupNum(),
+                databaseSchema.getMinSchemaRegionGroupNum(),
                 SCHEMA_REGION_PER_DATA_NODE,
                 dataNodeNum,
-                storageGroupNum,
-                storageGroupSchema.getSchemaReplicationFactor(),
+                databaseNum,
+                databaseSchema.getSchemaReplicationFactor(),
                 allocatedSchemaRegionGroupCount);
         LOGGER.info(
             "[AdjustRegionGroupNum] The maximum number of SchemaRegionGroups 
for Database: {} is adjusted to: {}",
-            storageGroupSchema.getName(),
+            databaseSchema.getName(),
             maxSchemaRegionGroupNum);
 
         // Adjust maxDataRegionGroupNum for each StorageGroup.
@@ -419,23 +432,22 @@ public class ClusterSchemaManager {
         // The allocated DataRegionGroups will not be shrunk.
         int allocatedDataRegionGroupCount =
             getPartitionManager()
-                .getRegionGroupCount(storageGroupSchema.getName(), 
TConsensusGroupType.DataRegion);
+                .getRegionGroupCount(databaseSchema.getName(), 
TConsensusGroupType.DataRegion);
         int maxDataRegionGroupNum =
             calcMaxRegionGroupNum(
-                storageGroupSchema.getMinDataRegionGroupNum(),
+                databaseSchema.getMinDataRegionGroupNum(),
                 DATA_REGION_PER_PROCESSOR,
                 totalCpuCoreNum,
-                storageGroupNum,
-                storageGroupSchema.getDataReplicationFactor(),
+                databaseNum,
+                databaseSchema.getDataReplicationFactor(),
                 allocatedDataRegionGroupCount);
         LOGGER.info(
             "[AdjustRegionGroupNum] The maximum number of DataRegionGroups for 
Database: {} is adjusted to: {}",
-            storageGroupSchema.getName(),
+            databaseSchema.getName(),
             maxDataRegionGroupNum);
 
         adjustMaxRegionGroupNumPlan.putEntry(
-            storageGroupSchema.getName(),
-            new Pair<>(maxSchemaRegionGroupNum, maxDataRegionGroupNum));
+            databaseSchema.getName(), new Pair<>(maxSchemaRegionGroupNum, 
maxDataRegionGroupNum));
       } catch (DatabaseNotExistsException e) {
         LOGGER.warn("Adjust maxRegionGroupNum failed because StorageGroup 
doesn't exist", e);
       }
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java
index 3c29a9f796..0ab2017a9f 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java
@@ -589,6 +589,10 @@ public class PartitionManager {
     return partitionInfo.getRegionGroupCount(database, type);
   }
 
+  public boolean isDatabaseExisted(String database) {
+    return partitionInfo.isDatabaseExisted(database);
+  }
+
   /**
    * Only leader use this interface.
    *
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java
index 02100ddc44..ea8ad01653 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java
@@ -301,7 +301,7 @@ public class PartitionInfo implements SnapshotProcessor {
       plan.getPartitionSlotsMap()
           .forEach(
               (storageGroup, partitionSlots) -> {
-                if (isStorageGroupExisted(storageGroup)) {
+                if (isDatabaseExisted(storageGroup)) {
                   schemaPartition.put(storageGroup, new 
SchemaPartitionTable());
 
                   if (!databasePartitionTables
@@ -340,7 +340,7 @@ public class PartitionInfo implements SnapshotProcessor {
     plan.getPartitionSlotsMap()
         .forEach(
             (storageGroup, partitionSlots) -> {
-              if (isStorageGroupExisted(storageGroup)) {
+              if (isDatabaseExisted(storageGroup)) {
                 dataPartition.put(storageGroup, new DataPartitionTable());
 
                 if (!databasePartitionTables
@@ -387,8 +387,8 @@ public class PartitionInfo implements SnapshotProcessor {
     }
   }
 
-  private boolean isStorageGroupExisted(String storageGroup) {
-    final DatabasePartitionTable databasePartitionTable = 
databasePartitionTables.get(storageGroup);
+  public boolean isDatabaseExisted(String database) {
+    final DatabasePartitionTable databasePartitionTable = 
databasePartitionTables.get(database);
     return databasePartitionTable != null && 
!databasePartitionTable.isPredeleted();
   }
 
@@ -402,7 +402,7 @@ public class PartitionInfo implements SnapshotProcessor {
     plan.getAssignedSchemaPartition()
         .forEach(
             (storageGroup, schemaPartitionTable) -> {
-              if (isStorageGroupExisted(storageGroup)) {
+              if (isDatabaseExisted(storageGroup)) {
                 databasePartitionTables
                     .get(storageGroup)
                     .createSchemaPartition(schemaPartitionTable);
@@ -422,7 +422,7 @@ public class PartitionInfo implements SnapshotProcessor {
     plan.getAssignedDataPartition()
         .forEach(
             (storageGroup, dataPartitionTable) -> {
-              if (isStorageGroupExisted(storageGroup)) {
+              if (isDatabaseExisted(storageGroup)) {
                 
databasePartitionTables.get(storageGroup).createDataPartition(dataPartitionTable);
               }
             });
@@ -436,7 +436,7 @@ public class PartitionInfo implements SnapshotProcessor {
     Map<String, SchemaPartitionTable> schemaPartitionMap = new 
ConcurrentHashMap<>();
 
     matchedStorageGroups.stream()
-        .filter(this::isStorageGroupExisted)
+        .filter(this::isDatabaseExisted)
         .forEach(
             storageGroup -> {
               schemaPartitionMap.put(storageGroup, new SchemaPartitionTable());
@@ -534,7 +534,7 @@ public class PartitionInfo implements SnapshotProcessor {
 
     partitionSlotsMap.forEach(
         (storageGroup, partitionSlots) -> {
-          if (isStorageGroupExisted(storageGroup)) {
+          if (isDatabaseExisted(storageGroup)) {
             result.put(
                 storageGroup,
                 databasePartitionTables
@@ -559,7 +559,7 @@ public class PartitionInfo implements SnapshotProcessor {
 
     partitionSlotsMap.forEach(
         (storageGroup, partitionSlots) -> {
-          if (isStorageGroupExisted(storageGroup)) {
+          if (isDatabaseExisted(storageGroup)) {
             result.put(
                 storageGroup,
                 databasePartitionTables
@@ -646,7 +646,7 @@ public class PartitionInfo implements SnapshotProcessor {
    */
   public int getRegionGroupCount(String database, TConsensusGroupType type)
       throws DatabaseNotExistsException {
-    if (!isStorageGroupExisted(database)) {
+    if (!isDatabaseExisted(database)) {
       throw new DatabaseNotExistsException(database);
     }
 
@@ -785,7 +785,7 @@ public class PartitionInfo implements SnapshotProcessor {
   }
 
   public DataSet getRegionId(GetRegionIdPlan plan) {
-    if (!isStorageGroupExisted(plan.getStorageGroup())) {
+    if (!isDatabaseExisted(plan.getStorageGroup())) {
       return new GetRegionIdResp(
           new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()), new 
ArrayList<>());
     }
@@ -797,7 +797,7 @@ public class PartitionInfo implements SnapshotProcessor {
   }
 
   public DataSet getTimeSlotList(GetTimeSlotListPlan plan) {
-    if (!isStorageGroupExisted(plan.getStorageGroup())) {
+    if (!isDatabaseExisted(plan.getStorageGroup())) {
       return new GetTimeSlotListResp(
           new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()), new 
ArrayList<>());
     }
@@ -809,7 +809,7 @@ public class PartitionInfo implements SnapshotProcessor {
   }
 
   public DataSet getSeriesSlotList(GetSeriesSlotListPlan plan) {
-    if (!isStorageGroupExisted(plan.getStorageGroup())) {
+    if (!isDatabaseExisted(plan.getStorageGroup())) {
       return new GetSeriesSlotListResp(
           new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()), new 
ArrayList<>());
     }

Reply via email to