liyuheng55555 commented on code in PR #14634:
URL: https://github.com/apache/iotdb/pull/14634#discussion_r1914609509


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ProcedureManager.java:
##########
@@ -903,6 +1035,141 @@ public TSStatus migrateRegion(TMigrateRegionReq 
migrateRegionReq) {
     }
   }
 
+  public TSStatus reconstructRegion(TReconstructRegionReq req) {
+    RegionMaintainHandler handler = env.getRegionMaintainHandler();
+    final TDataNodeLocation targetDataNode =
+        
configManager.getNodeManager().getRegisteredDataNode(req.getDataNodeId()).getLocation();
+    try (AutoCloseableLock ignoredLock =
+        AutoCloseableLock.acquire(env.getSubmitRegionMigrateLock())) {
+      List<ReconstructRegionProcedure> procedures = new ArrayList<>();
+      for (int x : req.getRegionIds()) {
+        TConsensusGroupId regionId =
+            configManager
+                .getPartitionManager()
+                .generateTConsensusGroupIdByRegionId(x)
+                .orElseThrow(() -> new IllegalArgumentException("Region id " + 
x + " is invalid"));
+        final TDataNodeLocation coordinator =
+            handler
+                .filterDataNodeWithOtherRegionReplica(
+                    regionId,
+                    targetDataNode,
+                    NodeStatus.Running,
+                    NodeStatus.Removing,
+                    NodeStatus.ReadOnly)
+                .orElse(null);
+        TSStatus status = checkReconstructRegion(req, regionId, 
targetDataNode, coordinator);
+        if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+          return status;
+        }
+        procedures.add(new ReconstructRegionProcedure(regionId, 
targetDataNode, coordinator));
+      }
+      // all checks pass, submit all procedures
+      procedures.forEach(
+          reconstructRegionProcedure -> {
+            this.executor.submitProcedure(reconstructRegionProcedure);
+            LOGGER.info(
+                "[ReconstructRegion] Submit ReconstructRegionProcedure 
successfully, {}",
+                reconstructRegionProcedure);
+          });
+    }
+    return RpcUtils.SUCCESS_STATUS;
+  }
+
+  public TSStatus extendRegion(TExtendRegionReq req) {
+    try (AutoCloseableLock ignoredLock =
+        AutoCloseableLock.acquire(env.getSubmitRegionMigrateLock())) {
+      TConsensusGroupId regionId;
+      Optional<TConsensusGroupId> optional =
+          configManager
+              .getPartitionManager()
+              .generateTConsensusGroupIdByRegionId(req.getRegionId());
+      if (optional.isPresent()) {
+        regionId = optional.get();
+      } else {
+        LOGGER.error("get region group id fail");
+        return new TSStatus(TSStatusCode.EXTEND_REGION_ERROR.getStatusCode())
+            .setMessage("get region group id fail");
+      }
+
+      // find target dn
+      final TDataNodeLocation targetDataNode =
+          
configManager.getNodeManager().getRegisteredDataNode(req.getDataNodeId()).getLocation();
+      // select coordinator for adding peer
+      RegionMaintainHandler handler = env.getRegionMaintainHandler();
+      // TODO: choose the DataNode which has lowest load
+      final TDataNodeLocation coordinator =
+          handler
+              .filterDataNodeWithOtherRegionReplica(

Review Comment:
   Maybe only use leader is not a good idea ? Follower's load is lighter than 
leader



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to