For NewPartition target state, doHandleStateChanges goes over the valid partitions and for every partition prints out the following TRACE message to the logs and requests the <> to <> to NewPartition state.
Changed partition [partition] state from [state] to NewPartition with assigned replicas [partitionReplicaAssignment]
For every partition with leader election successful, doHandleStateChanges prints out the following INFO message to the logs and requests the ControllerContext to putPartitionState to OnlinePartition state.
Changed partition [partition] from [state] to OnlinePartition with state [leaderAndIsr]
In the end, doHandleStateChanges returns the partitions with election failed.
For OfflinePartition target state, doHandleStateChanges goes over the valid partitions and for every partition prints out the following TRACE message to the logs and requests the <> to <> to OfflinePartition state.
Changed partition [partition] state from [state] to OfflinePartition
For NonExistentPartition target state, doHandleStateChanges goes over the valid partitions and for every partition prints out the following TRACE message to the logs and requests the <> to <> to NonExistentPartition state.
Changed partition [partition] state from [state] to NonExistentPartition
For every partition state response, doElectLeaderForPartitionsdecodes the response (if possible) and adds it to validLeaderAndIsrs internal registry (of (TopicPartition, LeaderAndIsr) pairs) or to failed elections (of TopicPartition, Either[Exception, LeaderAndIsr]s).
doElectLeaderForPartitions branches off per the input PartitionLeaderElectionStrategy that gives partitions with and without leaders elected.
doElectLeaderForPartitions prints out the following DEBUG message to the logs for every partition with no leader elected:
Controller failed to elect leader for partition [partition].
Attempted to write state [partition], but failed with bad ZK version.
This will be retried.
initializeLeaderAndIsrForPartitions starts by requesting the <> for the <> for every partition (in the given partitions).
From the partition replica assignments, initializeLeaderAndIsrForPartitions makes sure that the replicas are all <> only (per the <>) so all other partitions are filtered out (excluded).
initializeLeaderAndIsrForPartitions splits the partitions (with online replicas only) into two sets with and without replicas (partitionsWithLiveReplicas and partitionsWithoutLiveReplicas, respectively).
For every partition without live (online) replicas, initializeLeaderAndIsrForPartitions <>:
Controller [controllerId] epoch [epoch] failed to change state for partition [partition] from NewPartition to OnlinePartition
Controller [controllerId] epoch [epoch] encountered error during state change of partition [partition] from New to Online, assigned replicas are [[replicas]], live brokers are [[liveBrokerIds]]. No assigned replica is alive.
initializeLeaderAndIsrForPartitions converts the partitions with live (online) replicas into leaderIsrAndControllerEpochs (LeaderIsrAndControllerEpoch with LeaderAndIsr) and for every pair initializeLeaderAndIsrForPartitions requests the <> to <>.
For every successful response (from <>), initializeLeaderAndIsrForPartitions requests the following:
. The <> to record the leaderIsrAndControllerEpoch for the partition (in the <> registry)
. The <> to <> (with isNew flag on)
In the end, initializeLeaderAndIsrForPartitions returns the partitions that were successfully initialized.
In case of ControllerMovedException (while...FIXME), initializeLeaderAndIsrForPartitions...FIXME
In case of any other error (Exception) (while...FIXME), initializeLeaderAndIsrForPartitions...FIXME
NOTE: initializeLeaderAndIsrForPartitions is used exclusively when ZkPartitionStateMachine is requested to <> (for <>).