Search in sources :

Example 1 with ActionType

use of com.linkedin.kafka.cruisecontrol.analyzer.ActionType in project cruise-control by linkedin.

the class PotentialNwOutGoal method selfSatisfied.

/**
 * Check if the movement of potential outbound network utilization from the given source replica to given
 * destination broker is acceptable for this goal. The action is unacceptable if both of the following conditions
 * are met: (1) transfer of replica makes the potential network outbound utilization of the destination broker go
 * out of its allowed capacity, (2) broker containing the source replica is alive. For a swap action, this
 * consideration is bidirectional.
 *
 * @param clusterModel The state of the cluster.
 * @param action Action containing information about potential modification to the given cluster model.
 * @return True if requirements of this goal are not violated if this action is applied to the given cluster state,
 * false otherwise.
 */
@Override
protected boolean selfSatisfied(ClusterModel clusterModel, BalancingAction action) {
    Replica sourceReplica = clusterModel.broker(action.sourceBrokerId()).replica(action.topicPartition());
    ActionType actionType = action.balancingAction();
    Broker sourceBroker = sourceReplica.broker();
    // If the source broker is dead and currently self healing dead brokers only, then the action must be executed.
    if (!sourceBroker.isAlive() && _selfHealingDeadBrokersOnly && actionType != ActionType.REPLICA_SWAP) {
        return true;
    }
    Broker destinationBroker = clusterModel.broker(action.destinationBrokerId());
    double destinationBrokerUtilization = clusterModel.potentialLeadershipLoadFor(destinationBroker.id()).expectedUtilizationFor(Resource.NW_OUT);
    double destinationCapacity = destinationBroker.capacityFor(Resource.NW_OUT) * _balancingConstraint.capacityThreshold(Resource.NW_OUT);
    double sourceReplicaUtilization = clusterModel.partition(sourceReplica.topicPartition()).leader().load().expectedUtilizationFor(Resource.NW_OUT);
    if (actionType != ActionType.REPLICA_SWAP) {
        // Check whether replica or leadership transfer leads to violation of capacity limit requirement.
        return destinationCapacity >= destinationBrokerUtilization + sourceReplicaUtilization;
    }
    // Ensure that the destination capacity of self-satisfied for action type swap is not violated.
    double destinationReplicaUtilization = clusterModel.partition(action.destinationTopicPartition()).leader().load().expectedUtilizationFor(Resource.NW_OUT);
    if (destinationCapacity < destinationBrokerUtilization + sourceReplicaUtilization - destinationReplicaUtilization) {
        // Destination capacity would be violated due to swap.
        return false;
    }
    // Ensure that the source capacity of self-satisfied for action type swap is not violated.
    double sourceBrokerUtilization = clusterModel.potentialLeadershipLoadFor(sourceBroker.id()).expectedUtilizationFor(Resource.NW_OUT);
    double sourceCapacity = sourceBroker.capacityFor(Resource.NW_OUT) * _balancingConstraint.capacityThreshold(Resource.NW_OUT);
    return sourceCapacity >= sourceBrokerUtilization + destinationReplicaUtilization - sourceReplicaUtilization;
}
Also used : ActionType(com.linkedin.kafka.cruisecontrol.analyzer.ActionType) Broker(com.linkedin.kafka.cruisecontrol.model.Broker) Replica(com.linkedin.kafka.cruisecontrol.model.Replica)

Aggregations

ActionType (com.linkedin.kafka.cruisecontrol.analyzer.ActionType)1 Broker (com.linkedin.kafka.cruisecontrol.model.Broker)1 Replica (com.linkedin.kafka.cruisecontrol.model.Replica)1