【发布时间】:2017-01-27 13:44:58
【问题描述】:
在火花工作中。我正在使用如果文件未找到 system.exit(0)。它应该优雅地完成这项工作。本地 已成功完成。但是当我在 EMR 上运行时。步骤失败。
【问题讨论】:
-
EMR上的日志文件报什么错误?
在火花工作中。我正在使用如果文件未找到 system.exit(0)。它应该优雅地完成这项工作。本地 已成功完成。但是当我在 EMR 上运行时。步骤失败。
【问题讨论】:
EMR 使用YARN 进行集群管理和启动 Spark 应用程序。因此,当您在 EMR 中运行带有 --deploy-mode: cluster 的 Spark 应用程序时,Spark 应用程序代码不会单独在 JVM 中运行,而是由 ApplicationMaster 类执行。
浏览ApplicationMaster 代码可以解释当您尝试执行System.exit() 时会发生什么。用户应用程序在startUserApplication 中启动,然后在用户应用程序返回后调用finish 方法。但是,当您调用System.exit(0) 时,将执行的是a shutdown hook,它看到您的代码没有成功完成,并将其标记为EXIT_EARLY 失败。它也有这个有用的评论:
// The default state of ApplicationMaster is failed if it is invoked by shut down hook.
// This behavior is different compared to 1.x version.
// If user application is exited ahead of time by calling System.exit(N), here mark
// this application as failed with EXIT_EARLY. For a good shutdown, user shouldn't call
// System.exit(0) to terminate the application.
【讨论】:
main 什么都不返回?
main 中捕获该异常,然后在那里优雅地退出。根据您的代码结构,可能会有更好的方法。