2009-09-29 78 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() 
相關問題