use of org.apache.ignite.internal.processors.hadoop.HadoopTaskCancelledException in project ignite by apache.
the class HadoopV1MapTask method run.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void run(HadoopTaskContext taskCtx) throws IgniteCheckedException {
HadoopJobEx job = taskCtx.job();
HadoopV2TaskContext taskCtx0 = (HadoopV2TaskContext) taskCtx;
if (taskCtx.taskInfo().hasMapperIndex())
HadoopMapperUtils.mapperIndex(taskCtx.taskInfo().mapperIndex());
else
HadoopMapperUtils.clearMapperIndex();
try {
JobConf jobConf = taskCtx0.jobConf();
InputFormat inFormat = jobConf.getInputFormat();
HadoopInputSplit split = info().inputSplit();
InputSplit nativeSplit;
if (split instanceof HadoopFileBlock) {
HadoopFileBlock block = (HadoopFileBlock) split;
nativeSplit = new FileSplit(new Path(block.file().toString()), block.start(), block.length(), EMPTY_HOSTS);
} else
nativeSplit = (InputSplit) taskCtx0.getNativeSplit(split);
assert nativeSplit != null;
Reporter reporter = new HadoopV1Reporter(taskCtx);
HadoopV1OutputCollector collector = null;
try {
collector = collector(jobConf, taskCtx0, !job.info().hasCombiner() && !job.info().hasReducer(), fileName(), taskCtx0.attemptId());
RecordReader reader = inFormat.getRecordReader(nativeSplit, jobConf, reporter);
Mapper mapper = ReflectionUtils.newInstance(jobConf.getMapperClass(), jobConf);
Object key = reader.createKey();
Object val = reader.createValue();
assert mapper != null;
try {
try {
while (reader.next(key, val)) {
if (isCancelled())
throw new HadoopTaskCancelledException("Map task cancelled.");
mapper.map(key, val, collector, reporter);
}
taskCtx.onMapperFinished();
} finally {
mapper.close();
}
} finally {
collector.closeWriter();
}
collector.commit();
} catch (Exception e) {
if (collector != null)
collector.abort();
throw new IgniteCheckedException(e);
}
} finally {
HadoopMapperUtils.clearMapperIndex();
}
}
use of org.apache.ignite.internal.processors.hadoop.HadoopTaskCancelledException in project ignite by apache.
the class HadoopV1Task method collector.
/**
*
* @param jobConf Job configuration.
* @param taskCtx Task context.
* @param directWrite Direct write flag.
* @param fileName File name.
* @param attempt Attempt of task.
* @return Collector.
* @throws IOException In case of IO exception.
*/
protected HadoopV1OutputCollector collector(JobConf jobConf, HadoopV2TaskContext taskCtx, boolean directWrite, @Nullable String fileName, TaskAttemptID attempt) throws IOException {
HadoopV1OutputCollector collector = new HadoopV1OutputCollector(jobConf, taskCtx, directWrite, fileName, attempt) {
/** {@inheritDoc} */
@Override
public void collect(Object key, Object val) throws IOException {
if (cancelled)
throw new HadoopTaskCancelledException("Task cancelled.");
super.collect(key, val);
}
};
collector.setup();
return collector;
}
Aggregations