使用MultipleOutputs遇到的问题小记

在使用Hadoop MapReduce的MultipleOutputs功能时,遇到了AlreadyBeingCreatedException错误,该异常指出文件正在由当前的租约持有者尝试重新创建。解决方法是检查并确保作业配置和资源管理正确,避免文件操作冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、org.apache.hadoop.ipc.RemoteException: org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException: failed to create file /user/bjdata/user/wuyb/semv/SemAAJob_3/calsigma/_temporary/_attempt_201306261152_42270_r_000000_0/part-r-00000 for DFSClient_attempt_201306261152_42270_r_000000_0 on client 10.0.2.79 because current leaseholder is trying to recreate file.

     解决:

   MultipleOutputs.addNamedOutput(job, CalSigmaReducer.RECORD_OUT, MultipleTextOutputFormat.class, Text.class, NullWritable.class);
  原来是使用TextOutputFormat,改成MultipleTextOutputFormat。

2、使用了thrift生成的class,java.lang.IllegalStateException: Runtime parameterized Protobuf/Thrift class is unkonwn. This object was probably created with default constructor. Please use setConverter(Class).
   MultipleOutputs.addNamedOutput(job, CalSigmaReducer.RECORD_OUT2, MultipleSequenceFileOutputFormat.class, ThriftWritable.class, NullWritable.class);
  原来想设置输出格式为TextSequenceFileOutputFormat,然后使用ThriftWritable为key类型。hadoop在生成对象的时候使用ThriftWritable默认构造器,但ThriftWritable要求设置一个被包装的类型。这无法做到,因此导致用hadoop的生成对象的方法生成了一个不具有“被包装类型”的ThriftWritable对象。
   解决:写了一个工具类,把thrift生成的类转换为String。(为了不修改thrift生成的类)

3、使用后忘记close,然后发现有的文件没有内容。
   解决:cleanup的时候mos.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值