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;
}
}
Aggregations