Search in sources :

Example 16 with OptimizationOptions

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

the class GoalViolationDetector method optimizeForGoal.

protected boolean optimizeForGoal(ClusterModel clusterModel, Goal goal, GoalViolations goalViolations, Set<Integer> excludedBrokersForLeadership, Set<Integer> excludedBrokersForReplicaMove, boolean checkPartitionsWithRFGreaterThanNumRacks) throws KafkaCruiseControlException {
    if (clusterModel.topics().isEmpty()) {
        LOG.info("Skipping goal violation detection because the cluster model does not have any topic.");
        return false;
    }
    Map<TopicPartition, List<ReplicaPlacementInfo>> initReplicaDistribution = clusterModel.getReplicaDistribution();
    Map<TopicPartition, ReplicaPlacementInfo> initLeaderDistribution = clusterModel.getLeaderDistribution();
    try {
        OptimizationOptions options = _optimizationOptionsGenerator.optimizationOptionsForGoalViolationDetection(clusterModel, excludedTopics(clusterModel), excludedBrokersForLeadership, excludedBrokersForReplicaMove);
        if (checkPartitionsWithRFGreaterThanNumRacks) {
            _hasPartitionsWithRFGreaterThanNumRacks = clusterModel.maxReplicationFactor() > clusterModel.numAliveRacksAllowedReplicaMoves(options);
        }
        goal.optimize(clusterModel, Collections.emptySet(), options);
    } catch (OptimizationFailureException ofe) {
        // An OptimizationFailureException indicates (1) a hard goal violation that cannot be fixed typically due to
        // lack of physical hardware (e.g. insufficient number of racks to satisfy rack awareness, insufficient number
        // of brokers to satisfy Replica Capacity Goal, or insufficient number of resources to satisfy resource
        // capacity goals), or (2) a failure to move offline replicas away from dead brokers/disks.
        goalViolations.addViolation(goal.name(), false);
        return true;
    }
    boolean hasDiff = AnalyzerUtils.hasDiff(initReplicaDistribution, initLeaderDistribution, clusterModel);
    LOG.trace("{} generated {} proposals", goal.name(), hasDiff ? "some" : "no");
    if (hasDiff) {
        // A goal violation that can be optimized by applying the generated proposals.
        goalViolations.addViolation(goal.name(), true);
        return true;
    } else {
        // The goal is already satisfied.
        return false;
    }
}
Also used : OptimizationFailureException(com.linkedin.kafka.cruisecontrol.exception.OptimizationFailureException) OptimizationOptions(com.linkedin.kafka.cruisecontrol.analyzer.OptimizationOptions) TopicPartition(org.apache.kafka.common.TopicPartition) List(java.util.List) ReplicaPlacementInfo(com.linkedin.kafka.cruisecontrol.model.ReplicaPlacementInfo)

Aggregations

OptimizationOptions (com.linkedin.kafka.cruisecontrol.analyzer.OptimizationOptions)16 ClusterModel (com.linkedin.kafka.cruisecontrol.model.ClusterModel)15 ActionAcceptance (com.linkedin.kafka.cruisecontrol.analyzer.ActionAcceptance)9 ACCEPT (com.linkedin.kafka.cruisecontrol.analyzer.ActionAcceptance.ACCEPT)9 REPLICA_REJECT (com.linkedin.kafka.cruisecontrol.analyzer.ActionAcceptance.REPLICA_REJECT)9 ActionType (com.linkedin.kafka.cruisecontrol.analyzer.ActionType)9 BalancingAction (com.linkedin.kafka.cruisecontrol.analyzer.BalancingAction)9 GoalUtils.replicaSortName (com.linkedin.kafka.cruisecontrol.analyzer.goals.GoalUtils.replicaSortName)9 OptimizationFailureException (com.linkedin.kafka.cruisecontrol.exception.OptimizationFailureException)9 Broker (com.linkedin.kafka.cruisecontrol.model.Broker)9 Replica (com.linkedin.kafka.cruisecontrol.model.Replica)9 Set (java.util.Set)9 SortedSet (java.util.SortedSet)9 Collectors (java.util.stream.Collectors)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 BalancingConstraint (com.linkedin.kafka.cruisecontrol.analyzer.BalancingConstraint)8 ProvisionRecommendation (com.linkedin.kafka.cruisecontrol.analyzer.ProvisionRecommendation)8 ProvisionStatus (com.linkedin.kafka.cruisecontrol.analyzer.ProvisionStatus)8 ReplicaSortFunctionFactory (com.linkedin.kafka.cruisecontrol.model.ReplicaSortFunctionFactory)8