@Override
  BalanceAction generateCandidate(BalancerClusterState cluster, boolean isWeighing) {
    boolean isTableIsolationEnabled = getBalancerConditionals().isTableIsolationEnabled();
    ClusterLoadState cs = new ClusterLoadState(cluster.clusterState);
    float average = cs.getLoadAverage();
    int ceiling = (int) Math.ceil(average * (1 + slop));
    Set<Integer> sloppyServerIndices = new HashSet<>();
    for (int i = 0; i < cluster.numServers; i++) {
      int regionCount = cluster.regionsPerServer[i].length;
      if (regionCount > ceiling) {
        sloppyServerIndices.add(i);
      }
    }

    if (sloppyServerIndices.isEmpty()) {
      LOG.trace("No action to take because no sloppy servers exist.");
      return BalanceAction.NULL_ACTION;
    }

    List<MoveRegionAction> moves = new ArrayList<>();
    Set<ServerAndLoad> fixedServers = new HashSet<>();
    for (int sourceServer : sloppyServerIndices) {
      if (
        isTableIsolationEnabled
          && getBalancerConditionals().isServerHostingIsolatedTables(cluster, sourceServer)
      ) {
        // Don't fix sloppiness of servers hosting isolated tables
        continue;
      }
      for (int regionIdx : cluster.regionsPerServer[sourceServer]) {
        boolean regionFoundMove = false;
        for (ServerAndLoad serverAndLoad : cs.getServersByLoad().keySet()) {
          ServerName destinationServer = serverAndLoad.getServerName();
          int destinationServerIdx = cluster.serversToIndex.get(destinationServer.getAddress());
          int regionsOnDestination = cluster.regionsPerServer[destinationServerIdx].length;
          if (regionsOnDestination < average) {
            MoveRegionAction move =
              new MoveRegionAction(regionIdx, sourceServer, destinationServerIdx);
            if (willBeAccepted(cluster, move)) {
              if (isWeighing) {
                // Fast exit for weighing candidate
                return move;
              }
              moves.add(move);
              cluster.doAction(move);
              regionFoundMove = true;
              break;
            }
          } else {
            fixedServers.add(serverAndLoad);
          }
        }
        fixedServers.forEach(s -> cs.getServersByLoad().remove(s));
        fixedServers.clear();
        if (!regionFoundMove && LOG.isTraceEnabled()) {
          LOG.trace("Could not find a destination for region {} from server {}.", regionIdx,
            sourceServer);
        }
        if (cluster.regionsPerServer[sourceServer].length <= ceiling) {
          break;
        }
      }
    }

    return batchMovesAndResetClusterState(cluster, moves);
  }
A simple candidate generator that attempts to move regions from the most-loaded servers to the
least-loaded servers.
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/SlopFixingCandidateGenerator.java