@Override
  public Map<TConsensusGroupId, TRegionReplicaSet> generateOptimalRoutePriority(
      List<TRegionReplicaSet> replicaSets, Map<TConsensusGroupId, Integer> regionLeaderMap) {
    Map<TConsensusGroupId, TRegionReplicaSet> regionPriorityMap = new TreeMap<>();

    replicaSets.forEach(
        replicaSet -> {

          /* 1. Pick leader if leader exists and available */
          int leaderId = regionLeaderMap.getOrDefault(replicaSet.getRegionId(), -1);
          if (leaderId != -1) {
            for (int i = 0; i < replicaSet.getDataNodeLocationsSize(); i++) {
              if (replicaSet.getDataNodeLocations().get(i).getDataNodeId() == leaderId) {
                Collections.swap(replicaSet.getDataNodeLocations(), 0, i);
                break;
              }
            }
          }

          regionPriorityMap.put(replicaSet.getRegionId(), replicaSet);
        });

    return regionPriorityMap;
  }
The LeaderPriorityBalancer always pick the leader Replica
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/router/priority/LeaderPriorityBalancer.java