Browse Source

MINOR: A few cleanups in BrokerToControllerChannelManager (#11937)

Make the code style more consistent

Reviewers: Luke Chen <showuon@gmail.com>
pull/11944/head
David Jacot 3 years ago committed by GitHub
parent
commit
12bb23157c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      core/src/main/scala/kafka/server/BrokerToControllerChannelManager.scala

26
core/src/main/scala/kafka/server/BrokerToControllerChannelManager.scala

@ -78,9 +78,11 @@ class MetadataCacheControllerNodeProvider(
} }
object RaftControllerNodeProvider { object RaftControllerNodeProvider {
def apply(raftManager: RaftManager[ApiMessageAndVersion], def apply(
raftManager: RaftManager[ApiMessageAndVersion],
config: KafkaConfig, config: KafkaConfig,
controllerQuorumVoterNodes: Seq[Node]): RaftControllerNodeProvider = { controllerQuorumVoterNodes: Seq[Node]
): RaftControllerNodeProvider = {
val controllerListenerName = new ListenerName(config.controllerListenerNames.head) val controllerListenerName = new ListenerName(config.controllerListenerNames.head)
val controllerSecurityProtocol = config.effectiveListenerSecurityProtocolMap.getOrElse(controllerListenerName, SecurityProtocol.forName(controllerListenerName.value())) val controllerSecurityProtocol = config.effectiveListenerSecurityProtocolMap.getOrElse(controllerListenerName, SecurityProtocol.forName(controllerListenerName.value()))
val controllerSaslMechanism = config.saslMechanismControllerProtocol val controllerSaslMechanism = config.saslMechanismControllerProtocol
@ -98,7 +100,8 @@ object RaftControllerNodeProvider {
* Finds the controller node by checking the metadata log manager. * Finds the controller node by checking the metadata log manager.
* This provider is used when we are using a Raft-based metadata quorum. * This provider is used when we are using a Raft-based metadata quorum.
*/ */
class RaftControllerNodeProvider(val raftManager: RaftManager[ApiMessageAndVersion], class RaftControllerNodeProvider(
val raftManager: RaftManager[ApiMessageAndVersion],
controllerQuorumVoterNodes: Seq[Node], controllerQuorumVoterNodes: Seq[Node],
val listenerName: ListenerName, val listenerName: ListenerName,
val securityProtocol: SecurityProtocol, val securityProtocol: SecurityProtocol,
@ -133,7 +136,6 @@ object BrokerToControllerChannelManager {
} }
} }
trait BrokerToControllerChannelManager { trait BrokerToControllerChannelManager {
def start(): Unit def start(): Unit
def shutdown(): Unit def shutdown(): Unit
@ -144,7 +146,6 @@ trait BrokerToControllerChannelManager {
): Unit ): Unit
} }
/** /**
* This class manages the connection between a broker and the controller. It runs a single * This class manages the connection between a broker and the controller. It runs a single
* [[BrokerToControllerRequestThread]] which uses the broker's metadata cache as its own metadata to find * [[BrokerToControllerRequestThread]] which uses the broker's metadata cache as its own metadata to find
@ -250,13 +251,14 @@ class BrokerToControllerChannelManagerImpl(
)) ))
} }
def controllerApiVersions(): Option[NodeApiVersions] = def controllerApiVersions(): Option[NodeApiVersions] = {
requestThread.activeControllerAddress().flatMap( requestThread.activeControllerAddress().flatMap { activeController =>
activeController => if (activeController.id() == config.brokerId) if (activeController.id == config.brokerId)
Some(currentNodeApiVersions) Some(currentNodeApiVersions)
else else
Option(apiVersions.get(activeController.idString())) Option(apiVersions.get(activeController.idString))
) }
}
} }
abstract class ControllerRequestCompletionHandler extends RequestCompletionHandler { abstract class ControllerRequestCompletionHandler extends RequestCompletionHandler {
@ -351,10 +353,10 @@ class BrokerToControllerRequestThread(
requestQueue.putFirst(queueItem) requestQueue.putFirst(queueItem)
} else if (response.responseBody().errorCounts().containsKey(Errors.NOT_CONTROLLER)) { } else if (response.responseBody().errorCounts().containsKey(Errors.NOT_CONTROLLER)) {
// just close the controller connection and wait for metadata cache update in doWork // just close the controller connection and wait for metadata cache update in doWork
activeControllerAddress().foreach { controllerAddress => { activeControllerAddress().foreach { controllerAddress =>
networkClient.disconnect(controllerAddress.idString) networkClient.disconnect(controllerAddress.idString)
updateControllerAddress(null) updateControllerAddress(null)
}} }
requestQueue.putFirst(queueItem) requestQueue.putFirst(queueItem)
} else { } else {

Loading…
Cancel
Save