Search in sources :

Example 1 with FragmentExecutor

use of org.apache.drill.exec.work.fragment.FragmentExecutor in project drill by apache.

the class ControlMessageHandler method receivingFragmentFinished.

private Ack receivingFragmentFinished(final FinishedReceiver finishedReceiver) {
    final FragmentManager manager = bee.getContext().getWorkBus().getFragmentManagerIfExists(finishedReceiver.getSender());
    FragmentExecutor executor;
    if (manager != null) {
        manager.receivingFragmentFinished(finishedReceiver.getReceiver());
    } else {
        executor = bee.getFragmentRunner(finishedReceiver.getSender());
        if (executor != null) {
            executor.receivingFragmentFinished(finishedReceiver.getReceiver());
        } else {
            logger.warn("Dropping request for early fragment termination for path {} -> {} as path to executor unavailable.", QueryIdHelper.getQueryIdentifier(finishedReceiver.getSender()), QueryIdHelper.getQueryIdentifier(finishedReceiver.getReceiver()));
        }
    }
    return Acks.OK;
}
Also used : FragmentManager(org.apache.drill.exec.work.fragment.FragmentManager) NonRootFragmentManager(org.apache.drill.exec.work.fragment.NonRootFragmentManager) FragmentExecutor(org.apache.drill.exec.work.fragment.FragmentExecutor)

Example 2 with FragmentExecutor

use of org.apache.drill.exec.work.fragment.FragmentExecutor in project drill by axbaretto.

the class ControlMessageHandler method cancelFragment.

/* (non-Javadoc)
   * @see org.apache.drill.exec.work.batch.BitComHandler#cancelFragment(org.apache.drill.exec.proto.ExecProtos.FragmentHandle)
   */
private Ack cancelFragment(final FragmentHandle handle) {
    /**
     * For case 1, see {@link org.apache.drill.exec.work.foreman.QueryManager#cancelExecutingFragments}.
     * In comments below, "active" refers to fragment states: SENDING, AWAITING_ALLOCATION, RUNNING and
     * "inactive" refers to FINISHED, CANCELLATION_REQUESTED, CANCELLED, FAILED
     */
    // Case 2: Cancel active intermediate fragment. Such a fragment will be in the work bus. Delegate cancel to the
    // work bus.
    final boolean removed = bee.getContext().getWorkBus().removeFragmentManager(handle, true);
    if (removed) {
        return Acks.OK;
    }
    // Case 3: Cancel active leaf fragment. Such a fragment will be with the worker bee if and only if it is running.
    // Cancel directly in this case.
    final FragmentExecutor runner = bee.getFragmentRunner(handle);
    if (runner != null) {
        runner.cancel();
        return Acks.OK;
    }
    // Other cases: Fragment completed or does not exist. Currently known cases:
    // (1) Leaf or intermediate fragment that is inactive: although we should not receive a cancellation
    // request; it is possible that before the fragment state was updated in the QueryManager, this handler
    // received a cancel signal.
    // (2) Unknown fragment.
    logger.warn("Dropping request to cancel fragment. {} does not exist.", QueryIdHelper.getQueryIdentifier(handle));
    return Acks.OK;
}
Also used : FragmentExecutor(org.apache.drill.exec.work.fragment.FragmentExecutor)

Example 3 with FragmentExecutor

use of org.apache.drill.exec.work.fragment.FragmentExecutor in project drill by axbaretto.

the class ControlMessageHandler method resumeFragment.

private Ack resumeFragment(final FragmentHandle handle) {
    // resume a pending fragment
    final FragmentManager manager = bee.getContext().getWorkBus().getFragmentManager(handle);
    if (manager != null) {
        manager.unpause();
        return Acks.OK;
    }
    // resume a paused fragment
    final FragmentExecutor runner = bee.getFragmentRunner(handle);
    if (runner != null) {
        runner.unpause();
        return Acks.OK;
    }
    // fragment completed or does not exist
    logger.warn("Dropping request to resume fragment. {} does not exist.", QueryIdHelper.getQueryIdentifier(handle));
    return Acks.OK;
}
Also used : FragmentManager(org.apache.drill.exec.work.fragment.FragmentManager) NonRootFragmentManager(org.apache.drill.exec.work.fragment.NonRootFragmentManager) FragmentExecutor(org.apache.drill.exec.work.fragment.FragmentExecutor)

Example 4 with FragmentExecutor

use of org.apache.drill.exec.work.fragment.FragmentExecutor in project drill by apache.

the class FragmentsRunner method setupRootFragment.

/**
 * Set up the root fragment (which will run locally), and submit it for execution.
 *
 * @param rootFragment root fragment
 * @param rootOperator root operator
 * @throws ExecutionSetupException
 */
private void setupRootFragment(final PlanFragment rootFragment, final FragmentRoot rootOperator) throws ExecutionSetupException {
    QueryManager queryManager = foreman.getQueryManager();
    final FragmentContextImpl rootContext = new FragmentContextImpl(drillbitContext, rootFragment, foreman.getQueryContext(), initiatingClient, drillbitContext.getFunctionImplementationRegistry());
    final FragmentStatusReporter statusReporter = new FragmentStatusReporter(rootContext);
    final FragmentExecutor rootRunner = new FragmentExecutor(rootContext, rootFragment, statusReporter, rootOperator);
    final RootFragmentManager fragmentManager = new RootFragmentManager(rootFragment, rootRunner, statusReporter);
    queryManager.addFragmentStatusTracker(rootFragment, true);
    // FragmentManager is setting buffer for FragmentContext
    if (rootContext.isBuffersDone()) {
        // if we don't have to wait for any incoming data, start the fragment runner.
        bee.addFragmentRunner(rootRunner);
    } else {
        // if we do, record the fragment manager in the workBus.
        drillbitContext.getWorkBus().addFragmentManager(fragmentManager);
    }
}
Also used : FragmentStatusReporter(org.apache.drill.exec.work.fragment.FragmentStatusReporter) FragmentContextImpl(org.apache.drill.exec.ops.FragmentContextImpl) RootFragmentManager(org.apache.drill.exec.work.fragment.RootFragmentManager) FragmentExecutor(org.apache.drill.exec.work.fragment.FragmentExecutor)

Example 5 with FragmentExecutor

use of org.apache.drill.exec.work.fragment.FragmentExecutor in project drill by apache.

the class ControlMessageHandler method startNewFragment.

/**
 * Start a new fragment on this node. These fragments can be leaf or intermediate fragments
 * which are scheduled by remote or local Foreman node.
 * @param fragment
 * @throws UserRpcException
 */
public void startNewFragment(final PlanFragment fragment, final DrillbitContext drillbitContext) throws UserRpcException {
    logger.debug("Received remote fragment start instruction: {}", fragment);
    try {
        final FragmentContextImpl fragmentContext = new FragmentContextImpl(drillbitContext, fragment, drillbitContext.getFunctionImplementationRegistry());
        final FragmentStatusReporter statusReporter = new FragmentStatusReporter(fragmentContext);
        final FragmentExecutor fragmentExecutor = new FragmentExecutor(fragmentContext, fragment, statusReporter);
        // we either need to start the fragment if it is a leaf fragment, or set up a fragment manager if it is non leaf.
        if (fragment.getLeafFragment()) {
            bee.addFragmentRunner(fragmentExecutor);
        } else {
            // isIntermediate, store for incoming data.
            final NonRootFragmentManager manager = new NonRootFragmentManager(fragment, fragmentExecutor, statusReporter);
            drillbitContext.getWorkBus().addFragmentManager(manager);
        }
    } catch (final ExecutionSetupException ex) {
        throw new UserRpcException(drillbitContext.getEndpoint(), "Failed to create fragment context", ex);
    } catch (final Exception e) {
        throw new UserRpcException(drillbitContext.getEndpoint(), "Failure while trying to start remote fragment", e);
    } catch (final OutOfMemoryError t) {
        if (t.getMessage().startsWith("Direct buffer")) {
            throw new UserRpcException(drillbitContext.getEndpoint(), "Out of direct memory while trying to start remote fragment", t);
        } else {
            throw t;
        }
    }
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) NonRootFragmentManager(org.apache.drill.exec.work.fragment.NonRootFragmentManager) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) FragmentStatusReporter(org.apache.drill.exec.work.fragment.FragmentStatusReporter) FragmentContextImpl(org.apache.drill.exec.ops.FragmentContextImpl) FragmentExecutor(org.apache.drill.exec.work.fragment.FragmentExecutor) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) RpcException(org.apache.drill.exec.rpc.RpcException) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException)

Aggregations

FragmentExecutor (org.apache.drill.exec.work.fragment.FragmentExecutor)12 NonRootFragmentManager (org.apache.drill.exec.work.fragment.NonRootFragmentManager)8 FragmentStatusReporter (org.apache.drill.exec.work.fragment.FragmentStatusReporter)7 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)5 RpcException (org.apache.drill.exec.rpc.RpcException)3 UserRpcException (org.apache.drill.exec.rpc.UserRpcException)3 FragmentManager (org.apache.drill.exec.work.fragment.FragmentManager)3 RootFragmentManager (org.apache.drill.exec.work.fragment.RootFragmentManager)3 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)2 FragmentContext (org.apache.drill.exec.ops.FragmentContext)2 ControlTunnel (org.apache.drill.exec.rpc.control.ControlTunnel)2 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)1 IncomingBuffers (org.apache.drill.exec.work.batch.IncomingBuffers)1