use of org.apache.hyracks.control.nc.work.NotifyTaskFailureWork in project asterixdb by apache.
the class Task method run.
@Override
public void run() {
Thread ct = Thread.currentThread();
String threadName = ct.getName();
// the thread is not escaped from interruption.
if (!addPendingThread(ct)) {
exceptions.add(new InterruptedException("Task " + getTaskAttemptId() + " was aborted!"));
ExceptionUtils.setNodeIds(exceptions, ncs.getId());
ncs.getWorkQueue().schedule(new NotifyTaskFailureWork(ncs, this, exceptions));
return;
}
ct.setName(displayName + ":" + taskAttemptId + ":" + 0);
try {
try {
operator.initialize();
if (collectors.length > 0) {
final Semaphore sem = new Semaphore(collectors.length - 1);
for (int i = 1; i < collectors.length; ++i) {
final IPartitionCollector collector = collectors[i];
final IFrameWriter writer = operator.getInputFrameWriter(i);
sem.acquire();
final int cIdx = i;
executorService.execute(new Runnable() {
@Override
public void run() {
Thread thread = Thread.currentThread();
// the thread is not escaped from interruption.
if (!addPendingThread(thread)) {
return;
}
String oldName = thread.getName();
thread.setName(displayName + ":" + taskAttemptId + ":" + cIdx);
thread.setPriority(Thread.MIN_PRIORITY);
try {
pushFrames(collector, inputChannelsFromConnectors.get(cIdx), writer);
} catch (HyracksDataException e) {
synchronized (Task.this) {
exceptions.add(e);
}
} finally {
thread.setName(oldName);
sem.release();
removePendingThread(thread);
}
}
});
}
try {
pushFrames(collectors[0], inputChannelsFromConnectors.get(0), operator.getInputFrameWriter(0));
} finally {
sem.acquire(collectors.length - 1);
}
}
} finally {
operator.deinitialize();
}
NodeControllerService ncs = joblet.getNodeController();
ncs.getWorkQueue().schedule(new NotifyTaskCompleteWork(ncs, this));
} catch (Exception e) {
exceptions.add(e);
} finally {
ct.setName(threadName);
close();
removePendingThread(ct);
}
if (!exceptions.isEmpty()) {
for (Exception e : exceptions) {
e.printStackTrace();
}
NodeControllerService ncs = joblet.getNodeController();
ExceptionUtils.setNodeIds(exceptions, ncs.getId());
ncs.getWorkQueue().schedule(new NotifyTaskFailureWork(ncs, this, exceptions));
}
}
Aggregations