static Map<TDataNodeLocation, List<TConsensusGroupId>> getLeaderDataNodeRegionGroupMap(
      Map<TConsensusGroupId, Integer> leaderMap,
      Map<TConsensusGroupId, TRegionReplicaSet> regionReplicaSetMap) {
    Map<TDataNodeLocation, List<TConsensusGroupId>> dataNodeConsensusGroupIdMap = new HashMap<>();
    regionReplicaSetMap.forEach(
        (consensusGroupId, regionReplicaSet) -> {
          Integer leaderId = leaderMap.get(consensusGroupId);
          TDataNodeLocation leaderDataNodeLocation = null;
          if (leaderId == null || leaderId == -1) {
            leaderDataNodeLocation = regionReplicaSet.getDataNodeLocations().get(0);
          } else {
            for (TDataNodeLocation dataNodeLocation : regionReplicaSet.getDataNodeLocations()) {
              if (dataNodeLocation.getDataNodeId() == leaderId) {
                leaderDataNodeLocation = dataNodeLocation;
                break;
              }
            }
          }
          dataNodeConsensusGroupIdMap
              .computeIfAbsent(leaderDataNodeLocation, k -> new ArrayList<>())
              .add(regionReplicaSet.getRegionId());
        });
    return dataNodeConsensusGroupIdMap;
  }
Try to get and execute request on consensus group leader as possible. If fail to get leader,
select some other replica for execution.
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/DataNodeRegionGroupUtil.java