public Optional<TDataNodeLocation> filterDataNodeWithOtherRegionReplica(
      TConsensusGroupId regionId,
      List<TDataNodeLocation> excludeLocations,
      NodeStatus... allowingStatus) {
    List<TDataNodeLocation> regionLocations = findRegionLocations(regionId);
    if (regionLocations.isEmpty()) {
      LOGGER.warn("Cannot find DataNodes contain the given region: {}", regionId);
      return Optional.empty();
    }

    // Choosing the RUNNING DataNodes to execute firstly
    // If all DataNodes are not RUNNING, then choose the REMOVING DataNodes secondly
    List<TDataNodeLocation> aliveDataNodes =
        configManager.getNodeManager().filterDataNodeThroughStatus(allowingStatus).stream()
            .map(TDataNodeConfiguration::getLocation)
            .collect(Collectors.toList());
    final int leaderId = configManager.getLoadManager().getRegionLeaderMap().get(regionId);
    Collections.shuffle(aliveDataNodes);
    Optional<TDataNodeLocation> bestChoice = Optional.empty();
    for (TDataNodeLocation aliveDataNode : aliveDataNodes) {
      if (regionLocations.contains(aliveDataNode) && !excludeLocations.contains(aliveDataNode)) {
        if (leaderId == aliveDataNode.getDataNodeId()) {
          bestChoice = Optional.of(aliveDataNode);
          break;
        } else if (!bestChoice.isPresent()) {
          bestChoice = Optional.of(aliveDataNode);
        }
      }
    }
    return bestChoice;
  }
Filter a DataNode who contains other RegionReplica excepts the given one.

<p>Choose the RUNNING status datanode firstly, if no RUNNING status datanode match the
condition, then we choose the REMOVING status datanode.

<p>`addRegionPeer`, `removeRegionPeer` and `changeRegionLeader` invoke this method.

@param regionId The specific RegionId
@param filterLocation The DataNodeLocation that should be filtered
@return A DataNodeLocation that contains other RegionReplica and different from the
    filterLocation
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/env/RegionMaintainHandler.java