Search in sources :

Example 1 with NotifyTaskFailureWork

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));
    }
}
Also used : IPartitionCollector(org.apache.hyracks.api.comm.IPartitionCollector) IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) Semaphore(java.util.concurrent.Semaphore) NotifyTaskCompleteWork(org.apache.hyracks.control.nc.work.NotifyTaskCompleteWork) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) NotifyTaskFailureWork(org.apache.hyracks.control.nc.work.NotifyTaskFailureWork)

Aggregations

Semaphore (java.util.concurrent.Semaphore)1 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)1 IPartitionCollector (org.apache.hyracks.api.comm.IPartitionCollector)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 HyracksException (org.apache.hyracks.api.exceptions.HyracksException)1 NotifyTaskCompleteWork (org.apache.hyracks.control.nc.work.NotifyTaskCompleteWork)1 NotifyTaskFailureWork (org.apache.hyracks.control.nc.work.NotifyTaskFailureWork)1