0
  • 火花版本:2.4.5
  • 组件:Spark Streaming
  • 类:DirectKafkaInputDStream

在课堂DirectKafkaInputDStream上,我有点困惑为什么要paraniodPoll在 seekToEnd 之前调用?

protected def latestOffsets(): Map[TopicPartition, Long] = {
    val c = consumer
    paranoidPoll(c)
    val parts = c.assignment().asScala

    // make sure new partitions are reflected in currentOffsets
    val newPartitions = parts.diff(currentOffsets.keySet)

    // Check if there's any partition been revoked because of consumer rebalance.
    val revokedPartitions = currentOffsets.keySet.diff(parts)
    if (revokedPartitions.nonEmpty) {
      throw new IllegalStateException(s"Previously tracked partitions " +
        s"${revokedPartitions.mkString("[", ",", "]")} been revoked by Kafka because of consumer " +
        s"rebalance. This is mostly due to another stream with same group id joined, " +
        s"please check if there're different streaming application misconfigure to use same " +
        s"group id. Fundamentally different stream should use different group id")
    }

    // position for new partitions determined by auto.offset.reset if no commit
    currentOffsets = currentOffsets ++ newPartitions.map(tp => tp -> c.position(tp)).toMap

    // find latest available offsets
    c.seekToEnd(currentOffsets.keySet.asJava)
    parts.map(tp => tp -> c.position(tp)).toMap
  }
4

1 回答 1

1

如果没有 poll(0),assignment() 可能会返回空集,poll 确保客户端连接到 Kafka 协调器节点。

但是 poll(0) 已被 kafka-client 弃用,请检查 Spark 的备用 API。

另请参阅:KafkaConsumer assignment() 返回空

于 2021-08-18T07:06:21.930 回答