2009-09-29 32 views

Trả lời

11

Nếu bạn cần một id duy nhất cho một tập tin tác dụng phụ trong hadoop, bạn có thể tận dụng các nỗ lực id duy nhất trong công việc với mã này:

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

muộn để đảng, nhưng bạn có thể sử dụng TaskAttemptID để phân tích thuộc tính mapred.task.id.

Trong trường hợp của tôi, tôi muốn giá trị nỗ lực số chính nó và sử dụng như sau trong Mapper của tôi:

int _attemptID; 

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

Với Hadoop API mới:

context.getTaskAttemptID().getTaskID().getId() 
Các vấn đề liên quan