You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/04/22 03:40:49 UTC

[GitHub] [iotdb] wangchao316 commented on a diff in pull request #5627: [IOTDB-2945] Reconstruct ConfigNode manage layer and persistence layer

wangchao316 commented on code in PR #5627:
URL: https://github.com/apache/iotdb/pull/5627#discussion_r855741567


##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/PartitionInfo.java:
##########
@@ -56,40 +68,81 @@ public class PartitionInfoPersistence {
   // TODO: Serialize and Deserialize
   private final DataPartition dataPartition;
 
-  public PartitionInfoPersistence() {
+  private PartitionInfo() {
+    this.regionAllocateLock = new ReentrantReadWriteLock();
+    this.regionReadWriteLock = new ReentrantReadWriteLock();
+    this.regionMap = new HashMap<>();
+
     this.schemaPartitionReadWriteLock = new ReentrantReadWriteLock();
-    this.dataPartitionReadWriteLock = new ReentrantReadWriteLock();
     this.schemaPartition =
         new SchemaPartition(
             ConfigNodeDescriptor.getInstance().getConf().getSeriesPartitionExecutorClass(),
             ConfigNodeDescriptor.getInstance().getConf().getSeriesPartitionSlotNum());
     this.schemaPartition.setSchemaPartitionMap(new HashMap<>());
+
+    this.dataPartitionReadWriteLock = new ReentrantReadWriteLock();
     this.dataPartition =
         new DataPartition(
             ConfigNodeDescriptor.getInstance().getConf().getSeriesPartitionExecutorClass(),
             ConfigNodeDescriptor.getInstance().getConf().getSeriesPartitionSlotNum());
     this.dataPartition.setDataPartitionMap(new HashMap<>());
   }
 
+  public int generateNextRegionGroupId() {
+    int result;
+    regionAllocateLock.writeLock().lock();
+    try {
+      result = nextRegionGroupId;

Review Comment:
   if nextRegionGroupId  use AtomicLong,  will be not need lock...



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/PartitionInfo.java:
##########
@@ -56,40 +68,81 @@ public class PartitionInfoPersistence {
   // TODO: Serialize and Deserialize
   private final DataPartition dataPartition;
 
-  public PartitionInfoPersistence() {
+  private PartitionInfo() {
+    this.regionAllocateLock = new ReentrantReadWriteLock();
+    this.regionReadWriteLock = new ReentrantReadWriteLock();
+    this.regionMap = new HashMap<>();
+
     this.schemaPartitionReadWriteLock = new ReentrantReadWriteLock();
-    this.dataPartitionReadWriteLock = new ReentrantReadWriteLock();
     this.schemaPartition =
         new SchemaPartition(
             ConfigNodeDescriptor.getInstance().getConf().getSeriesPartitionExecutorClass(),
             ConfigNodeDescriptor.getInstance().getConf().getSeriesPartitionSlotNum());
     this.schemaPartition.setSchemaPartitionMap(new HashMap<>());
+
+    this.dataPartitionReadWriteLock = new ReentrantReadWriteLock();
     this.dataPartition =
         new DataPartition(
             ConfigNodeDescriptor.getInstance().getConf().getSeriesPartitionExecutorClass(),
             ConfigNodeDescriptor.getInstance().getConf().getSeriesPartitionSlotNum());
     this.dataPartition.setDataPartitionMap(new HashMap<>());
   }
 
+  public int generateNextRegionGroupId() {
+    int result;
+    regionAllocateLock.writeLock().lock();
+    try {
+      result = nextRegionGroupId;
+      nextRegionGroupId += 1;
+    } finally {
+      regionAllocateLock.writeLock().unlock();
+    }
+    return result;
+  }
+
+  /**
+   * Persistence allocation result of new Regions
+   *
+   * @param plan CreateRegionsPlan
+   * @return SUCCESS_STATUS
+   */
+  public TSStatus createRegions(CreateRegionsReq plan) {
+    TSStatus result;
+    regionReadWriteLock.writeLock().lock();
+    regionAllocateLock.writeLock().lock();

Review Comment:
   why does add a regionAllocateLock?     
   can regionReadWriteLock resoved only?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org