Browse Source

KafkaController.RequestSendThread can throw exception on broker socket; patched by Yang Ye; reviewed by Jun Rao; KAFKA-459, KAFKA-460

git-svn-id: https://svn.apache.org/repos/asf/incubator/kafka/branches/0.8@1373448 13f79535-47bb-0310-9956-ffa450edef68
0.8.0-beta1-candidate1
Jun Rao 12 years ago
parent
commit
0fe89f7a49
  1. 4
      core/src/main/scala/kafka/log/Log.scala
  2. 20
      core/src/main/scala/kafka/server/KafkaController.scala

4
core/src/main/scala/kafka/log/Log.scala

@ -438,8 +438,8 @@ private[kafka] class Log( val dir: File, val maxSize: Long, val flushInterval: I @@ -438,8 +438,8 @@ private[kafka] class Log( val dir: File, val maxSize: Long, val flushInterval: I
segment.truncateTo(targetOffset)
info("Truncated log segment %s to highwatermark %d".format(segment.file.getAbsolutePath, targetOffset))
case None =>
assert(targetOffset <= segments.view.last.absoluteEndOffset, "Last checkpointed hw %d cannot be greater than the latest message offset %d in the log %s".format(targetOffset, segments.view.last.absoluteEndOffset, segments.view.last.file.getAbsolutePath))
error("Cannot truncate log to %d since the log start offset is %d and end offset is %d".format(targetOffset, segments.view.head.start, segments.view.last.absoluteEndOffset))
if(targetOffset > segments.view.last.absoluteEndOffset)
error("Last checkpointed hw %d cannot be greater than the latest message offset %d in the log %s".format(targetOffset, segments.view.last.absoluteEndOffset, segments.view.last.file.getAbsolutePath))
}
val segmentsToBeDeleted = segments.view.filter(segment => segment.start > targetOffset)

20
core/src/main/scala/kafka/server/KafkaController.scala

@ -61,13 +61,6 @@ class RequestSendThread(val controllerId: Int, @@ -61,13 +61,6 @@ class RequestSendThread(val controllerId: Int,
lock synchronized {
channel.send(request)
receive = channel.receive()
}
} catch {
case e =>
// log it and let it go. Let controller shut it down.
debug("Exception occurs", e)
}
var response: RequestOrResponse = null
request.requestId.get match {
case RequestKeys.LeaderAndISRRequest =>
@ -81,6 +74,12 @@ class RequestSendThread(val controllerId: Int, @@ -81,6 +74,12 @@ class RequestSendThread(val controllerId: Int,
callback(response)
}
}
} catch {
case e =>
// log it and let it go. Let controller shut it down.
debug("Exception occurs", e)
}
}
} catch{
case e: InterruptedException => warn("intterrupted. Shutting down")
case e1 => error("Error due to ", e1)
@ -94,6 +93,7 @@ class ControllerChannelManager(allBrokers: Set[Broker], config : KafkaConfig) ex @@ -94,6 +93,7 @@ class ControllerChannelManager(allBrokers: Set[Broker], config : KafkaConfig) ex
private val messageChannels = new HashMap[Int, BlockingChannel]
private val messageQueues = new HashMap[Int, BlockingQueue[(RequestOrResponse, (RequestOrResponse) => Unit)]]
private val messageThreads = new HashMap[Int, RequestSendThread]
private val lock = new Object()
this.logIdent = "Channel manager on controller " + config.brokerId + ", "
for(broker <- allBrokers){
brokers.put(broker.id, broker)
@ -117,16 +117,19 @@ class ControllerChannelManager(allBrokers: Set[Broker], config : KafkaConfig) ex @@ -117,16 +117,19 @@ class ControllerChannelManager(allBrokers: Set[Broker], config : KafkaConfig) ex
}
def shutDown() = {
lock synchronized {
for((brokerId, broker) <- brokers){
removeBroker(brokerId)
}
}
}
def sendRequest(brokerId : Int, request : RequestOrResponse, callback: (RequestOrResponse) => Unit = null){
messageQueues(brokerId).put((request, callback))
}
def addBroker(broker: Broker){
lock synchronized {
brokers.put(broker.id, broker)
messageQueues.put(broker.id, new LinkedBlockingQueue[(RequestOrResponse, (RequestOrResponse) => Unit)](config.controllerMessageQueueSize))
val channel = new BlockingChannel(broker.host, broker.port,
@ -140,8 +143,10 @@ class ControllerChannelManager(allBrokers: Set[Broker], config : KafkaConfig) ex @@ -140,8 +143,10 @@ class ControllerChannelManager(allBrokers: Set[Broker], config : KafkaConfig) ex
thread.start()
messageThreads.put(broker.id, thread)
}
}
def removeBroker(brokerId: Int){
lock synchronized {
brokers.remove(brokerId)
try {
messageChannels(brokerId).disconnect()
@ -153,6 +158,7 @@ class ControllerChannelManager(allBrokers: Set[Broker], config : KafkaConfig) ex @@ -153,6 +158,7 @@ class ControllerChannelManager(allBrokers: Set[Broker], config : KafkaConfig) ex
case e => error("Error while removing broker by the controller", e)
}
}
}
}
class KafkaController(config : KafkaConfig, zkClient: ZkClient) extends Logging {

Loading…
Cancel
Save