来自 Kafka 源的 Spark Streaming 返回检查点或倒带
Spark Streaming from Kafka Source Go Back to a Checkpoint or Rewinding
当从 Kafka 源流式传输 Spark DStreams 作为消费者时,可以检查 spark 上下文,这样当应用程序崩溃(或受到 kill -9
影响)时,应用程序可以从上下文检查点恢复。但是,如果应用程序是 'accidentally deployed with bad logic',则可能需要倒带到最后一个主题+分区+偏移量,以重播来自某个 Kafka 主题的分区偏移位置的事件,这些位置在 'bad logic' 之前工作正常。当检查点生效时,流式应用程序如何倒回到最后一个 'good spot'(主题+分区+偏移量)?
注意:在 I (Heart) Logs 中,Jay Kreps 写到使用并行消费者(组)进程,该进程从不同的 Kafka 偏移位置开始,直到赶上原始进程,然后杀死原始进程。 (关于从某些 partition/offset 个位置开始的第二个 Spark 流处理过程是什么样的?)
边栏:这个问题可能与 有关,因为可能需要部署类似的机制。
您将无法在 运行 SparkStreamingContext
中倒带流。记住这些要点很重要(直接来自文档):
- Once a context has been started, no new streaming computations can be set up or added to it.
- Once a context has been stopped, it cannot be restarted.
- Only one StreamingContext can be active in a JVM at the same time.
- stop() on StreamingContext also stops the SparkContext. To stop only the StreamingContext, set the optional parameter of stop()
called stopSparkContext to false.
- A SparkContext can be re-used to create multiple StreamingContexts, as long as the previous StreamingContext is stopped (without stopping
the SparkContext) before the next StreamingContext is created
相反,您将不得不停止当前流,并创建一个新流。您可以使用 createDirectStream
的一个版本从一组特定的偏移量开始流,该版本采用带有签名 Map[TopicAndPartition, Long]
的 fromOffsets
参数——它是由主题和分区映射的起始偏移量.
另一种理论上的可能性是使用 KafkaUtils.createRDD
,它将偏移范围作为输入。假设您的 "bad logic" 从偏移量 X 开始,然后将其固定在偏移量 Y。对于某些用例,您可能只想对从 X 到 Y 的偏移量执行 createRDD
并处理这些结果,而不是尝试将其作为流进行。
当从 Kafka 源流式传输 Spark DStreams 作为消费者时,可以检查 spark 上下文,这样当应用程序崩溃(或受到 kill -9
影响)时,应用程序可以从上下文检查点恢复。但是,如果应用程序是 'accidentally deployed with bad logic',则可能需要倒带到最后一个主题+分区+偏移量,以重播来自某个 Kafka 主题的分区偏移位置的事件,这些位置在 'bad logic' 之前工作正常。当检查点生效时,流式应用程序如何倒回到最后一个 'good spot'(主题+分区+偏移量)?
注意:在 I (Heart) Logs 中,Jay Kreps 写到使用并行消费者(组)进程,该进程从不同的 Kafka 偏移位置开始,直到赶上原始进程,然后杀死原始进程。 (关于从某些 partition/offset 个位置开始的第二个 Spark 流处理过程是什么样的?)
边栏:这个问题可能与
您将无法在 运行 SparkStreamingContext
中倒带流。记住这些要点很重要(直接来自文档):
- Once a context has been started, no new streaming computations can be set up or added to it.
- Once a context has been stopped, it cannot be restarted.
- Only one StreamingContext can be active in a JVM at the same time.
- stop() on StreamingContext also stops the SparkContext. To stop only the StreamingContext, set the optional parameter of stop() called stopSparkContext to false.
- A SparkContext can be re-used to create multiple StreamingContexts, as long as the previous StreamingContext is stopped (without stopping the SparkContext) before the next StreamingContext is created
相反,您将不得不停止当前流,并创建一个新流。您可以使用 createDirectStream
的一个版本从一组特定的偏移量开始流,该版本采用带有签名 Map[TopicAndPartition, Long]
的 fromOffsets
参数——它是由主题和分区映射的起始偏移量.
另一种理论上的可能性是使用 KafkaUtils.createRDD
,它将偏移范围作为输入。假设您的 "bad logic" 从偏移量 X 开始,然后将其固定在偏移量 Y。对于某些用例,您可能只想对从 X 到 Y 的偏移量执行 createRDD
并处理这些结果,而不是尝试将其作为流进行。