监听/isr_change_notification路径下的节点
override def handleChildChange(parentPath: String, currentChildren: util.List[String]): Unit = {
import scala.collection.JavaConverters._
inLock(controller.controllerContext.controllerLock) {
debug("[IsrChangeNotificationListener] Fired!!!")
val childrenAsScala: mutable.Buffer[String] = currentChildren.asScala
try {
val topicAndPartitions: immutable.Set[TopicAndPartition] = childrenAsScala.map(x => getTopicAndPartition(x)).flatten.toSet
if (topicAndPartitions.nonEmpty) {
// 从Zookeeper中获取指定分区的Leader副本、ISR集合等信息,更新ControllerConetext
controller.updateLeaderAndIsrCache(topicAndPartitions)
// 向可用的Broker发送UpdateMetadataRequest
processUpdateNotifications(topicAndPartitions)
}
} finally {
// delete processed children
childrenAsScala.map(x => controller.controllerContext.zkUtils.deletePath(
ZkUtils.IsrChangeNotificationPath + "/" + x))
}
}
}
本文介绍了一个基于Scala实现的Zookeeper监听器,该监听器用于监听/isr_change_notification路径下的节点变化,并根据变更来更新ControllerContext中的Leader副本及ISR信息。此外,它还会触发向Broker发送UpdateMetadataRequest的动作。
483

被折叠的 条评论
为什么被折叠?



