2013-09-25 2 views

답변

2

이것은 Hadoop을위한 이상적인 사용 사례는 아니지만 좋은 연습은 아니지만 코드 내부에서 작업을 바로 종료 할 수 있습니다. 그래서 직장을 그만두기를 원하는 조건에 도달 할 때마다 필요한 일을 기록하고 직장을 그만 두십시오.

이전 mapred API를 사용하거나 Job.killJob()을 사용하여 RunningJob.killjob()을 수행 할 수 있습니다. configure() 또는 setup()에있는 작업 ID에 대해 RunningJob 또는 Job 개체를 각각 참조해야합니다. 당신이 필요로 할 때 그리고 킬 (kill) 작업을 전화로 보일 것이다 새로운 API에 대한 의사 코드는 다음과 같습니다

Class Map extends mapper<K1,V1,K2,V2>{ 
Job myJob; 
@Override 
setup(){ 
// Get the JObID 
// Get the Job object 
} 

map(){ 
... 
if(condition-to-stop){ 
myJob.killJob(); 
... 
} 
} 
} 
+0

새 API에서 어떻게 org.apache.hadoop.mapreduce.Job의 인스턴스를 org.apache.hadoop.mapreduce.JobID에서 가져 옵니까? –

0

당신은 간단하게 설치하고 매퍼의 실행 기능을 재정 의하여 getJobID 방법을 건너 뛸 수 있습니다.

public static class LineMapper extends Mapper<Object, Text, Text, Text>{ 
     boolean myCondition; 

     @Override 
     public void setup(Context context){ 
      myCondition = true; 
     } 

     public void map(Object key, Text value, Context context) throws IOException, InterruptedException { 
     //something happens in your code and you change the condition to false to stop the mapper 
      myCondition = false; 
     } 

     @Override 
     public void run(Context context) throws IOException, InterruptedException { 

      setup(context); 
      while (context.nextKeyValue()) { 
       if(linecounter < 50) { 
        map(context.getCurrentKey(), context.getCurrentValue(), context); 
       } else { 
        cleanup(context); 
        break; 
       } 
      } 
     } 
    } 
관련 문제