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

tanxinyu 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 7f4724dd3d7 Enhance concurrent control of data partition policy table 
(#12388)
7f4724dd3d7 is described below

commit 7f4724dd3d77ca6dea972f76749e1623a87201ea
Author: Yongzao <[email protected]>
AuthorDate: Tue Apr 23 11:46:48 2024 +0800

    Enhance concurrent control of data partition policy table (#12388)
---
 .../apache/iotdb/confignode/manager/load/LoadManager.java  |  4 +++-
 .../manager/load/balancer/PartitionBalancer.java           | 10 ++++++++--
 .../confignode/manager/partition/PartitionManager.java     | 14 ++++++++++----
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java
index 895d89246b8..1d53d101b38 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java
@@ -115,11 +115,13 @@ public class LoadManager {
    * Allocate DataPartitions.
    *
    * @param unassignedDataPartitionSlotsMap DataPartitionSlots that should be 
assigned
+   * @throws DatabaseNotExistsException If some specific Databases don't exist
+   * @throws NoAvailableRegionGroupException If there are no available 
RegionGroups
    * @return Map<DatabaseName, DataPartitionTable>, the allocating result
    */
   public Map<String, DataPartitionTable> allocateDataPartition(
       Map<String, Map<TSeriesPartitionSlot, TTimeSlotList>> 
unassignedDataPartitionSlotsMap)
-      throws NoAvailableRegionGroupException {
+      throws DatabaseNotExistsException, NoAvailableRegionGroupException {
     return 
partitionBalancer.allocateDataPartition(unassignedDataPartitionSlotsMap);
   }
 
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/PartitionBalancer.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/PartitionBalancer.java
index 51bf521c994..4d540c1ab2a 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/PartitionBalancer.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/PartitionBalancer.java
@@ -43,6 +43,7 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -108,12 +109,14 @@ public class PartitionBalancer {
    * Allocate DataPartitions
    *
    * @param unassignedDataPartitionSlotsMap DataPartitionSlots that should be 
assigned
+   * @throws DatabaseNotExistsException If some specific Databases don't exist
+   * @throws NoAvailableRegionGroupException If there are no available 
RegionGroups
    * @return Map<DatabaseName, DataPartitionTable>, the allocating result
    */
   public Map<String, DataPartitionTable> allocateDataPartition(
       Map<String, Map<TSeriesPartitionSlot, TTimeSlotList>> 
unassignedDataPartitionSlotsMap)
-      throws NoAvailableRegionGroupException {
-    Map<String, DataPartitionTable> result = new HashMap<>();
+      throws DatabaseNotExistsException, NoAvailableRegionGroupException {
+    Map<String, DataPartitionTable> result = new TreeMap<>();
 
     for (Map.Entry<String, Map<TSeriesPartitionSlot, TTimeSlotList>> 
slotsMapEntry :
         unassignedDataPartitionSlotsMap.entrySet()) {
@@ -133,6 +136,9 @@ public class PartitionBalancer {
       }
 
       DataPartitionTable dataPartitionTable = new DataPartitionTable();
+      if (!dataPartitionPolicyTableMap.containsKey(database)) {
+        throw new DatabaseNotExistsException(database);
+      }
       DataPartitionPolicyTable allotTable = 
dataPartitionPolicyTableMap.get(database);
       try {
         allotTable.acquireLock();
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 500a6d82660..5daf89f8dd5 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
@@ -389,7 +389,7 @@ public class PartitionManager {
       try {
         assignedDataPartition =
             
getLoadManager().allocateDataPartition(unassignedDataPartitionSlotsMap);
-      } catch (NoAvailableRegionGroupException e) {
+      } catch (DatabaseNotExistsException | NoAvailableRegionGroupException e) 
{
         status = getConsensusManager().confirmLeader();
         if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
           // The allocation might fail due to leadership change
@@ -398,9 +398,15 @@ public class PartitionManager {
         }
 
         LOGGER.error("Create DataPartition failed because: ", e);
-        resp.setStatus(
-            new 
TSStatus(TSStatusCode.NO_AVAILABLE_REGION_GROUP.getStatusCode())
-                .setMessage(e.getMessage()));
+        if (e instanceof DatabaseNotExistsException) {
+          resp.setStatus(
+              new TSStatus(TSStatusCode.DATABASE_NOT_EXIST.getStatusCode())
+                  .setMessage(e.getMessage()));
+        } else {
+          resp.setStatus(
+              new 
TSStatus(TSStatusCode.NO_AVAILABLE_REGION_GROUP.getStatusCode())
+                  .setMessage(e.getMessage()));
+        }
         return resp;
       }
 

Reply via email to