如何从shell脚本捕获spark错误

isr3a4wc  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(651)

我在aws数据管道中有一个管道,它运行一个名为shell.sh的shell脚本:

$ spark-submit transform_json.py

Running command on cluster...
[54.144.10.162] Running command...
[52.206.87.30] Running command...
[54.144.10.162] Command complete.
[52.206.87.30] Command complete.
run_command finished in 0:00:06.

aws数据管道控制台显示作业已“完成”,但在stderr日志中,我看到作业实际上已中止:

Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Status Code: 404, AWS Service: Amazon S3, AWS Request ID: xxxxx, AWS Error Code: null, AWS Error Message: Not Found...        
Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 5.0 failed 1 times, most recent failure: Lost task 0.0 in stage 5.0 (TID 5, localhost, executor driver): org.apache.spark.SparkException: Task failed while writing rows.
    ...
        20/05/22 11:42:47 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
        20/05/22 11:42:47 INFO MemoryStore: MemoryStore cleared
        20/05/22 11:42:47 INFO BlockManager: BlockManager stopped
        20/05/22 11:42:47 INFO BlockManagerMaster: BlockManagerMaster stopped
        20/05/22 11:42:47 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!
        20/05/22 11:42:47 INFO SparkContext: Successfully stopped SparkContext
        20/05/22 11:42:47 INFO ShutdownHookManager: Shutdown hook called

我对数据管道和spark有些陌生;我不知道幕后到底发生了什么。如何让shell脚本捕获 SparkException ?

uqjltbpv

uqjltbpv1#

试试下面这个例子。。。
您的shell脚本可以捕获如下错误代码。。。其中非零退出代码为错误 $? 是最近执行的命令的退出状态;按照惯例,0表示成功,其他任何东西都表示失败。

spark-submit transform_json.py

 ret_code=$?
   if [ $ret_code -ne 0 ]; then 
      exit $ret_code
   fi

您必须通过编码返回退出代码 sys.exit(-1) 处于错误状态。检查python异常处理。。。
在python中检查这个退出代码

相关问题