use of com.linkedin.kafka.cruisecontrol.analyzer.ProvisionRecommendation in project cruise-control by linkedin.
the class RackAwareGoal method ensureRackAware.
private void ensureRackAware(ClusterModel clusterModel, OptimizationOptions optimizationOptions) throws OptimizationFailureException {
// Sanity check to confirm that the final distribution is rack aware.
Set<String> excludedTopics = optimizationOptions.excludedTopics();
for (Replica leader : clusterModel.leaderReplicas()) {
if (excludedTopics.contains(leader.topicPartition().topic())) {
continue;
}
Set<String> replicaBrokersRackIds = new HashSet<>();
Set<Broker> followerBrokers = new HashSet<>(clusterModel.partition(leader.topicPartition()).followerBrokers());
// Add rack Id of replicas.
for (Broker followerBroker : followerBrokers) {
String followerRackId = followerBroker.rack().id();
replicaBrokersRackIds.add(followerRackId);
}
replicaBrokersRackIds.add(leader.broker().rack().id());
if (replicaBrokersRackIds.size() != (followerBrokers.size() + 1)) {
int missingRacks = (followerBrokers.size() + 1) - replicaBrokersRackIds.size();
ProvisionRecommendation recommendation = new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).numRacks(missingRacks).build();
throw new OptimizationFailureException(String.format("[%s] Partition %s is not rack-aware. Leader (%s) and follower brokers (%s).", name(), leader.topicPartition(), leader.broker(), followerBrokers), recommendation);
}
}
}
use of com.linkedin.kafka.cruisecontrol.analyzer.ProvisionRecommendation in project cruise-control by linkedin.
the class CapacityGoal method postSanityCheck.
private void postSanityCheck(boolean utilizationOverLimit, Broker broker, double brokerCapacityLimit, double hostCapacityLimit) throws OptimizationFailureException {
// 1. Capacity violation check -- note that this check also ensures that no replica resides on dead brokers.
if (utilizationOverLimit) {
Resource currentResource = resource();
ProvisionRecommendation recommendation = new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).numBrokers(1).resource(currentResource).build();
if (!currentResource.isHostResource()) {
// Utilization is above the capacity limit after all replicas in the given source broker were checked.
throw new OptimizationFailureException(String.format("[%s] Utilization (%.2f) of broker %d violated capacity limit (%.2f) for resource %s.", name(), broker.load().expectedUtilizationFor(currentResource), broker.id(), brokerCapacityLimit, currentResource), recommendation);
} else {
throw new OptimizationFailureException(String.format("[%s] Utilization (%.2f) of host %s violated capacity limit (%.2f) for resource %s.", name(), broker.host().load().expectedUtilizationFor(currentResource), broker.host().name(), hostCapacityLimit, currentResource), recommendation);
}
}
// 2. Ensure that no offline replicas remain in the broker.
if (!broker.currentOfflineReplicas().isEmpty()) {
ProvisionRecommendation recommendation = new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).numBrokers(1).resource(resource()).build();
throw new OptimizationFailureException(String.format("[%s] Cannot remove offline replicas from broker %d.", name(), broker.id()), recommendation);
}
}
use of com.linkedin.kafka.cruisecontrol.analyzer.ProvisionRecommendation in project cruise-control by linkedin.
the class GoalUtils method ensureNoOfflineReplicas.
/**
* Checks the replicas that are supposed to be moved away from the dead brokers or broken disks have been moved.
* If there are still replicas on the dead brokers or broken disks, throws an exception.
* @param clusterModel the cluster model to check.
* @param goalName Goal name for which the sanity check is executed.
* @throws OptimizationFailureException when there are still replicas on the dead brokers or on broken disks.
*/
public static void ensureNoOfflineReplicas(ClusterModel clusterModel, String goalName) throws OptimizationFailureException {
// Sanity check: No self-healing eligible replica should remain at a decommissioned broker or on broken disk.
for (Replica replica : clusterModel.selfHealingEligibleReplicas()) {
if (replica.isCurrentOffline()) {
ProvisionRecommendation recommendation = new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).numBrokers(1).build();
Broker broker = replica.broker();
throw new OptimizationFailureException(String.format("[%s] Cannot remove %s from %s broker %d (has %d replicas).", goalName, replica, broker.state(), broker.id(), broker.replicas().size()), recommendation);
}
}
}
use of com.linkedin.kafka.cruisecontrol.analyzer.ProvisionRecommendation in project cruise-control by linkedin.
the class IntraBrokerDiskCapacityGoal method updateGoalState.
/**
* Update goal state.
* Sanity check: After completion of balancing the resource, confirm that the utilization is under the capacity and finish.
*
* @param clusterModel The state of the cluster.
* @param optimizationOptions Options to take into account during optimization.
*/
@Override
protected void updateGoalState(ClusterModel clusterModel, OptimizationOptions optimizationOptions) throws OptimizationFailureException {
for (Broker broker : brokersToBalance(clusterModel)) {
for (Disk disk : broker.disks()) {
if (disk.isAlive() && isUtilizationOverLimit(disk)) {
// The utilization of the host for the resource is over the capacity limit.
double requiredCapacity = disk.utilization() / _balancingConstraint.capacityThreshold(RESOURCE);
ProvisionRecommendation recommendation = new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).numDisks(1).totalCapacity(requiredCapacity).build();
throw new OptimizationFailureException(String.format("[%s] Utilization (%.2f) for disk %s on broker %d is above capacity limit.", name(), disk.utilization(), disk, broker.id()), recommendation);
}
}
}
finish();
}
use of com.linkedin.kafka.cruisecontrol.analyzer.ProvisionRecommendation in project cruise-control by linkedin.
the class RightsizeRequest method handle.
@Override
protected RightsizeResult handle() {
KafkaCruiseControlConfig config = _kafkaCruiseControl.config();
ProvisionRecommendation recommendation = createProvisionRecommendation();
Map<String, ProvisionRecommendation> provisionRecommendation;
provisionRecommendation = Collections.singletonMap(RECOMMENDER_UP, recommendation);
ProvisionerState provisionerState = _kafkaCruiseControl.provisioner().rightsize(provisionRecommendation, new RightsizeOptions());
return new RightsizeResult(recommendation, provisionerState, config);
}
Aggregations