org.apache.spark.SparkException:无法找到Set的前导偏移量([test-topic,0])

时间:2016-09-05 16:09:26

标签: scala apache-spark apache-kafka confluent

我尝试使用Confluent平台,并以this code为例向REST端点发出高级Kafka请求。

我使用以下Kafka参数:

val kafkaParams = Map(
  "bootstrap.servers" -> "localhost:9092",
  "schema.registry.url" -> "http://localhost:8081",
  "group.id" -> "EventConsumer",
  "auto.offset.reset" -> "smallest"
)

这是我尝试运行代码时遇到的错误。错误发生在以下行:

@transient val kafkaStream: DStream[(String, Object)] =
  KafkaUtils.createDirectStream[String, Object, StringDecoder, KafkaAvroDecoder](
    ssc, kafkaParams, Set(topic)
  )
  

线程“main”中的异常org.apache.spark.SparkException:   java.nio.channels.ClosedChannelException   org.apache.spark.SparkException:无法找到领导者偏移量   设置([test-topic,0])at   org.apache.spark.streaming.kafka.KafkaCluster $$ anonfun $ checkErrors $ 1.适用(KafkaCluster.scala:366)     在   org.apache.spark.streaming.kafka.KafkaCluster $$ anonfun $ checkErrors $ 1.适用(KafkaCluster.scala:366)     在scala.util.Either.fold(Either.scala:98)at   org.apache.spark.streaming.kafka.KafkaCluster $ .checkErrors(KafkaCluster.scala:365)     在   org.apache.spark.streaming.kafka.KafkaUtils $ .getFromOffsets(KafkaUtils.scala:222)     在   org.apache.spark.streaming.kafka.KafkaUtils $ .createDirectStream(KafkaUtils.scala:484)     在   kafka.EventsConsumer $ .delayedEndpoint $卡夫卡$ EventsConsumer $ 1(EventsConsumer.scala:53)     在   kafka.EventsConsumer $ delayedInit $ body.apply(EventsConsumer.scala:22)     在scala.Function0 $ class.apply $ mcV $ sp(Function0.scala:34)at   scala.runtime.AbstractFunction0.apply $ MCV $ SP(AbstractFunction0.scala:12)     在scala.App $$ anonfun $ main $ 1.apply(App.scala:76)at   scala.App $$ anonfun $ main $ 1.apply(App.scala:76)at   scala.collection.immutable.List.foreach(List.scala:381)at   scala.collection.generic.TraversableForwarder $ class.foreach(TraversableForwarder.scala:35)     在scala.App $ class.main(App.scala:76)at   kafka.EventsConsumer $ .main(EventsConsumer.scala:22)at   kafka.EventsConsumer.main(EventsConsumer.scala)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)at   com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

更新:

我尝试将localhost更改为IP,但仍然遇到同样的问题。

1 个答案:

答案 0 :(得分:0)

看起来领导者不能用于主题分区。尝试描述该主题并检查是否有任何领导可用于test-topic的分区0。如果分区的所有副本都已关闭,则会发生这种情况。如果您的复制因子为1,则这是最可能的原因。