如何在spark-shell中停止Structured Streaming查询?
Spark Shell中Structured Streaming任务的正确终止方法
- 两次按下Ctrl+C:第一次Ctrl+C会触发中断信号,但
awaitTermination()的阻塞逻辑可能未立即响应,第二次按下会强制触发JVM退出,同时终止Streaming任务。 - 通过应用ID手动终止:
- 登录Spark UI,在Applications标签页找到任务的应用ID(格式如
application_1699999999_0001) - 打开新终端,执行对应命令:
- 本地/Standalone模式:
./bin/spark-class org.apache.spark.deploy.Client stop <你的应用ID> - YARN集群模式:
yarn application -kill <你的应用ID>
- 本地/Standalone模式:
- 登录Spark UI,在Applications标签页找到任务的应用ID(格式如
- 修改代码预留终止入口:
启动任务时先保存StreamingQuery对象,通过手动输入触发停止,避免直接用awaitTermination()阻塞:
这样在Spark Shell中按下回车,就能优雅终止任务。val query = result.writeStream.outputMode("complete").format("console").start() scala.io.StdIn.readLine("按下回车键停止任务...") query.stop() query.awaitTermination()
内容的提问来源于stack exchange,提问作者beatrice
相关产品推荐
相关产品推荐

