private Map<TConsensusGroupId, Integer> constructGreedyDistribution() {
    Map<Integer, Integer> leaderCounter = new TreeMap<>();
    regionLocationMap.forEach(
        (regionGroupId, dataNodeIds) -> {
          int minCount = Integer.MAX_VALUE,
              leaderId = regionLeaderMap.getOrDefault(regionGroupId, -1);
          for (int dataNodeId : dataNodeIds) {
            if (isDataNodeAvailable(dataNodeId) && isRegionAvailable(regionGroupId, dataNodeId)) {
              // Select the DataNode with the minimal leader count as the new leader
              int count = leaderCounter.getOrDefault(dataNodeId, 0);
              if (count < minCount) {
                minCount = count;
                leaderId = dataNodeId;
              }
            }
          }
          regionLeaderMap.put(regionGroupId, leaderId);
          leaderCounter.merge(leaderId, 1, Integer::sum);
        });
    return new ConcurrentHashMap<>(regionLeaderMap);
  }
Leader distribution balancer that uses greedy algorithm
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/router/leader/GreedyLeaderBalancer.java