MINOR: A few cleanups in BrokerToControllerChannelManager (#11937)

Make the code style more consistent

Reviewers: Luke Chen <showuon@gmail.com>
This commit is contained in:
David Jacot 2022-03-24 08:49:25 +01:00 committed by GitHub
parent e8f09007e4
commit 12bb23157c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 18 deletions

View File

@ -78,9 +78,11 @@ class MetadataCacheControllerNodeProvider(
} }
object RaftControllerNodeProvider { object RaftControllerNodeProvider {
def apply(raftManager: RaftManager[ApiMessageAndVersion], def apply(
config: KafkaConfig, raftManager: RaftManager[ApiMessageAndVersion],
controllerQuorumVoterNodes: Seq[Node]): RaftControllerNodeProvider = { config: KafkaConfig,
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,12 +100,13 @@ 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(
controllerQuorumVoterNodes: Seq[Node], val raftManager: RaftManager[ApiMessageAndVersion],
val listenerName: ListenerName, controllerQuorumVoterNodes: Seq[Node],
val securityProtocol: SecurityProtocol, val listenerName: ListenerName,
val saslMechanism: String val securityProtocol: SecurityProtocol,
) extends ControllerNodeProvider with Logging { val saslMechanism: String
) extends ControllerNodeProvider with Logging {
val idToNode = controllerQuorumVoterNodes.map(node => node.id() -> node).toMap val idToNode = controllerQuorumVoterNodes.map(node => node.id() -> node).toMap
override def get(): Option[Node] = { override def get(): Option[Node] = {
@ -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 {