AbstractControllerBrokerRequestBatch¶
AbstractControllerBrokerRequestBatch is an abstraction of ControllerBrokerRequestBatches that can send controller requests to brokers.
Contract¶
Sending ControllerEvent¶
sendEvent(
event: ControllerEvent): Unit
Sends the ControllerEvent
Used when:
AbstractControllerBrokerRequestBatchis requested to sendLeaderAndIsrRequest, sendUpdateMetadataRequests, sendStopReplicaRequests
Sending Request (to Broker)¶
sendRequest(
brokerId: Int,
request: AbstractControlRequest.Builder[_ <: AbstractControlRequest],
callback: AbstractResponse => Unit = null): Unit
Sends out an AbstractControlRequest to the given broker (with optional callback to handle a response)
Used when:
AbstractControllerBrokerRequestBatchis requested to sendLeaderAndIsrRequest, sendUpdateMetadataRequests, sendStopReplicaRequests
Implementations¶
Creating Instance¶
AbstractControllerBrokerRequestBatch takes the following to be created:
- KafkaConfig
- ControllerContext
-
StateChangeLogger
Abstract Class
AbstractControllerBrokerRequestBatch is an abstract class and cannot be created directly. It is created indirectly for the concrete AbstractControllerBrokerRequestBatches.
Preparing New Batch¶
newBatch(): Unit
newBatch throws an IllegalStateException when any of the internal registries are not empty:
-
Controller to broker state change requests batch is not empty while creating a new one. Some LeaderAndIsr state changes [leaderAndIsrRequestMap] might be lost -
Controller to broker state change requests batch is not empty while creating a new one. Some StopReplica state changes [stopReplicaRequestMap] might be lost -
updateMetadataRequestBrokerSet
Controller to broker state change requests batch is not empty while creating a new one. Some UpdateMetadata state changes to brokers [updateMetadataRequestBrokerSet] with partition info [updateMetadataRequestPartitionInfoMap] might be lost
newBatch is used when:
KafkaControlleris requested to updateLeaderEpochAndSendRequest, sendUpdateMetadataRequest, doControlledShutdownZkPartitionStateMachineis requested to handleStateChangesZkReplicaStateMachineis requested to handleStateChanges
Sending Controller Requests To Brokers¶
sendRequestsToBrokers(
controllerEpoch: Int): Unit
sendRequestsToBrokers sends LeaderAndIsr requests out to brokers.
sendRequestsToBrokers sends UpdateMetadata requests out to brokers.
sendRequestsToBrokers sends StopReplica requests out to brokers.
sendRequestsToBrokers is used when:
KafkaControlleris requested to updateLeaderEpochAndSendRequest, sendUpdateMetadataRequest, doControlledShutdownZkPartitionStateMachineis requested to handleStateChangesZkReplicaStateMachineis requested to handleStateChanges
Sending Out UpdateMetadata Requests¶
sendUpdateMetadataRequests(
controllerEpoch: Int,
stateChangeLog: StateChangeLogger): Unit
sendUpdateMetadataRequests prints out the following INFO message to the logs:
Sending UpdateMetadata request to brokers [updateMetadataRequestBrokerSet] for [size] partitions
sendUpdateMetadataRequests...FIXME
Sending Out LeaderAndIsr Requests¶
sendLeaderAndIsrRequest(
controllerEpoch: Int,
stateChangeLog: StateChangeLogger): Unit
sendLeaderAndIsrRequest uses the leaderAndIsrRequestMap internal registry for the brokers and partitions to send LeaderAndIsr requests to.
For every broker (that is liveOrShuttingDownBrokerIds) and partitions (with their state), sendLeaderAndIsrRequest determines the type of request:
become-leaderwhen the broker is assumed the leaderbecome-followerotherwise
sendLeaderAndIsrRequest prints out the following TRACE message to the logs:
Sending [typeOfRequest] LeaderAndIsr request [state] to broker [broker] for partition [partition]
sendLeaderAndIsrRequest prints out the following INFO message to the logs:
Sending LeaderAndIsr request to broker [broker]
with [numBecomeLeaders] become-leader and [becomeFollower] become-follower partitions
sendLeaderAndIsrRequest creates a LeaderAndIsrRequest.Builder for sending a LeaderAndIsr request to the brokers (one by one).
In the end, sendLeaderAndIsrRequest clears out the leaderAndIsrRequestMap.
addLeaderAndIsrRequestForBrokers¶
addLeaderAndIsrRequestForBrokers(
brokerIds: Seq[Int],
topicPartition: TopicPartition,
leaderIsrAndControllerEpoch: LeaderIsrAndControllerEpoch,
replicaAssignment: ReplicaAssignment,
isNew: Boolean): Unit
addLeaderAndIsrRequestForBrokers...FIXME
addLeaderAndIsrRequestForBrokers is used when:
KafkaControlleris requested to updateLeaderEpochAndSendRequestZkPartitionStateMachineis requested to initializeLeaderAndIsrForPartitions and doElectLeaderForPartitionsZkReplicaStateMachineis requested to doHandleStateChanges