Avro AvroMultipleOutputs part-r-00000:文件未打开以编写异常

时间:2014-05-04 06:31:35

标签: hadoop mapreduce avro

我在Hadoop 2.3.0上用Avro 1.7.4编写了MapReduce作业。在第一步中,我在AvroSequenceFile中编写了所有Avro结果。一切顺利,没有问题。

然后我尝试使用AvroMultipleOutputs类将结果写入不同的文件中。我在没有使用Avro的情况下编写了相同的MapReduce作业,将数据写入两个单独的文件是没有问题的(顺便说一句,部分-r-00000是在hdfs中创建的,但是留空)。

如果我在reducer中写入数据,Avro变体会产生异常。 (如果我注释掉写出数据的行,我没有例外)。

这是工作配置:

this.conf = new Configuration();
Job job = Job.getInstance(conf);
job.setJarByClass(ArchiveDataProcessorMR.class); 
Path inPath         = new Path(props.getProperty("inPath").trim());
Path outPath        = new Path(props.getProperty("outPath").trim());
Path outPathMeta    = new Path(props.getProperty("outPath.meta").trim());
Path outPathPayload = new Path(props.getProperty("outPath.payload").trim());

// cleanup resources from previous run
FileSystem fs = FileSystem.get(conf);
fs.delete(outPath, true);

FileInputFormat.setInputPaths(job, inPath);
FileOutputFormat.setOutputPath(job, outPath);

AvroSequenceFileInputFormat<DataExportKey,DataExportValue> sequenceInputFormat = new AvroSequenceFileInputFormat<DataExportKey,DataExportValue>();
job.setInputFormatClass(sequenceInputFormat.getClass());

AvroJob.setInputValueSchema(job, DataExportValue.getClassSchema());
AvroJob.setInputKeySchema(job, DataExportKey.getClassSchema());
AvroJob.setMapOutputValueSchema(job, DataExportValue.getClassSchema());
AvroJob.setMapOutputKeySchema(job, DataExportKey.getClassSchema());
job.setMapperClass(ArchiveDataMapper.class);
job.setReducerClass(ArchiveDataReducer.class);

AvroSequenceFileOutputFormat<DataExportKey,DataExportValue> sequenceOutputFormat = new AvroSequenceFileOutputFormat<DataExportKey,DataExportValue>();
AvroJob.setOutputKeySchema(job, DataExportKey.getClassSchema());
AvroJob.setOutputValueSchema(job, DataExportValue.getClassSchema());

job.setOutputFormatClass(AvroSequenceFileOutputFormat.class);
AvroMultipleOutputs.addNamedOutput(job, "meta",    sequenceOutputFormat.getClass(), DataExportKey.getClassSchema(), DataExportValue.getClassSchema());
AvroMultipleOutputs.addNamedOutput(job, "payload", sequenceOutputFormat.getClass(), DataExportKey.getClassSchema(), DataExportValue.getClassSchema());

reducer代码(没有业务逻辑)看起来像

public static class ArchiveDataReducer extends Reducer<AvroKey<DataExportKey>, AvroValue<DataExportValue>,AvroKey<DataExportKey>,AvroValue<DataExportValue>> {

    private AvroMultipleOutputs amos;

    public void setup(Context context) throws IOException,  InterruptedException {
        this.amos = new AvroMultipleOutputs(context);
    }

    public void cleanup(Context context) throws IOException, InterruptedException {
        this.amos.close();
    }


    /**
     * @param key 
    */  
    public void reduce(AvroKey<DataExportKey> key, Iterable<AvroValue<DataExportValue>>  xmlIter,  Context context) throws IOException, InterruptedException {
        try {
            DataExportValue newValue = new DataExportValue();
            if (key.datum()......) {
                ... snip...
                amos.write("meta",key, new AvroValue<DataExportValue>(newValue));

            } else {    
              ... snip...
                amos.write("payload",key, new AvroValue<DataExportValue>(newValue));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

} // class ArchiveDataReducer

异常消息是

14/05/04 06:52:58 INFO mapreduce.Job:  map 100% reduce 0%
14/05/04 06:53:09 INFO mapreduce.Job:  map 100% reduce 91%
14/05/04 06:53:09 INFO mapreduce.Job: Task Id : attempt_1399104292130_0016_r_000000_1, Status : FAILED
Error: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException): No lease on /applications/wd/data_avro/_temporary/1/_temporary/attempt_1399104292130_0016_r_000000_1/part-r-00000: File is not open for writing. Holder DFSClient_attempt_1399104292130_0016_r_000000_1_338983539_1 does not have any open files.
        at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkLease(FSNamesystem.java:2856)                                                                                                                                                                                                                                                                         
        at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.analyzeFileState(FSNamesystem.java:2667)                                                                                                                                                                                                                                                                   
        at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:2573)                                                                                                                                                                                                                                                                 
        at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:563)                                                                                                                                                                                                                                                                  
        at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:407)                                                                                                                                                                                                                 
        at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)                                                                                                                                                                                                              
        at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:585)                                                                                                                                                                                                                                                             
        at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:928)                                                                                                                                                                                                                                                                                                            
        at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1962)                                                                                                                                                                                                                                                                                                   
        at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1958)                                                                                                                                                                                                                                                                                                   
        at java.security.AccessController.doPrivileged(Native Method)                                                                                                                                                                                                                                                                                                     
        at javax.security.auth.Subject.doAs(Subject.java:415)                                                                                                                                                                                                                                                                                                             
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548)                                                                                                                                                                                                                                                                           
        at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1956)                                                                                                                                                                                                                                                                                                     

        at org.apache.hadoop.ipc.Client.call(Client.java:1406)                                                                                                                                                                                                                                                                                                            
        at org.apache.hadoop.ipc.Client.call(Client.java:1359)                                                                                                                                                                                                                                                                                                            
        at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:206)                                                                                                                                                                                                                                                                             
        at com.sun.proxy.$Proxy10.addBlock(Unknown Source)                                                                                                                                                                                                                                                                                                                
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                                                                                                                                                                                                    
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)                                                                                                                                                                                                                                                                                  
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                                                                                                                                                                                          
        at java.lang.reflect.Method.invoke(Method.java:606)                                                                                                                                                                                                                                                                                                               
        at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:186)                                                                                                                                                                                                                                                                
        at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)                                                                                                                                                                                                                                                                      
        at com.sun.proxy.$Proxy10.addBlock(Unknown Source)                                                                                                                                                                                                                                                                                                                
        at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:348)                                                                                                                                                                                                                                     
        at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.locateFollowingBlock(DFSOutputStream.java:1264)                                                                                                                                                                                                                                                            
        at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1112)                                                                                                                                                                                                                                                           
        at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:522)                                                                                                                                                                                                                                                                              

任何提示如何解决这个问题?你有另一个运行AvroMultipleOutputs的例子吗?我想看看你的代码。

亲切的问候

马丁

0 个答案:

没有答案