-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-2300: Error in controller log when broker tries to rejoin cluster #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dbd1bf3
KAFKA-2300: Error in controller log when broker tries to rejoin cluster
fpj 9b6390a
Updated package name and removed unnecessary imports.
fpj f1261b1
Fixed some style issues.
fpj aa6ec90
KAFKA-2300: Wrapped all occurences of sendRequestToBrokers with try/c…
fpj 7bd2edb
KAFKA-2300: Removed unnecessary s" occurrences.
fpj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
core/src/test/scala/unit/kafka/controller/ControllerFailoverTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package kafka.controller | ||
|
|
||
| import java.util.concurrent.LinkedBlockingQueue | ||
| import java.util.Properties | ||
|
|
||
| import junit.framework.Assert._ | ||
| import org.scalatest.junit.JUnit3Suite | ||
|
|
||
| import org.junit.{Test, After, Before} | ||
| import org.I0Itec.zkclient.{IZkDataListener, IZkStateListener, ZkClient} | ||
| import org.I0Itec.zkclient.serialize.ZkSerializer | ||
| import org.apache.log4j.{Logger, Level} | ||
|
|
||
| import kafka.api.RequestOrResponse | ||
| import kafka.common.TopicAndPartition | ||
| import kafka.integration.KafkaServerTestHarness | ||
| import kafka.server.BrokerState | ||
| import kafka.server.KafkaConfig | ||
| import kafka.server.KafkaServer | ||
| import kafka.server.RunningAsController | ||
| import kafka.utils._ | ||
| import kafka.utils.TestUtils._ | ||
|
|
||
| import scala.collection.Map | ||
| import scala.collection.mutable | ||
|
|
||
|
|
||
| class ControllerFailoverTest extends KafkaServerTestHarness with Logging { | ||
| val log = Logger.getLogger(classOf[ControllerFailoverTest]) | ||
| val numNodes = 2 | ||
| val numParts = 1 | ||
| val msgQueueSize = 1 | ||
| val topic = "topic1" | ||
| val overridingProps = new Properties() | ||
| overridingProps.put(KafkaConfig.NumPartitionsProp, numParts.toString) | ||
|
|
||
| override def generateConfigs() = TestUtils.createBrokerConfigs(numNodes, zkConnect) | ||
| .map(KafkaConfig.fromProps(_, overridingProps)) | ||
|
|
||
| override def setUp() { | ||
| super.setUp() | ||
| } | ||
|
|
||
| override def tearDown() { | ||
| super.tearDown() | ||
| } | ||
|
|
||
| /** | ||
| * See @link{https://issues.apache.org/jira/browse/KAFKA-2300} | ||
| * for the background of this test case | ||
| */ | ||
| def testMetadataUpdate() { | ||
| log.setLevel(Level.INFO) | ||
| var controller: KafkaServer = this.servers.head; | ||
| // Find the current controller | ||
| val epochMap: mutable.Map[Int, Int] = mutable.Map.empty | ||
| for (server <- this.servers) { | ||
| epochMap += (server.config.brokerId -> server.kafkaController.epoch) | ||
| if(server.kafkaController.isActive()) { | ||
| controller = server | ||
| } | ||
| } | ||
| // Create topic with one partition | ||
| kafka.admin.AdminUtils.createTopic(controller.zkClient, topic, 1, 1) | ||
| val topicPartition = TopicAndPartition("topic1", 0) | ||
| var partitions = controller.kafkaController.partitionStateMachine.partitionsInState(OnlinePartition) | ||
| while (!partitions.contains(topicPartition)) { | ||
| partitions = controller.kafkaController.partitionStateMachine.partitionsInState(OnlinePartition) | ||
| Thread.sleep(100) | ||
| } | ||
| // Replace channel manager with our mock manager | ||
| controller.kafkaController.controllerContext.controllerChannelManager.shutdown() | ||
| val channelManager = new MockChannelManager(controller.kafkaController.controllerContext, | ||
| controller.kafkaController.config) | ||
| channelManager.startup() | ||
| controller.kafkaController.controllerContext.controllerChannelManager = channelManager | ||
| channelManager.shrinkBlockingQueue(0) | ||
| channelManager.stopSendThread(0) | ||
| // Spawn a new thread to block on the outgoing channel | ||
| // queue | ||
| val thread = new Thread(new Runnable { | ||
| def run() { | ||
| try { | ||
| controller.kafkaController.sendUpdateMetadataRequest(Seq(0), Set(topicPartition)) | ||
| log.info("Queue state %d %d".format(channelManager.queueCapacity(0), channelManager.queueSize(0))) | ||
| controller.kafkaController.sendUpdateMetadataRequest(Seq(0), Set(topicPartition)) | ||
| log.info("Queue state %d %d".format(channelManager.queueCapacity(0), channelManager.queueSize(0))) | ||
| } catch { | ||
| case e : Exception => { | ||
| log.info("Thread interrupted") | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| thread.setName("mythread") | ||
| thread.start() | ||
| while (thread.getState() != Thread.State.WAITING) { | ||
| Thread.sleep(100) | ||
| } | ||
| // Assume that the thread is WAITING because it is | ||
| // blocked on the queue, so interrupt and move forward | ||
| thread.interrupt() | ||
| thread.join() | ||
| channelManager.resumeSendThread(0) | ||
| // Wait and find current controller | ||
| var found = false | ||
| var counter = 0 | ||
| while (!found && counter < 10) { | ||
| for (server <- this.servers) { | ||
| val previousEpoch = (epochMap get server.config.brokerId) match { | ||
| case Some(epoch) => | ||
| epoch | ||
| case None => | ||
| val msg = String.format("Missing element in epoch map %s", epochMap.mkString(", ")) | ||
| throw new IllegalStateException(msg) | ||
| } | ||
|
|
||
| if (server.kafkaController.isActive | ||
| && (previousEpoch) < server.kafkaController.epoch) { | ||
| controller = server | ||
| found = true | ||
| } | ||
| } | ||
| if (!found) { | ||
| Thread.sleep(100) | ||
| counter += 1 | ||
| } | ||
| } | ||
| // Give it a shot to make sure that sending isn't blocking | ||
| try { | ||
| controller.kafkaController.sendUpdateMetadataRequest(Seq(0), Set(topicPartition)) | ||
| } catch { | ||
| case e : Throwable => { | ||
| fail(e) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class MockChannelManager(private val controllerContext: ControllerContext, | ||
| config: KafkaConfig) | ||
| extends ControllerChannelManager(controllerContext, config) { | ||
| def stopSendThread(brokerId: Int) { | ||
| val requestThread = brokerStateInfo(brokerId).requestSendThread | ||
| requestThread.isRunning.set(false) | ||
| requestThread.interrupt | ||
| requestThread.join | ||
| } | ||
|
|
||
| def shrinkBlockingQueue(brokerId: Int) { | ||
| val messageQueue = new LinkedBlockingQueue[(RequestOrResponse, RequestOrResponse => Unit)](1) | ||
| val brokerInfo = this.brokerStateInfo(brokerId) | ||
| this.brokerStateInfo.put(brokerId, new ControllerBrokerStateInfo(brokerInfo.channel, | ||
| brokerInfo.broker, | ||
| messageQueue, | ||
| brokerInfo.requestSendThread)) | ||
| } | ||
|
|
||
| def resumeSendThread (brokerId: Int) { | ||
| this.startRequestSendThread(0) | ||
| } | ||
|
|
||
| def queueCapacity(brokerId: Int): Int = { | ||
| this.brokerStateInfo(brokerId).messageQueue.remainingCapacity | ||
| } | ||
|
|
||
| def queueSize(brokerId: Int): Int = { | ||
| this.brokerStateInfo(brokerId).messageQueue.size | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that resign on exception thrown may be an overkill, but until we figured out what exceptions could possibly thrown here we may want to be as conservative as resigning the controller.