我在job类中有一些map类,有时需要中断当前任务的执行(hadoop map reduce框架为job的inputformat生成的每个inputspilt生成一个map任务):
public static class TestJobMapper
extends Mapper<LongWritable, Text, Text, Text> {
@Override
protected void setup(Context context) throws IOException, InterruptedException {
super.setup(context);
// here I want to check some predicate, and may be break execution of task
// http://hadoop.apache.org/docs/r2.3.0/api/org/apache/hadoop/mapreduce/Mapper.html
}
// continue....
2条答案
按热度按时间j8ag8udp1#
通过重写
run()
方法。在普通代码中,实现方式如下:
您可以做的是围绕以下内容进行设置:
这样,如果 predicate 告诉任务,任务就直接进入完成状态。这仍然有一些开销,但它比更改输入格式更容易。
46scxncf2#
不能在setup方法处中断执行。
但是,如果不在某个拆分上执行Map器的逻辑是基于拆分编号的,则可以使用自定义的inputformat和record reader跳过某些记录/输入拆分。