2015-04-15 82 views
0

我有控制n个作业链的JobControl。如何在使用JobControl开始MapReduce作业之前执行操作

for (int i = 0; i < iterations; i++) { 
     Job eStep = EStepJob.createJob(config); 
     Job mStep = MStepJob.createJob(config); 
     emChain.add(new ControlledJob(eStep, getDeps(emChain))); 
     emChain.add(new ControlledJob(mStep, getDeps(emChain))); 
    } 
    jobControl.addJobCollection(emChain); 

我想仅在每个作业开始之前清理输出目录; 但是在作业初始化时不能清理目录。 我目前的解决方案是将清除代码放入映射阶段,这大大减缓了执行速度。

 public void map(LongWritable key, Text value, Context context) 
      throws IOException, InterruptedException { 
     FileSystem fs = FileSystem.get(context.getConfiguration()); 
     if (fs.exists(new Path(context.getConfiguration().get(
       AR_PROBS_OUTPUT)))) { 
      fs.delete(
        new Path(context.getConfiguration() 
          .get(AR_PROBS_OUTPUT)), true); 
     } 

有没有更适合的方法?

回答

1

您可以使用相同的方法Mapper.setup()。它是在任何节点上启动任何映射任务之前执行的方法。 我相信你在代码中初始化文件系统时使用HDFS。

无论如何,代码应该以同样的方式工作。但是它执行的次数将等于生成的Mapper任务的数量,而不是每个Mapper任务执行的次数!

相关问题