@ThreadSafe public class GoalOptimizationHistory extends Object implements AutoCloseable
TopicPartition
s. It tracks the movements in a
TopicPartitionHistoryPool
and generate suspension event when too many repeated movements are detected for a
TopicPartition
. It also spawns two separate threads to automatically clean the expired goal optimization
history items. When TopicPartitionHistory
s are recorded or expired, notifications will be sent to the
registered GoalOptimizationHistoryListener
so that the listens can take actions accordingly.Modifier and Type | Method and Description |
---|---|
void |
addSuspendedTopicPartitionListener(GoalOptimizationHistoryListener<SuspendedTopicPartition> suspendedTopicPartitionListener)
Adds a listener to the suspended topic partition listeners list.
|
void |
addTopicPartitionMovementListener(GoalOptimizationHistoryListener<TopicPartitionMovement> topicPartitionMovementListener)
Adds a listener to the topic partition movement listeners list.
|
void |
clear()
Clears all the goal optimization history.
|
void |
close()
Close method is called when SBC is disabled, so that we don't leave the two cleaner threads alone.
|
static GoalOptimizationHistory |
create(KafkaCruiseControlConfig config)
Creates a
GoalOptimizationHistory with given Kafka cruise control configuration. |
int |
numberOfMovements(org.apache.kafka.common.TopicPartition tp)
Retrieves the recorded number of movements of a
TopicPartition . |
void |
record(TopicPartitionMovement topicPartitionMovement)
Records a new
TopicPartitionMovement and perform necessary subsequent actions: |
public static GoalOptimizationHistory create(KafkaCruiseControlConfig config)
GoalOptimizationHistory
with given Kafka cruise control configuration. This method should only be
called once during SBC startup.public void addTopicPartitionMovementListener(GoalOptimizationHistoryListener<TopicPartitionMovement> topicPartitionMovementListener)
public void addSuspendedTopicPartitionListener(GoalOptimizationHistoryListener<SuspendedTopicPartition> suspendedTopicPartitionListener)
public void record(TopicPartitionMovement topicPartitionMovement)
TopicPartitionMovement
and perform necessary subsequent actions:
1. Sends out notifications to topic partition movement listeners about the new movement
2. If the number of movements for a topic partition exceeds certain threshold, records a new
SuspendedTopicPartition
and sends out notifications to the suspended topic partition listeners about the
new suspension
topicPartitionMovement
- new topic partition movementpublic void clear()
1. When self-healing succeeds, any topic partition movement recorded during the last self-healing balancing round or before should not impact the rounds afterwards
2. When brokers are added/removed, it doesn't make sense to restrict future movements based on the existing topic partition movements since cluster topology changed.
public int numberOfMovements(org.apache.kafka.common.TopicPartition tp)
TopicPartition
. Due to the concurrency nature of the adding
and removing of topic partition history, the returned value is the best effort estimation.public void close() throws Exception
close
in interface AutoCloseable
Exception