private Set<TRegionReplicaSet> identifyAffectedReplicaSets(
      List<TRegionReplicaSet> allocatedReplicaSets,
      List<TDataNodeLocation> removedDataNodes,
      Map<TConsensusGroupId, TDataNodeLocation> removedNodeMap) {

    Set<TRegionReplicaSet> affectedReplicaSets = new HashSet<>();
    // Create a copy of allocatedReplicaSets to avoid concurrent modifications
    List<TRegionReplicaSet> allocatedCopy = new ArrayList<>(allocatedReplicaSets);

    for (TDataNodeLocation removedNode : removedDataNodes) {
      allocatedCopy.stream()
          .filter(replicaSet -> replicaSet.getDataNodeLocations().contains(removedNode))
          .forEach(
              replicaSet -> {
                removedNodeMap.put(replicaSet.getRegionId(), removedNode);
                affectedReplicaSets.add(replicaSet);
              });
    }
    return affectedReplicaSets;
  }
Identifies affected replica sets from allocatedReplicaSets that contain any DataNode in
removedDataNodes, and records the removed DataNode for each replica set.
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RemoveDataNodeHandler.java