【发布时间】:2017-08-30 01:56:37
【问题描述】:
我需要从减速器中的映射器访问计数器。这可能吗?如果有怎么做?
例如: 我的映射器是:
public class CounterMapper extends Mapper<Text,Text,Text,Text> {
static enum TestCounters { TEST }
@Override
protected void map(Text key, Text value, Context context)
throws IOException, InterruptedException {
context.getCounter(TestCounters.TEST).increment(1);
context.write(key, value);
}
}
我的减速机是
public class CounterReducer extends Reducer<Text,Text,Text,LongWritable> {
@Override
protected void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
Counter counter = context.getCounter(CounterMapper.TestCounters.TEST);
long counterValue = counter.getValue();
context.write(key, new LongWritable(counterValue));
}
}
counterValue 始终为 0。 是我做错了什么还是这不可能?
【问题讨论】: