错误:用户未初始化spark上下文

时间:2018-08-20 00:40:14

标签: apache-spark hadoop

记录错误:

  

TestSuccessfull
   2018-08-20 04:52:15 INFO ApplicationMaster:54-最终应用程序状态:失败,退出代码:13   2018-08-20 04:52:15错误ApplicationMaster:91-未捕获的异常:   java.lang.IllegalStateException:用户未初始化spark上下文!       在org.apache.spark.deploy.yarn.ApplicationMaster.runDriver(ApplicationMaster.scala:498)       在org.apache.spark.deploy.yarn.ApplicationMaster.org $ apache $ spark $ deploy $ yarn $ ApplicationMaster $$ runImpl(ApplicationMaster.scala:345)       在org.apache.spark.deploy.yarn.ApplicationMaster $$ anonfun $ run $ 2.apply $ mcV $ sp(ApplicationMaster.scala:260)       在org.apache.spark.deploy.yarn.ApplicationMaster $$ anonfun $ run $ 2.apply(ApplicationMaster.scala:260)       在org.apache.spark.deploy.yarn.ApplicationMaster $$ anonfun $ run $ 2.apply(ApplicationMaster.scala:260)       在org.apache.spark.deploy.yarn.ApplicationMaster $$ anon $ 5.run(ApplicationMaster.scala:800)       在java.security.AccessController.doPrivileged(本机方法)       在javax.security.auth.Subject.doAs(Subject.java:422)       在org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1698)       在org.apache.spark.deploy.yarn.ApplicationMaster.doAsUser(ApplicationMaster.scala:799)       在org.apache.spark.deploy.yarn.ApplicationMaster.run(ApplicationMaster.scala:259)       在org.apache.spark.deploy.yarn.ApplicationMaster $ .main(ApplicationMaster.scala:824)       在org.apache.spark.deploy.yarn.ApplicationMaster.main(ApplicationMaster.scala)   2018-08-20 04:52:15 INFO SparkContext:54-从关机钩子调用stop()

在控制台上错误登录提交命令后:

  

2018-08-20 05:47:35 INFO客户端:54-application_1534690018301_0035的应用报告(状态:已接受)
  2018-08-20 05:47:36 INFO客户端:54-application_1534690018301_0035的申请报告(状态:已接受)
  2018-08-20 05:47:37 INFO客户端:54-application_1534690018301_0035的申请报告(状态:失败)
  2018-08-20 05:47:37 INFO客户端:54-        客户令牌:N / A        诊断:应用程序application_1534690018301_0035失败两次,原因是appattempt_1534690018301_0035_000002的AM容器退出,退出代码为:13   诊断失败:[2018-08-20 05:47:36.454]容器启动时发生异常。   容器编号:container_1534690018301_0035_02_000001   退出代码:13

我的代码:

val sparkConf = new SparkConf().setAppName("Gathering Data")            
val sc = new SparkContext(sparkConf)

提交命令:

spark-submit --class spark_basic.Test_Local --master yarn --deploy-mode cluster /home/IdeaProjects/target/Spark-1.0-SNAPSHOT.jar

说明:

我已经在psedo分发模式下的hadoop上安装了spark。

spark-shell工作正常。当我使用群集模式时唯一的问题。

我的代码也可以工作。我可以打印输出,但最终会出错。

3 个答案:

答案 0 :(得分:4)

如果代码中有将master设置为local的行,那么我猜您是一行。

SparkConf.setMaster("local[*]")

如果是这样,请尝试注释掉该行,然后重试,因为您将在命令中将master设置为yarn

/usr/cdh/current/spark-client/bin/spark-submit --class com.test.sparkApp --master yarn --deploy-mode cluster --num-executors 40 --executor-cores 4 --driver-memory 17g --executor-memory 22g --files /usr/cdh/current/spark-client/conf/hive-site.xml /home/user/sparkApp.jar

答案 1 :(得分:1)

最后我明白了

火花提交

  

/home/mahendra/Marvaland/SparkEcho/spark-2.3.0-bin-hadoop2.7/bin/spark-submit --master yarn --class spark_basic.Test_Local / home / mahendra / IdeaProjects / SparkTraining / target / SparkTraining-1.0-SNAPSHOT.jar

火花会话

val spark = SparkSession.builder()
    .appName("DataETL")
    .master("local[1]")
    .enableHiveSupport()
    .getOrCreate()

感谢@ cricket_007

答案 2 :(得分:0)

如果您像这样提交Spark作业,则可能会发生此错误: spark-submit --class some.path.com.Main --master yarn --deploy-mode cluster some_spark.jar(在CLI中以传递主模式和部署模式作为参数),同时在代码中包含以下行:new SparkContext

如果要使用val sc = SparkContext.getOrCreate(),要么用new SparkContext获取上下文,要么不传递spark-submit master和deploy-mode参数。