我试图在 map 方法中抛出 IOExceptions,但 MR 作业没有停止。在抛出大量 IOException 后,该作业将停止。有没有办法通过抛出异常或一些简单的调用来停止整个工作?谢谢。
问问题
1570 次
2 回答
2
这不是 Hadoop 的理想用例,也不是一个好的实践,但您可以直接从代码内部终止您的工作。因此,每当您达到希望停止工作的条件时,请记录必要的并杀死您的工作。
这可以使用旧mapred
API 或使用.RunningJob.killjob() 来完成Job.killJob()
。您应该在或中分别获得对 jobID 的引用RunningJob
或Job
对象。然后在需要时调用 kill 作业,新 API 的伪代码如下所示:configure()
setup()
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();
...
}
}
}
于 2013-09-25T07:45:37.310 回答
0
您可以通过简单地覆盖 Mapper 的 setup 和 run 函数来跳过 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;
}
}
}
}
于 2017-03-29T14:31:26.413 回答