2009-09-29 21 views

cevap

11

Eğer Hadoop bir yan etkisi dosyası için benzersiz bir kimlik gerekiyorsa, bu kodla işinde girişimi benzersiz kimliği kaldıraç olabilir: partiye Geç

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

ancak TaskAttemptID kullanabilirsiniz mapred.task.id özelliğinin ayrıştırılması için sınıf. Benim durumumda

, ben sayısal girişimi değerini kendisi istedi ve benim Eşleyicisi'ndeki aşağıdaki kullandı: Yeni Hadoop API ile

int _attemptID; 

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

:

context.getTaskAttemptID().getTaskID().getId() 
İlgili konular