private Pair<Long, Integer> tryToFindLaziestWorker(final long clusterId, final MetadataStore metadataStore,
                                                       final List<Pair<Long, Integer>> lazyWorkers) {
        final List<Pair<Pair<Long, Integer>, StoreStats>> storeStatsList = Lists.newArrayList();
        for (final Pair<Long, Integer> worker : lazyWorkers) {
            final StoreStats stats = metadataStore.getStoreStats(clusterId, worker.getKey());
            if (stats != null) {
                // TODO check timeInterval
                storeStatsList.add(Pair.of(worker, stats));
            }
        }
        if (storeStatsList.isEmpty()) {
            return null;
        }
        if (storeStatsList.size() == 1) {
            return storeStatsList.get(0).getKey();
        }
        final Pair<Pair<Long, Integer>, StoreStats> min = Collections.min(storeStatsList, (o1, o2) -> {
            final StoreStats s1 = o1.getValue();
            final StoreStats s2 = o2.getValue();
            int val = Boolean.compare(s1.isBusy(), s2.isBusy());
            if (val != 0) {
                return val;
            }
            val = Integer.compare(s1.getRegionCount(), s2.getRegionCount());
            if (val != 0) {
                return val;
            }
            val = Long.compare(s1.getBytesWritten(), s2.getBytesWritten());
            if (val != 0) {
                return val;
            }
            val = Long.compare(s1.getBytesRead(), s2.getBytesRead());
            if (val != 0) {
                return val;
            }
            val = Long.compare(s1.getKeysWritten(), s2.getKeysWritten());
            if (val != 0) {
                return val;
            }
            val = Long.compare(s1.getKeysRead(), s2.getKeysRead());
            if (val != 0) {
                return val;
            }
            return Long.compare(-s1.getAvailable(), -s2.getAvailable());
        });
        return min.getKey();
    }
Trying to balance the number of leaders in each store.

@author jiachun.fjc
jraft-rheakv/rheakv-pd/src/main/java/com/alipay/sofa/jraft/rhea/pipeline/handler/RegionLeaderBalanceHandler.java