public class ReplicaPlacementGoal extends AbstractGoal
balancingConstraint, finished, minMonitoredPartitionPercentage, numWindows, optimizationResultBuilder, proposalStatsBuilder
Constructor and Description |
---|
ReplicaPlacementGoal()
Constructor used by tests
|
Modifier and Type | Method and Description |
---|---|
protected SortedSet<Broker> |
brokersToBalance(ClusterModel clusterModel)
Get sorted brokers that the rebalance process will go over to apply balancing actions to replicas they contain.
|
boolean |
canChangeReplicationFactor()
True if this goal can change replication factor of a topic
|
ModelCompletenessRequirements |
clusterModelCompletenessRequirements()
Specify the load requirements for this goal.
|
void |
finish()
Signal for finishing the process for rebalance or self-healing for this goal.
|
void |
initGoalState(ClusterModel clusterModel,
OptimizationOptions optimizationOptions,
Optional<OptimizationMetrics> optimizationMetricsOpt)
Sanity check:
There must be at least enough brokers matching a particular constraint across both replicas and observers.
|
boolean |
isHardGoal()
True if this is a hard goal, false otherwise.
|
String |
name()
Get the name of this goal.
|
protected Map<Map<String,String>,Integer> |
numReplicasRequiredByAttributeGroup(kafka.common.TopicPlacement topicPlacement)
Return the total number of replicas that should be present on a rack regardless of observer/sync-replica status
|
ActionAcceptance |
partitionActionAcceptance(PartitionBalancingAction action,
ClusterModel clusterModel)
Checks if the action on the partition specified by the
PartitionBalancingAction
is acceptable. |
boolean |
partitionActionSelfSatisfied(ClusterModel clusterModel,
PartitionBalancingAction action)
Check if requirements of this goal are not violated if this partition action is applied
to the given cluster state, false otherwise.
|
protected void |
rebalanceForBroker(Broker broker,
ClusterModel clusterModel,
Set<Goal> optimizedGoals,
OptimizationOptions optimizationOptions)
Try to rebalance each broker by moving any replicas that exceed the total number of partition replicas for a rack
to a rack with unsatisfied constraints.
|
ActionAcceptance |
replicaActionAcceptance(ReplicaBalancingAction action,
ClusterModel clusterModel)
Assuming that the cluster already satisfies replica placement constraints, then:
Replica movement from broker A to broker B is accepted in two cases
1.
|
boolean |
replicaActionSelfSatisfied(ClusterModel clusterModel,
ReplicaBalancingAction action)
Check if requirements of this goal are not violated if this replica action is applied
to the given cluster state, false otherwise.
|
protected boolean |
shouldMoveReplica(Replica replica,
ClusterModel clusterModel)
We should move a replica if it has a topic placement specified and there are more replicas on the rack than
specified by the constraint.
|
protected int |
totalReplicasMatchingConstraint(Map<String,String> constraint,
org.apache.kafka.common.TopicPartition topicPartition,
ClusterModel clusterModel)
Computes the number of alive replicas on a rack.
|
protected void |
updateGoalState(ClusterModel clusterModel,
Set<String> excludedTopics)
Validate that all topic placements have been satisfied.
|
changeObservership, configure, maybeApplyBalancingAction, maybeApplyBalancingAction, maybeMoveReplicaBetweenDisks, optimize, proposalTrackingOptions, relocateReplica, selfSatisfied, shouldExclude, shouldExclude, shouldTryLeadershipMovement, toString, tryAcceptProposal, updateReplicationFactor
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
actionAcceptance, clusterModelStatsComparator, optimize
public ActionAcceptance replicaActionAcceptance(ReplicaBalancingAction action, ClusterModel clusterModel)
action
- Action to be checked for acceptance.clusterModel
- State of the cluster before application of the action.public ActionAcceptance partitionActionAcceptance(PartitionBalancingAction action, ClusterModel clusterModel)
GoalBalancingActionAcceptance
PartitionBalancingAction
is acceptable.
For performance optimization purposes, it is recommended goals return the wider-level action acceptance first
(e.g ActionAcceptance.BROKER_REJECT
versus ActionAcceptance.REPLICA_REJECT
) as that helps
the proposal-generating logic short-circuit invalid proposal generations.action
- Action to be checked for acceptance.clusterModel
- State of the cluster before application of the action.
We operate under the assumption that this method is called only after ReplicaPlacementGoal has been
optimized, so the clusterModel is in a state that satisfies all TopicPlacement constraints.public ModelCompletenessRequirements clusterModelCompletenessRequirements()
Goal
public String name()
Goal
name
in interface Goal
name
in class AbstractGoal
public void finish()
Goal
public boolean canChangeReplicationFactor()
Goal
public boolean isHardGoal()
Goal
protected SortedSet<Broker> brokersToBalance(ClusterModel clusterModel)
AbstractGoal
brokersToBalance
in class AbstractGoal
clusterModel
- The state of the cluster.public boolean replicaActionSelfSatisfied(ClusterModel clusterModel, ReplicaBalancingAction action)
GoalBalancingActionAcceptance
clusterModel
- The state of the cluster.action
- Action containing information about potential modification to the given cluster model.public boolean partitionActionSelfSatisfied(ClusterModel clusterModel, PartitionBalancingAction action)
GoalBalancingActionAcceptance
clusterModel
- The state of the cluster.action
- Action containing information about potential modification to the given cluster model.public void initGoalState(ClusterModel clusterModel, OptimizationOptions optimizationOptions, Optional<OptimizationMetrics> optimizationMetricsOpt) throws OptimizationFailureException
initGoalState
in class AbstractGoal
clusterModel
- The state of the cluster.optimizationOptions
- Options to take into account during optimization -- e.g. excluded topics.optimizationMetricsOpt
- An optional of OptimizationMetrics
used to capture various metrics throughout this goal's optimization run.OptimizationFailureException
protected void updateGoalState(ClusterModel clusterModel, Set<String> excludedTopics) throws OptimizationFailureException
updateGoalState
in class AbstractGoal
clusterModel
- The state of the cluster.excludedTopics
- The topics that should be excluded from the optimization action.OptimizationFailureException
protected void rebalanceForBroker(Broker broker, ClusterModel clusterModel, Set<Goal> optimizedGoals, OptimizationOptions optimizationOptions) throws OptimizationFailureException
rebalanceForBroker
in class AbstractGoal
broker
- Broker to be balanced.clusterModel
- The state of the cluster.optimizedGoals
- Optimized goals.optimizationOptions
- Options to take into account during optimization -- e.g. excluded topics.OptimizationFailureException
protected boolean shouldMoveReplica(Replica replica, ClusterModel clusterModel)
protected int totalReplicasMatchingConstraint(Map<String,String> constraint, org.apache.kafka.common.TopicPartition topicPartition, ClusterModel clusterModel)