Search in sources :

Example 1 with IOperatorNodePushable

use of org.apache.hyracks.api.dataflow.IOperatorNodePushable in project asterixdb by apache.

the class SuperActivityOperatorNodePushable method init.

private void init() throws HyracksDataException {
    Queue<Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>>> childQueue = new LinkedList<>();
    List<IConnectorDescriptor> outputConnectors;
    /*
         * Set up the source operators
         */
    for (Entry<ActivityId, IActivity> entry : startActivities.entrySet()) {
        IOperatorNodePushable opPushable = entry.getValue().createPushRuntime(ctx, recordDescProvider, partition, nPartitions);
        operatorNodePushablesBFSOrder.add(opPushable);
        operatorNodePushables.put(entry.getKey(), opPushable);
        inputArity += opPushable.getInputArity();
        outputConnectors = MapUtils.getObject(parent.getActivityOutputMap(), entry.getKey(), Collections.emptyList());
        for (IConnectorDescriptor conn : outputConnectors) {
            childQueue.add(parent.getConnectorActivityMap().get(conn.getConnectorId()));
        }
    }
    /*
         * Using BFS (breadth-first search) to construct to runtime execution DAG...
         */
    while (!childQueue.isEmpty()) {
        /*
             * construct the source to destination information
             */
        Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>> channel = childQueue.poll();
        ActivityId sourceId = channel.getLeft().getLeft().getActivityId();
        int outputChannel = channel.getLeft().getRight();
        ActivityId destId = channel.getRight().getLeft().getActivityId();
        int inputChannel = channel.getRight().getRight();
        IOperatorNodePushable sourceOp = operatorNodePushables.get(sourceId);
        IOperatorNodePushable destOp = operatorNodePushables.get(destId);
        if (destOp == null) {
            destOp = channel.getRight().getLeft().createPushRuntime(ctx, recordDescProvider, partition, nPartitions);
            operatorNodePushablesBFSOrder.add(destOp);
            operatorNodePushables.put(destId, destOp);
        }
        /*
             * construct the dataflow connection from a producer to a consumer
             */
        sourceOp.setOutputFrameWriter(outputChannel, destOp.getInputFrameWriter(inputChannel), recordDescProvider.getInputRecordDescriptor(destId, inputChannel));
        /*
             * traverse to the child of the current activity
             */
        outputConnectors = MapUtils.getObject(parent.getActivityOutputMap(), destId, Collections.emptyList());
        /*
             * expend the executing activities further to the downstream
             */
        for (IConnectorDescriptor conn : outputConnectors) {
            if (conn != null) {
                childQueue.add(parent.getConnectorActivityMap().get(conn.getConnectorId()));
            }
        }
    }
}
Also used : IConnectorDescriptor(org.apache.hyracks.api.dataflow.IConnectorDescriptor) IActivity(org.apache.hyracks.api.dataflow.IActivity) IOperatorNodePushable(org.apache.hyracks.api.dataflow.IOperatorNodePushable) ActivityId(org.apache.hyracks.api.dataflow.ActivityId) LinkedList(java.util.LinkedList) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with IOperatorNodePushable

use of org.apache.hyracks.api.dataflow.IOperatorNodePushable in project asterixdb by apache.

the class SuperActivityOperatorNodePushable method getInputFrameWriter.

@Override
public IFrameWriter getInputFrameWriter(final int index) {
    /*
         * get the right IFrameWriter from the cluster input index
         */
    Pair<ActivityId, Integer> activityIdInputIndex = parent.getActivityIdInputIndex(index);
    IOperatorNodePushable operatorNodePushable = operatorNodePushables.get(activityIdInputIndex.getLeft());
    return operatorNodePushable.getInputFrameWriter(activityIdInputIndex.getRight());
}
Also used : IOperatorNodePushable(org.apache.hyracks.api.dataflow.IOperatorNodePushable) ActivityId(org.apache.hyracks.api.dataflow.ActivityId)

Example 3 with IOperatorNodePushable

use of org.apache.hyracks.api.dataflow.IOperatorNodePushable in project asterixdb by apache.

the class SuperActivityOperatorNodePushable method runInParallel.

private void runInParallel(OperatorNodePushableAction action) throws HyracksDataException {
    List<Future<Void>> tasks = new ArrayList<>();
    final Semaphore startSemaphore = new Semaphore(1 - operatorNodePushablesBFSOrder.size());
    final Semaphore completeSemaphore = new Semaphore(1 - operatorNodePushablesBFSOrder.size());
    try {
        for (final IOperatorNodePushable op : operatorNodePushablesBFSOrder) {
            tasks.add(ctx.getExecutorService().submit(() -> {
                startSemaphore.release();
                try {
                    action.run(op);
                } finally {
                    completeSemaphore.release();
                }
                return null;
            }));
        }
        for (Future<Void> task : tasks) {
            task.get();
        }
    } catch (InterruptedException e) {
        cancelTasks(tasks, startSemaphore, completeSemaphore);
        Thread.currentThread().interrupt();
        throw HyracksDataException.create(e);
    } catch (Exception e) {
        cancelTasks(tasks, startSemaphore, completeSemaphore);
        throw HyracksDataException.create(e);
    }
}
Also used : IOperatorNodePushable(org.apache.hyracks.api.dataflow.IOperatorNodePushable) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Semaphore(java.util.concurrent.Semaphore) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 4 with IOperatorNodePushable

use of org.apache.hyracks.api.dataflow.IOperatorNodePushable in project asterixdb by apache.

the class StartTasksWork method run.

@Override
public void run() {
    Task task = null;
    try {
        NCServiceContext serviceCtx = ncs.getContext();
        Joblet joblet = getOrCreateLocalJoblet(deploymentId, jobId, serviceCtx, acgBytes);
        final ActivityClusterGraph acg = joblet.getActivityClusterGraph();
        IRecordDescriptorProvider rdp = new IRecordDescriptorProvider() {

            @Override
            public RecordDescriptor getOutputRecordDescriptor(ActivityId aid, int outputIndex) {
                ActivityCluster ac = acg.getActivityMap().get(aid);
                IConnectorDescriptor conn = ac.getActivityOutputMap().get(aid).get(outputIndex);
                return ac.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
            }

            @Override
            public RecordDescriptor getInputRecordDescriptor(ActivityId aid, int inputIndex) {
                ActivityCluster ac = acg.getActivityMap().get(aid);
                IConnectorDescriptor conn = ac.getActivityInputMap().get(aid).get(inputIndex);
                return ac.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
            }
        };
        for (TaskAttemptDescriptor td : taskDescriptors) {
            TaskAttemptId taId = td.getTaskAttemptId();
            TaskId tid = taId.getTaskId();
            ActivityId aid = tid.getActivityId();
            ActivityCluster ac = acg.getActivityMap().get(aid);
            IActivity han = ac.getActivityMap().get(aid);
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info("Initializing " + taId + " -> " + han);
            }
            final int partition = tid.getPartition();
            List<IConnectorDescriptor> inputs = ac.getActivityInputMap().get(aid);
            task = new Task(joblet, taId, han.getClass().getName(), ncs.getExecutor(), ncs, createInputChannels(td, inputs));
            IOperatorNodePushable operator = han.createPushRuntime(task, rdp, partition, td.getPartitionCount());
            List<IPartitionCollector> collectors = new ArrayList<>();
            if (inputs != null) {
                for (int i = 0; i < inputs.size(); ++i) {
                    IConnectorDescriptor conn = inputs.get(i);
                    IConnectorPolicy cPolicy = connectorPoliciesMap.get(conn.getConnectorId());
                    if (LOGGER.isLoggable(Level.INFO)) {
                        LOGGER.info("input: " + i + ": " + conn.getConnectorId());
                    }
                    RecordDescriptor recordDesc = ac.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
                    IPartitionCollector collector = createPartitionCollector(td, partition, task, i, conn, recordDesc, cPolicy);
                    collectors.add(collector);
                }
            }
            List<IConnectorDescriptor> outputs = ac.getActivityOutputMap().get(aid);
            if (outputs != null) {
                for (int i = 0; i < outputs.size(); ++i) {
                    final IConnectorDescriptor conn = outputs.get(i);
                    RecordDescriptor recordDesc = ac.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
                    IConnectorPolicy cPolicy = connectorPoliciesMap.get(conn.getConnectorId());
                    IPartitionWriterFactory pwFactory = createPartitionWriterFactory(task, cPolicy, jobId, conn, partition, taId, flags);
                    if (LOGGER.isLoggable(Level.INFO)) {
                        LOGGER.info("output: " + i + ": " + conn.getConnectorId());
                    }
                    IFrameWriter writer = conn.createPartitioner(task, recordDesc, pwFactory, partition, td.getPartitionCount(), td.getOutputPartitionCounts()[i]);
                    operator.setOutputFrameWriter(i, writer, recordDesc);
                }
            }
            task.setTaskRuntime(collectors.toArray(new IPartitionCollector[collectors.size()]), operator);
            joblet.addTask(task);
            task.start();
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Failure starting a task", e);
        // notify cc of start task failure
        List<Exception> exceptions = new ArrayList<>();
        ExceptionUtils.setNodeIds(exceptions, ncs.getId());
        ncs.getWorkQueue().schedule(new NotifyTaskFailureWork(ncs, task, exceptions));
    }
}
Also used : IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) Task(org.apache.hyracks.control.nc.Task) TaskId(org.apache.hyracks.api.dataflow.TaskId) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) ActivityId(org.apache.hyracks.api.dataflow.ActivityId) ArrayList(java.util.ArrayList) IRecordDescriptorProvider(org.apache.hyracks.api.dataflow.value.IRecordDescriptorProvider) Joblet(org.apache.hyracks.control.nc.Joblet) IActivity(org.apache.hyracks.api.dataflow.IActivity) NCServiceContext(org.apache.hyracks.control.nc.application.NCServiceContext) INCServiceContext(org.apache.hyracks.api.application.INCServiceContext) List(java.util.List) ArrayList(java.util.ArrayList) IConnectorDescriptor(org.apache.hyracks.api.dataflow.IConnectorDescriptor) IPartitionCollector(org.apache.hyracks.api.comm.IPartitionCollector) TaskAttemptId(org.apache.hyracks.api.dataflow.TaskAttemptId) IConnectorPolicy(org.apache.hyracks.api.dataflow.connectors.IConnectorPolicy) IPartitionWriterFactory(org.apache.hyracks.api.comm.IPartitionWriterFactory) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) UnknownHostException(java.net.UnknownHostException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) ActivityCluster(org.apache.hyracks.api.job.ActivityCluster) TaskAttemptDescriptor(org.apache.hyracks.control.common.job.TaskAttemptDescriptor) ActivityClusterGraph(org.apache.hyracks.api.job.ActivityClusterGraph) IOperatorNodePushable(org.apache.hyracks.api.dataflow.IOperatorNodePushable)

Example 5 with IOperatorNodePushable

use of org.apache.hyracks.api.dataflow.IOperatorNodePushable in project asterixdb by apache.

the class SuperActivityOperatorNodePushable method setOutputFrameWriter.

@Override
public void setOutputFrameWriter(int clusterOutputIndex, IFrameWriter writer, RecordDescriptor recordDesc) throws HyracksDataException {
    /*
         * set the right output frame writer
         */
    Pair<ActivityId, Integer> activityIdOutputIndex = parent.getActivityIdOutputIndex(clusterOutputIndex);
    IOperatorNodePushable opPushable = operatorNodePushables.get(activityIdOutputIndex.getLeft());
    opPushable.setOutputFrameWriter(activityIdOutputIndex.getRight(), writer, recordDesc);
}
Also used : IOperatorNodePushable(org.apache.hyracks.api.dataflow.IOperatorNodePushable) ActivityId(org.apache.hyracks.api.dataflow.ActivityId)

Aggregations

IOperatorNodePushable (org.apache.hyracks.api.dataflow.IOperatorNodePushable)5 ActivityId (org.apache.hyracks.api.dataflow.ActivityId)4 ArrayList (java.util.ArrayList)2 IActivity (org.apache.hyracks.api.dataflow.IActivity)2 IConnectorDescriptor (org.apache.hyracks.api.dataflow.IConnectorDescriptor)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 UnknownHostException (java.net.UnknownHostException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 Semaphore (java.util.concurrent.Semaphore)1 Pair (org.apache.commons.lang3.tuple.Pair)1 INCServiceContext (org.apache.hyracks.api.application.INCServiceContext)1 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)1 IPartitionCollector (org.apache.hyracks.api.comm.IPartitionCollector)1 IPartitionWriterFactory (org.apache.hyracks.api.comm.IPartitionWriterFactory)1 TaskAttemptId (org.apache.hyracks.api.dataflow.TaskAttemptId)1 TaskId (org.apache.hyracks.api.dataflow.TaskId)1 IConnectorPolicy (org.apache.hyracks.api.dataflow.connectors.IConnectorPolicy)1 IRecordDescriptorProvider (org.apache.hyracks.api.dataflow.value.IRecordDescriptorProvider)1