Search in sources :

Example 51 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext in project drill by apache.

the class TestBitBitKerberos method setupFragmentContextAndManager.

private static void setupFragmentContextAndManager() {
    final FragmentContext fcontext = new MockUp<FragmentContext>() {

        @SuppressWarnings("unused")
        BufferAllocator getAllocator() {
            return c1.getAllocator();
        }
    }.getMockInstance();
    manager = new MockUp<FragmentManager>() {

        int v = 0;

        @Mock
        boolean handle(IncomingDataBatch batch) throws FragmentSetupException, IOException {
            try {
                v++;
                if (v % 10 == 0) {
                    System.out.println("sleeping.");
                    Thread.sleep(3000);
                }
            } catch (InterruptedException e) {
            }
            RawFragmentBatch rfb = batch.newRawFragmentBatch(c1.getAllocator());
            rfb.sendOk();
            rfb.release();
            return true;
        }

        @SuppressWarnings("unused")
        public FragmentContext getFragmentContext() {
            return fcontext;
        }
    }.getMockInstance();
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) FragmentContext(org.apache.drill.exec.ops.FragmentContext) MockUp(mockit.MockUp) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator)

Example 52 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext in project drill by apache.

the class TestImplicitCastFunctions method runTest.

public void runTest(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable {
    mockDrillbitContext(bitContext);
    final String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8);
    if (reader == null) {
        reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    }
    if (registry == null) {
        registry = new FunctionImplementationRegistry(c);
    }
    if (context == null) {
        context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    }
    final PhysicalPlan plan = reader.readPhysicalPlan(planString);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    // skip schema batch
    exec.next();
    while (exec.next()) {
        final Object[] res = getRunResult(exec);
        assertEquals("return count does not match", res.length, expectedResults.length);
        for (int i = 0; i < res.length; i++) {
            assertEquals(String.format("column %s does not match", i), res[i], expectedResults[i]);
        }
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 53 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext in project drill by apache.

the class ControlMessageHandler method startNewRemoteFragment.

private void startNewRemoteFragment(final PlanFragment fragment) throws UserRpcException {
    logger.debug("Received remote fragment start instruction", fragment);
    final DrillbitContext drillbitContext = bee.getContext();
    try {
        // 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()) {
            final FragmentContext context = new FragmentContext(drillbitContext, fragment, drillbitContext.getFunctionImplementationRegistry());
            final ControlTunnel tunnel = drillbitContext.getController().getTunnel(fragment.getForeman());
            final FragmentStatusReporter statusReporter = new FragmentStatusReporter(context, tunnel);
            final FragmentExecutor fr = new FragmentExecutor(context, fragment, statusReporter);
            bee.addFragmentRunner(fr);
        } else {
            // isIntermediate, store for incoming data.
            final NonRootFragmentManager manager = new NonRootFragmentManager(fragment, drillbitContext);
            drillbitContext.getWorkBus().addFragmentManager(manager);
        }
    } 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 : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) ControlTunnel(org.apache.drill.exec.rpc.control.ControlTunnel) NonRootFragmentManager(org.apache.drill.exec.work.fragment.NonRootFragmentManager) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) FragmentContext(org.apache.drill.exec.ops.FragmentContext) FragmentStatusReporter(org.apache.drill.exec.work.fragment.FragmentStatusReporter) FragmentExecutor(org.apache.drill.exec.work.fragment.FragmentExecutor) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) RpcException(org.apache.drill.exec.rpc.RpcException)

Example 54 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext in project drill by axbaretto.

the class TestExternalSortInternals method testConfigConstraints.

@Test
public void testConfigConstraints() {
    int memConstraint = 40 * ONE_MEG;
    int batchSizeConstraint = ONE_MEG / 2;
    int mergeSizeConstraint = ONE_MEG;
    OperatorFixture.Builder builder = new OperatorFixture.Builder();
    builder.configBuilder().put(ExecConstants.EXTERNAL_SORT_MAX_MEMORY, memConstraint).put(ExecConstants.EXTERNAL_SORT_SPILL_BATCH_SIZE, batchSizeConstraint).build();
    FragmentContext fragmentContext = builder.build().getFragmentContext();
    fragmentContext.getOptions().setLocalOption(ExecConstants.OUTPUT_BATCH_SIZE, mergeSizeConstraint);
    SortConfig sortConfig = new SortConfig(fragmentContext.getConfig(), fragmentContext.getOptions());
    long memoryLimit = 50 * ONE_MEG;
    SortMemoryManager memManager = new SortMemoryManager(sortConfig, memoryLimit);
    assertEquals(batchSizeConstraint, memManager.getPreferredSpillBatchSize());
    assertEquals(mergeSizeConstraint, memManager.getPreferredMergeBatchSize());
    assertEquals(memConstraint, memManager.getMemoryLimit());
    int rowWidth = 300;
    int rowCount = 10000;
    int batchSize = rowWidth * rowCount * 2;
    memManager.updateEstimates(batchSize, rowWidth, rowCount);
    verifyCalcs(sortConfig, memConstraint, memManager, batchSize, rowWidth, rowCount);
}
Also used : FragmentContext(org.apache.drill.exec.ops.FragmentContext) OperatorFixture(org.apache.drill.test.OperatorFixture) OperatorTest(org.apache.drill.categories.OperatorTest) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 55 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext in project drill by axbaretto.

the class TestExternalSortInternals method testMergeCalcs.

@Test
public void testMergeCalcs() {
    // No artificial merge limit
    int mergeLimitConstraint = 100;
    OperatorFixture.Builder builder = new OperatorFixture.Builder();
    builder.configBuilder().put(ExecConstants.EXTERNAL_SORT_MERGE_LIMIT, mergeLimitConstraint).build();
    FragmentContext fragmentContext = builder.build().getFragmentContext();
    SortConfig sortConfig = new SortConfig(fragmentContext.getConfig(), fragmentContext.getOptions());
    // Allow four spill batches, 8 MB each, plus one output of 16
    // Allow for internal fragmentation
    // 96 > (4 * 8 + 16) * 2
    long memoryLimit = 96 * ONE_MEG;
    SortMemoryManager memManager = new SortMemoryManager(sortConfig, memoryLimit);
    // Prime the estimates. Batch size is data size, not buffer size.
    int rowWidth = 300;
    int rowCount = 10000;
    int batchSize = rowWidth * rowCount * 2;
    memManager.updateEstimates(batchSize, rowWidth, rowCount);
    assertFalse(memManager.isLowMemory());
    int spillBatchBufferSize = memManager.getSpillBatchSize().maxBufferSize;
    int inputBatchBufferSize = memManager.getInputBatchSize().expectedBufferSize;
    // One in-mem batch, no merging.
    long allocMemory = inputBatchBufferSize;
    MergeTask task = memManager.consolidateBatches(allocMemory, 1, 0);
    assertEquals(MergeAction.NONE, task.action);
    // Many in-mem batches, just enough to merge
    int memBatches = (int) (memManager.getMergeMemoryLimit() / inputBatchBufferSize);
    allocMemory = memBatches * inputBatchBufferSize;
    task = memManager.consolidateBatches(allocMemory, memBatches, 0);
    assertEquals(MergeAction.NONE, task.action);
    // Spills if no room to merge spilled and in-memory batches
    int spillCount = (int) Math.ceil((memManager.getMergeMemoryLimit() - allocMemory) / (1.0 * spillBatchBufferSize));
    assertTrue(spillCount >= 1);
    task = memManager.consolidateBatches(allocMemory, memBatches, spillCount);
    assertEquals(MergeAction.SPILL, task.action);
    // One more in-mem batch: now needs to spill
    memBatches++;
    allocMemory = memBatches * inputBatchBufferSize;
    task = memManager.consolidateBatches(allocMemory, memBatches, 0);
    assertEquals(MergeAction.SPILL, task.action);
    // No spill for various in-mem/spill run combinations
    long freeMem = memManager.getMergeMemoryLimit() - spillBatchBufferSize;
    memBatches = (int) (freeMem / inputBatchBufferSize);
    allocMemory = memBatches * inputBatchBufferSize;
    task = memManager.consolidateBatches(allocMemory, memBatches, 1);
    assertEquals(MergeAction.NONE, task.action);
    freeMem = memManager.getMergeMemoryLimit() - 2 * spillBatchBufferSize;
    memBatches = (int) (freeMem / inputBatchBufferSize);
    allocMemory = memBatches * inputBatchBufferSize;
    task = memManager.consolidateBatches(allocMemory, memBatches, 2);
    assertEquals(MergeAction.NONE, task.action);
    // No spill if no in-memory, only spill, and spill fits
    freeMem = memManager.getMergeMemoryLimit();
    int spillBatches = (int) (freeMem / spillBatchBufferSize);
    task = memManager.consolidateBatches(0, 0, spillBatches);
    assertEquals(MergeAction.NONE, task.action);
    // One more and must merge
    task = memManager.consolidateBatches(0, 0, spillBatches + 1);
    assertEquals(MergeAction.MERGE, task.action);
    assertEquals(2, task.count);
    // Two more and will merge more
    task = memManager.consolidateBatches(0, 0, spillBatches + 2);
    assertEquals(MergeAction.MERGE, task.action);
    assertEquals(3, task.count);
    // If only one spilled run, and no in-memory batches,
    // skip merge.
    task = memManager.consolidateBatches(0, 0, 1);
    assertEquals(MergeAction.NONE, task.action);
    // Very large number of spilled runs. Limit to what fits in memory.
    task = memManager.consolidateBatches(0, 0, 1000);
    assertEquals(MergeAction.MERGE, task.action);
    assertTrue(task.count <= (int) (memoryLimit / spillBatchBufferSize) - 1);
}
Also used : MergeTask(org.apache.drill.exec.physical.impl.xsort.managed.SortMemoryManager.MergeTask) FragmentContext(org.apache.drill.exec.ops.FragmentContext) OperatorFixture(org.apache.drill.test.OperatorFixture) OperatorTest(org.apache.drill.categories.OperatorTest) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

FragmentContext (org.apache.drill.exec.ops.FragmentContext)58 Test (org.junit.Test)43 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)40 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)39 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)39 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)35 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)21 SchemaPath (org.apache.drill.common.expression.SchemaPath)16 ExecTest (org.apache.drill.exec.ExecTest)16 OperatorTest (org.apache.drill.categories.OperatorTest)10 OperatorFixture (org.apache.drill.test.OperatorFixture)10 SubOperatorTest (org.apache.drill.test.SubOperatorTest)10 ValueVector (org.apache.drill.exec.vector.ValueVector)7 IntVector (org.apache.drill.exec.vector.IntVector)6 Ignore (org.junit.Ignore)6 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)5 BigIntVector (org.apache.drill.exec.vector.BigIntVector)5 NonStrictExpectations (mockit.NonStrictExpectations)4 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)4 DrillConfig (org.apache.drill.common.config.DrillConfig)3