流应用程序重启后如何保持状态?

How to maintain state after streaming application restart?

我想了解 Spark Streaming 中的状态管理一般是如何工作的。如果我 运行 这个示例程序两次,第二个 运行 会看到第一个 运行 的状态吗? https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/streaming/StatefulNetworkWordCount.scala

有没有办法实现这个?我正在考虑重新部署应用程序,我不想失去当前状态。

tl;dr 这取决于您需要其他实例看到的内容。 Checkpointing 通常 一个解决方案。

ssc.checkpoint(".")(在 the line 50 in StatefulNetworkWordCount) enables checkpointing that (quoting the official documentation):

Spark Streaming needs to checkpoint enough information to a fault-tolerant storage system such that it can recover from failures.

失败可以被认为是一种重新部署的形式。在Upgrading Application Code下的官方文档中有描述,列举了两种情况:

  • 两个实例运行并行
  • 一个被优雅地关闭,另一个从检查点目录读取状态。