This is the zookeeper listener that triggers all the state transitions for a replica
This API exercises the replica's state machine.
This API exercises the replica's state machine. It ensures that every state transition happens from a legal previous state to the target state. Valid state transitions are: NonExistentReplica --> NewReplica --send LeaderAndIsr request with current leader and isr to the new replica and UpdateMetadata request for the partition to every live broker
NewReplica -> OnlineReplica --add the new replica to the assigned replica list if needed
OnlineReplica,OfflineReplica -> OnlineReplica --send LeaderAndIsr request with current leader and isr to the new replica and UpdateMetadata request for the partition to every live broker
NewReplica,OnlineReplica,OfflineReplica,ReplicaDeletionIneligible -> OfflineReplica --send StopReplicaRequest to the replica (w/o deletion) --remove this replica from the isr and send LeaderAndIsr request (with new isr) to the leader replica and UpdateMetadata request for the partition to every live broker.
OfflineReplica -> ReplicaDeletionStarted --send StopReplicaRequest to the replica (with deletion)
ReplicaDeletionStarted -> ReplicaDeletionSuccessful -- mark the state of the replica in the state machine
ReplicaDeletionStarted -> ReplicaDeletionIneligible -- mark the state of the replica in the state machine
ReplicaDeletionSuccessful -> NonExistentReplica -- remove the replica from the in memory partition replica assignment cache
The replica for which the state transition is invoked
The end state that the replica should be moved to
This API is invoked by the broker change controller callbacks and the startup API of the state machine
This API is invoked by the broker change controller callbacks and the startup API of the state machine
The list of replicas (brokers) that need to be transitioned to the target state
The state that the replicas should be moved to The controller's allLeaders cache should have been updated before this
Invoked on controller shutdown.
Invoked on successful controller election.
Invoked on successful controller election. First registers a broker change listener since that triggers all state transitions for replicas. Initializes the state of replicas for all partitions by reading from zookeeper. Then triggers the OnlineReplica state change for all replicas.
This class represents the state machine for replicas. It defines the states that a replica can be in, and transitions to move the replica to another legal state. The different states that a replica can be in are - 1. NewReplica : The controller can create new replicas during partition reassignment. In this state, a replica can only get become follower state change request. Valid previous state is NonExistentReplica 2. OnlineReplica : Once a replica is started and part of the assigned replicas for its partition, it is in this state. In this state, it can get either become leader or become follower state change requests. Valid previous state are NewReplica, OnlineReplica or OfflineReplica 3. OfflineReplica : If a replica dies, it moves to this state. This happens when the broker hosting the replica is down. Valid previous state are NewReplica, OnlineReplica 4. ReplicaDeletionStarted: If replica deletion starts, it is moved to this state. Valid previous state is OfflineReplica 5. ReplicaDeletionSuccessful: If replica responds with no error code in response to a delete replica request, it is moved to this state. Valid previous state is ReplicaDeletionStarted 6. ReplicaDeletionIneligible: If replica deletion fails, it is moved to this state. Valid previous state is ReplicaDeletionStarted 7. NonExistentReplica: If a replica is deleted successfully, it is moved to this state. Valid previous state is ReplicaDeletionSuccessful