在 EMR 集群上运行的 Spark 作业。system.exit(0) 用于正常完成作业,但仍踩 EMR 失败

man*_*sha 3 amazon-emr apache-spark

在火花工作。我正在使用如果文件未找到 system.exit(0)。它应该优雅地完成工作。本地 成功完成。但是当我在 EMR 上运行时。步骤失败。

Iva*_*iev 7

EMR 使用YARN进行集群管理和启动 Spark 应用程序。因此,当您--deploy-mode: cluster在 EMR 中运行 Spark 应用程序时,Spark 应用程序代码不会单独在 JVM 中运行,而是由ApplicationMaster类执行。

浏览ApplicationMaster代码可以解释当您尝试执行时会发生什么System.exit()。用户应用程序在 中启动startUserApplication,然后finish在用户应用程序返回后调用该方法。但是,当您调用 时System.exit(0),执行的是关闭挂钩,它会看到您的代码尚未成功完成,并将其标记为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.
Run Code Online (Sandbox Code Playgroud)

  • 当您想要完成工作时,您可能需要找到一种从 main 方法返回的方法。例如,一种有点黑客的方法可能是从您想要的完成点抛出异常,在“main”中捕获该异常,然后在那里优雅地退出。根据代码的结构,可能有更好的方法。 (2认同)