2009-09-29 73 views

回答

11

如果您需要在Hadoop的一个副作用文件的唯一ID,您可以利用的尝试独特的ID与此代码的工作:

public static String getAttemptId(Configuration conf) throws IllegalArgumentException 
    { 
     if (conf == null) { 
      throw new NullPointerException("conf is null"); 
     } 

     String taskId = conf.get("mapred.task.id"); 
     if (taskId == null) { 
      throw new IllegalArgumentException("Configutaion does not contain the property mapred.task.id"); 
     } 

     String[] parts = taskId.split("_"); 
     if (parts.length != 6 || 
       !parts[0].equals("attempt") || 
       (!"m".equals(parts[3]) && !"r".equals(parts[3]))) { 
      throw new IllegalArgumentException("TaskAttemptId string : " + taskId + " is not properly formed"); 
     } 

     return parts[4] + "-" + parts[5]; 
    } 
4

迟到了,但你可以使用TaskAttemptID类来解析mapred.task.id属性。

在我的情况,我想数字尝试值本身和使用我的映射如下:

int _attemptID; 

@Override 
public void configure(JobConf conf) { 
    TaskAttemptID attempt = TaskAttemptID.forName(conf.get("mapred.task.id")); 
    _attemptID = attempt.id(); 
} 
9

有了新的Hadoop API:

context.getTaskAttemptID().getTaskID().getId() 
相关问题