首页 > 解决方案 > 在集群模式下读取文本文件时出现异常

问题描述

我使用 spark 读取了一个文本文件并将其保存在 JavaRDD 中,并尝试打印保存在 RDD 中的数据。我在一个主服务器和两个从服务器的集群中运行我的代码。但是我遇到了异常,例如容器超过阈值,同时遍历 RDD。该代码在独立模式下完美运行。

我的代码:

SparkContext sc = new SparkContext("spark://master.com:7077","Spark-Phoenix");
JavaSparkContext jsc = new JavaSparkContext(sc);

JavaRDD<String> trs_testing = jsc.textFile("hdfs://master.com:9000/Table/sample");


//using iterator
Iterator<String> iStr= trs_testing.toLocalIterator();

while(iStr.hasNext()){ //here I am getting exception    
    System.out.println("itr next : " + iStr.next());        
}   

//using foreach()
trs_testing.foreach(new VoidFunction<String>() {//here I am getting exception
        private static final long serialVersionUID = 1L;

        @Override public void call(String line) throws Exception {
            System.out.println(line);       
        }           
});

//using collect()
for(String line:trs_testing.collect()){//here I am getting exception 
    System.out.println(line);
}

//using foreachPartition()
trs_testing.foreachPartition(new VoidFunction<Iterator<String>>() {//here I am getting exception 
        private static final long serialVersionUID = 1L;

        @Override public void call(Iterator<String> arg0) throws Exception {          
            while (arg0.hasNext()) {            
                String line = arg0.next();
                System.out.println(line);
            }
    }
});

例外:

ERROR TaskSchedulerImpl Lost executor 0 on master.com: Remote RPC client dis associated。可能是由于容器超过阈值, 或网络问题。检查驱动程序日志以获取 WARN 消息。错误 TaskSchedulerImpl 在 slave1.com 上丢失了执行程序 1:远程 RPC 客户端已解除关联。可能是由于容器超过阈值或网络问题。检查驱动程序日志以获取 WARN 消息。错误 TaskSchedulerImpl 在 master.com 上丢失了执行程序 2:远程 RPC 客户端已解除关联。可能是由于容器超过阈值或网络问题。检查驱动程序日志以获取 WARN 消息。slave2.com 上的错误 TaskSchedulerImpl 丢失执行程序 3:远程 RPC 客户端已解除关联。可能是由于容器超过阈值或网络问题。检查驱动程序日志以获取 WARN 消息。ERROR TaskSetManager Task 0 in stage 0.0 失败 4 次;线程“主”org.apache.spark.SparkException 中的中止作业异常:作业因阶段失败而中止:阶段 0 中的任务 0。0 失败 4 次,最近一次失败:在 0.0 阶段丢失任务 0.3(TID 3,slave1.com):ExecutorLostFailure(由于其中一个正在运行的任务导致执行器 3 退出) 原因:远程 RPC 客户端解除关联。可能是由于容器超过阈值或网络问题。检查驱动程序日志以获取 WARN 消息。驱动程序堆栈跟踪:在 org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1 的 org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1454)。在 scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala: 59)在 scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48) 在 org。

标签: apache-sparkcluster-computingrdd

解决方案


我得到了解决方案。我正在通过我的机器执行代码,而我的主从服务器正在远程服务器上运行。我将代码导出到远程服务器并最终能够处理数据。


推荐阅读