HxpSerein commented on code in PR #15022:
URL: https://github.com/apache/iotdb/pull/15022#discussion_r1985035261


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RemoveDataNodeHandler.java:
##########
@@ -193,6 +201,136 @@ public List<RegionMigrationPlan> getRegionMigrationPlans(
     return regionMigrationPlans;
   }
 
+  /**
+   * Retrieves all region migration plans for the specified removed DataNodes 
and selects the
+   * destination.
+   *
+   * @param removedDataNodes the list of DataNodes from which to obtain 
migration plans
+   * @return a list of region migration plans associated with the removed 
DataNodes
+   */
+  public List<RegionMigrationPlan> selectedRegionMigrationPlans(
+      List<TDataNodeLocation> removedDataNodes) {
+
+    Set<Integer> removedDataNodesSet = new HashSet<>();
+    for (TDataNodeLocation removedDataNode : removedDataNodes) {
+      removedDataNodesSet.add(removedDataNode.dataNodeId);
+    }
+
+    final List<TDataNodeConfiguration> availableDataNodes =
+        configManager
+            .getNodeManager()
+            .filterDataNodeThroughStatus(NodeStatus.Running, 
NodeStatus.Unknown)
+            .stream()
+            .filter(node -> 
!removedDataNodesSet.contains(node.getLocation().getDataNodeId()))
+            .collect(Collectors.toList());
+
+    List<RegionMigrationPlan> regionMigrationPlans = new ArrayList<>();
+
+    regionMigrationPlans.addAll(
+        selectMigrationPlans(availableDataNodes, 
TConsensusGroupType.DataRegion, removedDataNodes));
+
+    regionMigrationPlans.addAll(
+        selectMigrationPlans(
+            availableDataNodes, TConsensusGroupType.SchemaRegion, 
removedDataNodes));
+
+    return regionMigrationPlans;
+  }
+
+  public List<RegionMigrationPlan> selectMigrationPlans(
+      List<TDataNodeConfiguration> availableDataNodes,
+      TConsensusGroupType consensusGroupType,
+      List<TDataNodeLocation> removedDataNodes) {
+    List<TRegionReplicaSet> allocatedRegionGroups =
+        
configManager.getPartitionManager().getAllReplicaSets(consensusGroupType);
+
+    Map<TConsensusGroupId, TDataNodeLocation> replicaSetRemoved = new 
HashMap<>();
+    List<TRegionReplicaSet> migratedReplicas = new ArrayList<>();
+
+    for (TDataNodeLocation dataNodeLocation : removedDataNodes) {
+      List<TRegionReplicaSet> replicaSets =
+          allocatedRegionGroups.stream()
+              .filter(replicaSet -> 
replicaSet.getDataNodeLocations().contains(dataNodeLocation))
+              .collect(Collectors.toList());
+      for (TRegionReplicaSet replicaSet : replicaSets) {
+        replicaSetRemoved.put(replicaSet.getRegionId(), dataNodeLocation);

Review Comment:
   Yes, currently we have checks to ensure that removeDataNodes have at most 
one peer per region.



-- 
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