mapreduce输出多文件出错

来源:互联网 发布:诺贝尔知乎 编辑:程序博客网 时间:2024/05/21 16:26

运行mapreduce多文件输出试报错。

17/06/19 17:25:45 INFO mapreduce.Job: Task Id : attempt_1497864070486_0001_r_000000_2, Status : FAILEDError: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException): failed to create file /test/output/_temporary/1/_temporary/attempt_1497864070486_0001_r_000000_2/b-r-00000 for DFSClient_attempt_1497864070486_0001_r_000000_2_473674087_1 for client 192.168.10.250 because current leaseholder is trying to recreate file.at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.recoverLeaseInternal(FSNamesystem.java:3034)at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFileInternal(FSNamesystem.java:2737)at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFileInt(FSNamesystem.java:2632)at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFile(FSNamesystem.java:2520)at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.create(NameNodeRpcServer.java:579)at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.create(ClientNamenodeProtocolServerSideTranslatorPB.java:394)at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:619)at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:962)at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2040)at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2036)at java.security.AccessController.doPrivileged(Native Method)at javax.security.auth.Subject.doAs(Subject.java:422)at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1656)at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2034)at org.apache.hadoop.ipc.Client.call(Client.java:1469)at org.apache.hadoop.ipc.Client.call(Client.java:1400)at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:232)at com.sun.proxy.$Proxy13.create(Unknown Source)at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.create(ClientNamenodeProtocolTranslatorPB.java:295)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:187)at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)at com.sun.proxy.$Proxy14.create(Unknown Source)at org.apache.hadoop.hdfs.DFSOutputStream.newStreamForCreate(DFSOutputStream.java:1725)at org.apache.hadoop.hdfs.DFSClient.create(DFSClient.java:1657)at org.apache.hadoop.hdfs.DFSClient.create(DFSClient.java:1582)at org.apache.hadoop.hdfs.DistributedFileSystem$6.doCall(DistributedFileSystem.java:397)at org.apache.hadoop.hdfs.DistributedFileSystem$6.doCall(DistributedFileSystem.java:393)at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)at org.apache.hadoop.hdfs.DistributedFileSystem.create(DistributedFileSystem.java:393)at org.apache.hadoop.hdfs.DistributedFileSystem.create(DistributedFileSystem.java:337)at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:908)at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:889)at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:786)at org.apache.hadoop.mapreduce.lib.output.TextOutputFormat.getRecordWriter(TextOutputFormat.java:132)at org.apache.hadoop.mapreduce.lib.output.MultipleOutputs.getRecordWriter(MultipleOutputs.java:475)at org.apache.hadoop.mapreduce.lib.output.MultipleOutputs.write(MultipleOutputs.java:433)at org.apache.hadoop.mapreduce.lib.output.MultipleOutputs.write(MultipleOutputs.java:411)at hadoop.WordCount$WordCountReduce.reduce(WordCount.java:51)at hadoop.WordCount$WordCountReduce.reduce(WordCount.java:1)at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:171)at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:627)at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:389)at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163)at java.security.AccessController.doPrivileged(Native Method)at javax.security.auth.Subject.doAs(Subject.java:422)at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1656)at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)

后来发现我的reduce里面MultipleOutputs忘记close了。下面是运行正常的程序

package hadoop;import java.io.IOException;import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapred.lib.MultipleTextOutputFormat;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.Mapper;import org.apache.hadoop.mapreduce.Reducer;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;import org.apache.hadoop.util.GenericOptionsParser;import scala.reflect.generic.Trees.New;public class WordCount {public static class WordCountMapper extends Mapper<Object, Text, Text, IntWritable>{private static final IntWritable Number = new IntWritable(1);private Text word = new Text();@Overrideprotected void map(Object key, Text value, Context context)throws IOException, InterruptedException {StringTokenizer stringTokenizer = new StringTokenizer(value.toString());while(stringTokenizer.hasMoreTokens()){String string = stringTokenizer.nextToken();word.set(string);context.write(word, Number);}}}public static class WordCountReduce extends Reducer<Text, IntWritable, Text, IntWritable>{MultipleOutputs multipleOutputs=null;@Overrideprotected void setup(Reducer<Text, IntWritable, Text, IntWritable>.Context context)throws IOException, InterruptedException {// TODO Auto-generated method stub multipleOutputs = new MultipleOutputs(context);}@Overrideprotected void reduce(Text key, Iterable<IntWritable> vlaues,Context context) throws IOException, InterruptedException {int num=0;for(IntWritable intWritable:vlaues){num+=intWritable.get();}if("hello".equals(key.toString())){multipleOutputs.write("a", key, new IntWritable(num));}else{multipleOutputs.write("b", key, new IntWritable(num));}}@Overrideprotected void cleanup(Reducer<Text, IntWritable, Text, IntWritable>.Context context)throws IOException, InterruptedException {// TODO Auto-generated method stubmultipleOutputs.close();}}public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {Configuration conf = new Configuration();String[] argsValues = new GenericOptionsParser(conf, args).getRemainingArgs();if(args.length<2){System.exit(2);}Job job = new Job(conf, "word count");  job.setJarByClass(WordCount.class);job.setMapperClass(WordCountMapper.class);job.setReducerClass(WordCountReduce.class);        job.setOutputKeyClass(Text.class);        job.setOutputValueClass(IntWritable.class);FileInputFormat.addInputPaths(job, argsValues[0]);FileOutputFormat.setOutputPath(job, new Path(argsValues[1]));MultipleOutputs.addNamedOutput(job, "a", TextOutputFormat.class, Text.class, IntWritable.class);MultipleOutputs.addNamedOutput(job, "b", TextOutputFormat.class, Text.class, IntWritable.class);System.exit(job.waitForCompletion(true)?0:1);}}


原创粉丝点击