gpt4 book ai didi

apache-spark - HDFS 文件接收器输出作为另一个流的文件流输入 - 竞争条件?

转载 作者:行者123 更新时间:2023-12-03 21:21:27 24 4
gpt4 key购买 nike

我正在使用结构化流评估 15 节点 Spark 集群中的特定数据流。我在我的应用程序中定义了 2 个流查询:

  • SQ1 - 从 Kakfa 读取数据 -> 进程 -> 写入 HDFS 文件接收器(路径 - hdfs://tmp/output)
  • SQ2 - 从 HDFS(与上述路径相同)读取数据作为文件流 -> 进一步处理 -> 使用 ForeachWriter 写入外部数据库

  • 这两个查询都设置为每 15 秒触发一次。

    我的问题 - 我是否在这里查看竞争条件,其中 SQ2 从 HDFS 中获取部分写入的文件(由 SQ1 生成)?一个更普遍的问题是,HDFS 的文件接收器编写器是“原子的”吗?我试图在 Spark 中挖掘流式源代码,但没有取得太大进展。

    最佳答案

    这种方法的主要问题是 Spark Structured Streaming 中的所有 File Sink(例如 HDFS)都只能在 append 模式下运行。此外,一旦创建了文件,就会从文件中读取。任何后续更新或写入的完成都将被忽略。
    根据关于从文件中读取的“Learning Spark - 2nd Edition”一书

    "each file must appear in the directory listing atomically - that is, the whole file must be available at once for reading, and once it is available, the file cannot be updated or modified."

    "[Writing to files] ... it only supports append mode, because while it is easy to write new files in the output directory (i.e., append data to a directory), it is hard to modify existing data files (as would be expected with update and complete modes)."


    为了克服您面临的问题,您可以将流查询更改为:
  • SQ1 - 从 Kafka 读取数据 -> 进程 -> 进一步处理 -> 缓存/持久化
  • SQ2a 将缓存的 DataFrame 写入 HDFS 文件接收器(路径 - hdfs://tmp/output)
  • SQ2b 使用 ForeachWriter 将缓存的 DataFrame 写入外部数据库
    -> 使用 ForeachWriter 写入外部数据库
  • 关于apache-spark - HDFS 文件接收器输出作为另一个流的文件流输入 - 竞争条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51321810/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com