private synchronized void balanceRegionPriority() {
    priorityMapLock.writeLock().lock();
    AtomicBoolean needBroadcast = new AtomicBoolean(false);
    Map<TConsensusGroupId, Pair<TRegionReplicaSet, TRegionReplicaSet>> differentPriorityMap =
        new TreeMap<>();
    try {
      Map<TConsensusGroupId, Integer> regionLeaderMap = getLoadManager().getRegionLeaderMap();

      // Balancing region priority in each SchemaRegionGroup
      Map<TConsensusGroupId, TRegionReplicaSet> optimalRegionPriorityMap =
          priorityRouter.generateOptimalRoutePriority(
              getPartitionManager().getAllReplicaSets(TConsensusGroupType.SchemaRegion),
              regionLeaderMap);
      // Balancing region priority in each DataRegionGroup
      optimalRegionPriorityMap.putAll(
          priorityRouter.generateOptimalRoutePriority(
              getPartitionManager().getAllReplicaSets(TConsensusGroupType.DataRegion),
              regionLeaderMap));

      optimalRegionPriorityMap.forEach(
          (regionGroupId, optimalRegionPriority) -> {
            TRegionReplicaSet currentRegionPriority = regionPriorityMap.get(regionGroupId);
            if (!optimalRegionPriority.equals(currentRegionPriority)) {
              differentPriorityMap.put(
                  regionGroupId, new Pair<>(currentRegionPriority, optimalRegionPriority));
              regionPriorityMap.put(regionGroupId, optimalRegionPriority);
              needBroadcast.set(true);
            }
          });
    } finally {
      priorityMapLock.writeLock().unlock();
    }

    if (needBroadcast.get()) {
      recordRegionPriorityMap(differentPriorityMap);
      broadcastLatestRegionPriorityMap();
    }
  }
Balance cluster RegionGroup route priority through configured algorithm.
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java