java - hadoop 当前租户正在尝试重新创建文件

标签 java hadoop mapreduce cloudera

我的 MapReduce 作业按日期处理数据,需要将输出写入特定的文件夹结构。目前的期望是生成以下结构的输出:

天 => 天/月/文件

reducer 类:

public static class Reducerclass  extends Reducer<Text,Text,Text,Text> {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        private MultipleOutputs<Text, Text> multipleOutputs;
        public void reduce(Text rkey, Iterable<Text> rvalue, Context context) throws IOException, InterruptedException {
            multipleOutputs = new MultipleOutputs<Text, Text>(context);
            for(Text value : rvalue) {              

                Date date = new Date(Long.parseLong(value.toString()));     
                String datestring = dateFormat.format(date); 
                //              context.write(new Text(rkey + ", "),new Text(", "+value +", "+datestring));


                String[] parts = datestring.split(" ");
                String[] dateparts = parts[0].split("-");

                String day = dateparts[2]; 
                String month = dateparts[1]; 
                String year = dateparts[0]; 


                String baseFileName ="Days";  
                String dayFolderpath = baseFileName + day + "/" + month + "/" + year;

                String outputFileName = baseFileName + "/" + month + "/" + day; 
                if(datestring.equals("2017-10-26 20:30:42") || datestring.equals("2017-10-26 20:29:32")){

                    multipleOutputs.write(new Text(rkey + ", "), new Text(", "+value +", "+datestring),outputFileName) ;
                }
                else{   

                multipleOutputs.write(new Text(rkey + ", "), new Text(", "+value +", "+datestring),generateFileName(new Text(rkey),new Text(value) )) ;
                }

            }   
        }
        String generateFileName(Text key, Text value){
            return key.toString() + "_" + value.toString();     
        }

        @Override
        public void setup(Context context){
            multipleOutputs = new MultipleOutputs<Text, Text>(context);
        }

        @Override
        public void cleanup(final Context context) throws IOException, InterruptedException{
            multipleOutputs.close();
        }
    }

当我运行 jar 时收到以下错误消息

17/11/14 18:30:17 INFO mapreduce.Job: Task Id : attempt_1510547616164_0054_r_000000_0, Status : FAILED
Error: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException): failed to create file /user/hdfs/OutputFile/_temporary/1/_temporary/attempt_1510547616164_0054_r_000000_0/Days/10/26-r-00000 for DFSClient_attempt_1510547616164_0054_r_000000_0_757297700_1 for client 10.0.2.15 because current leaseholder is trying to recreate file.
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.recoverLeaseInternal(FSNamesystem.java:3171)

最佳答案

我相信你错过的是:

job.setReducerClass(ReducerFormatMultiOutput.class);

请贴出驱动代码,找出具体原因。

关于java - hadoop 当前租户正在尝试重新创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47298503/

相关文章:

java - 如何使用JPA从自引用实体中的某个级别选择子实体?

java - 在 Java 中不进行强制转换来表示数字

java - 如何集成eclipse和hadoop 2.6

hadoop - 增加hdfs java堆内存的正确方法

java - 如何调试第三方Intellij IDEA插件?

java - 如何使用类中的参数返回特定方法的名称

hadoop - 自定义文件格式

python - 用于Python(PySpark)的Spark的自定义Hadoop配置?

java - 如何在 Hive 嵌入式模式下运行包含 "select count(*)"和 "group by"子句的 Hive Sql 查询?

mysql - 无法在 Mac 上使用 mysql 启动 Hive