public List<RegionMigrationPlan> selectMigrationPlans(
      List<TDataNodeConfiguration> availableDataNodes,
      TConsensusGroupType consensusGroupType,
      List<TDataNodeLocation> removedDataNodes) {

    // Retrieve all allocated replica sets for the given consensus group type
    List<TRegionReplicaSet> allocatedReplicaSets =
        configManager.getPartitionManager().getAllReplicaSets(consensusGroupType);

    // Step 1: Identify affected replica sets and record the removed DataNode for each replica set
    Map<TConsensusGroupId, TDataNodeLocation> removedNodeMap = new HashMap<>();
    Set<TRegionReplicaSet> affectedReplicaSets =
        identifyAffectedReplicaSets(allocatedReplicaSets, removedDataNodes, removedNodeMap);

    // Step 2: Update affected replica sets by removing the removed DataNode
    updateReplicaSets(allocatedReplicaSets, affectedReplicaSets, removedNodeMap);

    // Build a mapping of available DataNodes and their free disk space (computed only once)
    Map<Integer, TDataNodeConfiguration> availableDataNodeMap =
        buildAvailableDataNodeMap(availableDataNodes);
    Map<Integer, Double> freeDiskSpaceMap = buildFreeDiskSpaceMap(availableDataNodes);

    // Step 3: For each affected replica set, select a new destination DataNode and create a
    // migration plan
    List<RegionMigrationPlan> migrationPlans = new ArrayList<>();

    Map<TConsensusGroupId, TRegionReplicaSet> remainReplicasMap = new HashMap<>();
    Map<TConsensusGroupId, String> regionDatabaseMap = new HashMap<>();
    Map<String, List<TRegionReplicaSet>> databaseAllocatedRegionGroupMap = new HashMap<>();

    for (TRegionReplicaSet replicaSet : affectedReplicaSets) {
      remainReplicasMap.put(replicaSet.getRegionId(), replicaSet);
      String database =
          configManager.getPartitionManager().getRegionDatabase(replicaSet.getRegionId());
      List<TRegionReplicaSet> databaseAllocatedReplicaSets =
          configManager.getPartitionManager().getAllReplicaSets(database, consensusGroupType);
      regionDatabaseMap.put(replicaSet.getRegionId(), database);
      databaseAllocatedRegionGroupMap.put(database, databaseAllocatedReplicaSets);
    }

    Map<TConsensusGroupId, TDataNodeConfiguration> result =
        regionGroupAllocator.removeNodeReplicaSelect(
            availableDataNodeMap,
            freeDiskSpaceMap,
            allocatedReplicaSets,
            regionDatabaseMap,
            databaseAllocatedRegionGroupMap,
            remainReplicasMap);

    for (TConsensusGroupId regionId : result.keySet()) {

      TDataNodeConfiguration selectedNode = result.get(regionId);
      LOGGER.info(
          "Selected DataNode {} for Region {}",
          selectedNode.getLocation().getDataNodeId(),
          regionId);

      // Create the migration plan
      RegionMigrationPlan plan = RegionMigrationPlan.create(regionId, removedNodeMap.get(regionId));
      plan.setToDataNode(selectedNode.getLocation());
      migrationPlans.add(plan);
    }
    return migrationPlans;
  }
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
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RemoveDataNodeHandler.java