private Map<TConsensusGroupId, Integer> collectLeaderDistribution() {
    Map<TConsensusGroupId, Integer> result = new ConcurrentHashMap<>();

    databaseRegionGroupMap.forEach(
        (database, regionGroupIds) ->
            regionGroupIds.forEach(
                regionGroupId -> {
                  int originalLeader = regionLeaderMap.getOrDefault(regionGroupId, -1);
                  if (!regionGroupIntersection.contains(regionGroupId)) {
                    result.put(regionGroupId, originalLeader);
                    return;
                  }
                  boolean matchLeader = false;
                  for (int currentEdge = vertexHeadEdge[rVertexMap.get(regionGroupId)];
                      currentEdge >= 0;
                      currentEdge = costFlowEdges.get(currentEdge).nextEdge) {
                    CostFlowEdge edge = costFlowEdges.get(currentEdge);
                    if (edge.destVertex != S_VERTEX && edge.capacity == 0) {
                      matchLeader = true;
                      result.put(regionGroupId, sDVertexReflect.get(database).get(edge.destVertex));
                    }
                  }
                  if (!matchLeader) {
                    result.put(regionGroupId, originalLeader);
                  }
                }));

    return result;
  }
@return Map<RegionGroupId, DataNodeId where the new leader locate>
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/router/leader/CostFlowSelectionLeaderBalancer.java