Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/kafka/server/AlterIsrManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object AlterIsrManager {
time = time,
metrics = metrics,
config = config,
channelName = "alterIsrChannel",
channelName = "alterIsr",
threadNamePrefix = threadNamePrefix,
retryTimeoutMs = Long.MaxValue
)
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/kafka/server/BrokerServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ class BrokerServer(
time,
metrics,
config,
channelName = "controllerForwardingChannel",
channelName = "forwarding",
threadNamePrefix,
retryTimeoutMs = 60000
)
clientToControllerChannelManager.start()
forwardingManager = new ForwardingManagerImpl(clientToControllerChannelManager)

val apiVersionManager = ApiVersionManager(
Expand All @@ -211,7 +212,7 @@ class BrokerServer(
time,
metrics,
config,
channelName = "alterisr",
channelName = "alterIsr",
threadNamePrefix,
retryTimeoutMs = Long.MaxValue
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class BrokerToControllerChannelManagerImpl(
threadNamePrefix: Option[String],
retryTimeoutMs: Long
) extends BrokerToControllerChannelManager with Logging {
private val logContext = new LogContext(s"[broker-${config.brokerId}-to-controller] ")
private val logContext = new LogContext(s"[BrokerToControllerChannelManager broker=${config.brokerId} name=$channelName] ")
Comment thread
mumrah marked this conversation as resolved.
private val manualMetadataUpdater = new ManualMetadataUpdater()
private val apiVersions = new ApiVersions()
private val currentNodeApiVersions = NodeApiVersions.create()
Expand Down Expand Up @@ -226,8 +226,8 @@ class BrokerToControllerChannelManagerImpl(
)
}
val threadName = threadNamePrefix match {
case None => s"broker-${config.brokerId}-to-controller-send-thread"
case Some(name) => s"$name:broker-${config.brokerId}-to-controller-send-thread"
case None => s"BrokerToControllerChannelManager broker=${config.brokerId} name=$channelName"
case Some(name) => s"$name:BrokerToControllerChannelManager broker=${config.brokerId} name=$channelName"
}

new BrokerToControllerRequestThread(
Expand Down Expand Up @@ -304,6 +304,9 @@ class BrokerToControllerRequestThread(
}

def enqueue(request: BrokerToControllerQueueItem): Unit = {
if (!this.isAlive) {
Comment thread
mumrah marked this conversation as resolved.
Outdated
throw new IllegalStateException("Cannot enqueue a request if the request thread is not running")
}
requestQueue.add(request)
if (activeControllerAddress().isDefined) {
wakeup()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/kafka/server/KafkaServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class KafkaServer(
time = time,
metrics = metrics,
config = config,
channelName = "controllerForwardingChannel",
channelName = "forwarding",
threadNamePrefix = threadNamePrefix,
retryTimeoutMs = config.requestTimeoutMs.longValue)
brokerToControllerManager.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BrokerToControllerRequestThreadTest {
val retryTimeoutMs = 30000
val testRequestThread = new BrokerToControllerRequestThread(mockClient, new ManualMetadataUpdater(), controllerNodeProvider,
config, time, "", retryTimeoutMs)
testRequestThread.start()

val completionHandler = new TestRequestCompletionHandler(None)
val queueItem = BrokerToControllerQueueItem(
Expand Down Expand Up @@ -82,6 +83,7 @@ class BrokerToControllerRequestThreadTest {
val expectedResponse = RequestTestUtils.metadataUpdateWith(2, Collections.singletonMap("a", 2))
val testRequestThread = new BrokerToControllerRequestThread(mockClient, new ManualMetadataUpdater(), controllerNodeProvider,
config, time, "", retryTimeoutMs = Long.MaxValue)
testRequestThread.start()
mockClient.prepareResponse(expectedResponse)

val completionHandler = new TestRequestCompletionHandler(Some(expectedResponse))
Expand Down Expand Up @@ -123,6 +125,7 @@ class BrokerToControllerRequestThreadTest {
val expectedResponse = RequestTestUtils.metadataUpdateWith(3, Collections.singletonMap("a", 2))
val testRequestThread = new BrokerToControllerRequestThread(mockClient, new ManualMetadataUpdater(),
controllerNodeProvider, config, time, "", retryTimeoutMs = Long.MaxValue)
testRequestThread.start()

val completionHandler = new TestRequestCompletionHandler(Some(expectedResponse))
val queueItem = BrokerToControllerQueueItem(
Expand Down Expand Up @@ -172,6 +175,7 @@ class BrokerToControllerRequestThreadTest {
val expectedResponse = RequestTestUtils.metadataUpdateWith(3, Collections.singletonMap("a", 2))
val testRequestThread = new BrokerToControllerRequestThread(mockClient, new ManualMetadataUpdater(), controllerNodeProvider,
config, time, "", retryTimeoutMs = Long.MaxValue)
testRequestThread.start()

val completionHandler = new TestRequestCompletionHandler(Some(expectedResponse))
val queueItem = BrokerToControllerQueueItem(
Expand Down Expand Up @@ -226,6 +230,7 @@ class BrokerToControllerRequestThreadTest {
Collections.singletonMap("a", 2))
val testRequestThread = new BrokerToControllerRequestThread(mockClient, new ManualMetadataUpdater(), controllerNodeProvider,
config, time, "", retryTimeoutMs)
testRequestThread.start()

val completionHandler = new TestRequestCompletionHandler()
val queueItem = BrokerToControllerQueueItem(
Expand Down Expand Up @@ -283,6 +288,7 @@ class BrokerToControllerRequestThreadTest {

val testRequestThread = new BrokerToControllerRequestThread(mockClient, new ManualMetadataUpdater(), controllerNodeProvider,
config, time, "", retryTimeoutMs = Long.MaxValue)
testRequestThread.start()

testRequestThread.enqueue(queueItem)
pollUntil(testRequestThread, () => callbackResponse.get != null)
Expand Down Expand Up @@ -319,12 +325,44 @@ class BrokerToControllerRequestThreadTest {

val testRequestThread = new BrokerToControllerRequestThread(mockClient, new ManualMetadataUpdater(), controllerNodeProvider,
config, time, "", retryTimeoutMs = Long.MaxValue)
testRequestThread.start()

testRequestThread.enqueue(queueItem)
pollUntil(testRequestThread, () => callbackResponse.get != null)
assertNotNull(callbackResponse.get.authenticationException)
}

@Test
def testThreadNotStarted(): Unit = {
// Make sure we throw if we enqueue anything while the thread is not running
val time = new MockTime()
val config = new KafkaConfig(TestUtils.createBrokerConfig(1, "localhost:2181"))
val controllerId = 2

val metadata = mock(classOf[Metadata])
val mockClient = new MockClient(time, metadata)

val controllerNodeProvider = mock(classOf[ControllerNodeProvider])
val activeController = new Node(controllerId, "host", 1234)

when(controllerNodeProvider.get()).thenReturn(Some(activeController))
Comment thread
mumrah marked this conversation as resolved.
Outdated

val expectedResponse = RequestTestUtils.metadataUpdateWith(2, Collections.singletonMap("a", 2))
Comment thread
mumrah marked this conversation as resolved.
Outdated
val testRequestThread = new BrokerToControllerRequestThread(mockClient, new ManualMetadataUpdater(), controllerNodeProvider,
config, time, "", retryTimeoutMs = Long.MaxValue)
mockClient.prepareResponse(expectedResponse)

val completionHandler = new TestRequestCompletionHandler(Some(expectedResponse))
val queueItem = BrokerToControllerQueueItem(
time.milliseconds(),
new MetadataRequest.Builder(new MetadataRequestData()),
completionHandler
)

assertThrows(classOf[IllegalStateException], () => testRequestThread.enqueue(queueItem))
assertEquals(0, testRequestThread.queueSize)
}

private def pollUntil(
requestThread: BrokerToControllerRequestThread,
condition: () => Boolean,
Expand Down