【发布时间】:2023-01-18 21:09:21
【问题描述】:
由于业务需求,我每天使用 Trigger.Once 方法触发一个 Spark 流作业。
StreamingQuery query = joinedDf
.writeStream()
.outputMode("append")
.format("parquet")
.option("path", resultPath)
.option("checkpointLocation", checkpointLocationPathForDate)
.trigger(Trigger.Once())
.start();
我正在使用 map flatMapGroupsWithState 以便我们可以存储分组数据的状态 (GroupState)。
我在某个地方读到每个 StreamingQuery 的 checkpointLocation 应该不同。因此我使用这样的检查点位置:/path/to/nfs/checkpoint/<current date in format: yyyyMMdd>
每天,Spark 作业都会处理文件夹/path/to/data/<current date in format: yyyyMMdd> 中的文件
我想访问昨天 Spark 作业的状态,因为昨天的数据可能包含今天数据所需的相关状态。
但是,Spark 将状态数据存储在 checkpointLocation 即 /path/to/nfs/checkpoint/<current date in format: yyyyMMdd>/<queryName>/state 中,因此当使用不同的 checkpointLocation 时,无法访问它。
那么,如何访问存储在先前 Spark 作业的 checkpointLocation 中的 GroupState 数据?可以对不同的 StreamingQueries 使用相同的 checkpointLocation 吗?
编辑: 我尝试对昨天的 StreamingQuery 和今天的 StreamingQuery 使用相同的 checkpointLocation,并且 Spark 恢复了昨天批次的状态,这是我想要的,但是这在任何地方都有记录吗?当在每日批次之间使用相同的 checkpointLocation 时,这是预期的行为还是可能的行为不端?
【问题讨论】:
标签: apache-spark spark-structured-streaming