protected Result tryReduceLoadByAction(ActionType actionType,
                                                 ClusterModelSnapshot cluster,
                                                 BrokerUpdater.Broker srcBroker,
                                                 List<BrokerUpdater.Broker> candidateBrokers,
                                                 Collection<Goal> goalsByPriority,
                                                 Collection<Goal> optimizedGoals,
                                                 Map<String, Set<String>> goalsByGroup) {
        List<Action> actionList = new ArrayList<>();
        candidateBrokers = candidateBrokers.stream().filter(b -> !b.isSlowBroker()).collect(Collectors.toList());
        if (candidateBrokers.isEmpty()) {
            return new Result(actionList, 0.0);
        }
        List<TopicPartitionReplicaUpdater.TopicPartitionReplica> srcReplicas = cluster
                .replicasFor(srcBroker.getBrokerId())
                .stream()
                .sorted(partitionComparator) // higher load first
                .collect(Collectors.toList());
        double loadChange = 0.0;
        for (TopicPartitionReplicaUpdater.TopicPartitionReplica tp : srcReplicas) {
            candidateBrokers.sort(lowLoadComparator()); // lower load first
            Optional<Action> optionalAction;
            ActionParameters parameters = new ActionParameters(cluster, tp, srcBroker, candidateBrokers, goalsByPriority, optimizedGoals, goalsByGroup);
            if (actionType == ActionType.MOVE) {
                optionalAction = tryMovePartitionOut(parameters);
            } else {
                optionalAction = trySwapPartitionOut(parameters, Comparator.comparingDouble(p -> p.loadValue(resource())),
                        (src, candidate) -> src.loadValue(resource()) > candidate.loadValue(resource()));
            }

            if (optionalAction.isPresent()) {
                Action action = optionalAction.get();
                cluster.applyAction(action);
                actionList.add(action);
                loadChange -= tp.loadValue(resource());
                if (action.getType() == ActionType.SWAP) {
                    loadChange += cluster.replica(action.getDestBrokerId(), action.getDestTopicPartition()).loadValue(resource());
                }
            }
            if (isBrokerAcceptable(srcBroker)) {
                // broker is acceptable after action, skip iterating reset partitions
                return new Result(actionList, loadChange);
            }
        }
        return new Result(actionList, loadChange);
    }
Try to reduce resource load by move or swap replicas out.

@param actionType       type of action
@param cluster          cluster model
@param srcBroker        broker to reduce load
@param candidateBrokers candidate brokers to move replicas to, or swap replicas with
@param goalsByPriority  all configured goals sorted by priority
@return a list of actions able to reduce load of srcBroker along with load change
core/src/main/java/kafka/autobalancer/goals/AbstractResourceGoal.java