Search in sources :

Example 51 with Drillbit

use of org.apache.drill.exec.server.Drillbit in project drill by apache.

the class TestPauseInjection method timedPauseOnSpecificBit.

@Test
public void timedPauseOnSpecificBit() {
    final RemoteServiceSet remoteServiceSet = RemoteServiceSet.getLocalServiceSet();
    final ZookeeperHelper zkHelper = new ZookeeperHelper();
    zkHelper.startZookeeper(1);
    final long pauseDuration = 2000L;
    final long expectedDuration = pauseDuration;
    try {
        // Creating two drillbits
        final Drillbit drillbit1, drillbit2;
        final DrillConfig drillConfig = zkHelper.getConfig();
        try {
            drillbit1 = Drillbit.start(drillConfig, remoteServiceSet);
            drillbit2 = Drillbit.start(drillConfig, remoteServiceSet);
        } catch (final DrillbitStartupException e) {
            throw new RuntimeException("Failed to start two drillbits.", e);
        }
        final DrillbitContext drillbitContext1 = drillbit1.getContext();
        final DrillbitContext drillbitContext2 = drillbit2.getContext();
        final UserSession session = UserSession.Builder.newBuilder().withCredentials(UserCredentials.newBuilder().setUserName("foo").build()).withUserProperties(UserProperties.getDefaultInstance()).withOptionManager(drillbitContext1.getOptionManager()).build();
        final DrillbitEndpoint drillbitEndpoint1 = drillbitContext1.getEndpoint();
        final String controls = Controls.newBuilder().addTimedPauseOnBit(DummyClass.class, DummyClass.PAUSES, drillbitEndpoint1, 0, pauseDuration).build();
        ControlsInjectionUtil.setControls(session, controls);
        {
            final ExtendedLatch trigger = new ExtendedLatch(1);
            final Pointer<Exception> ex = new Pointer<>();
            final QueryContext queryContext = new QueryContext(session, drillbitContext1, QueryId.getDefaultInstance());
            // test that the pause happens
            final DummyClass dummyClass = new DummyClass(queryContext, trigger);
            final long actualDuration = dummyClass.pauses();
            assertTrue(String.format("Test should stop for at least %d milliseconds.", expectedDuration), expectedDuration <= actualDuration);
            assertNull("No exception should be thrown.", ex.value);
            try {
                queryContext.close();
            } catch (final Exception e) {
                fail("Failed to close query context: " + e);
            }
        }
        {
            final ExtendedLatch trigger = new ExtendedLatch(1);
            final QueryContext queryContext = new QueryContext(session, drillbitContext2, QueryId.getDefaultInstance());
            // if the resume did not happen, the test would hang
            final DummyClass dummyClass = new DummyClass(queryContext, trigger);
            dummyClass.pauses();
            try {
                queryContext.close();
            } catch (final Exception e) {
                fail("Failed to close query context: " + e);
            }
        }
    } finally {
        zkHelper.stopZookeeper();
    }
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) ZookeeperHelper(org.apache.drill.exec.ZookeeperHelper) Pointer(org.apache.drill.exec.util.Pointer) QueryContext(org.apache.drill.exec.ops.QueryContext) DrillbitStartupException(org.apache.drill.exec.exception.DrillbitStartupException) ExtendedLatch(org.apache.drill.common.concurrent.ExtendedLatch) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillConfig(org.apache.drill.common.config.DrillConfig) DrillbitStartupException(org.apache.drill.exec.exception.DrillbitStartupException) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) UserSession(org.apache.drill.exec.rpc.user.UserSession) Test(org.junit.Test)

Example 52 with Drillbit

use of org.apache.drill.exec.server.Drillbit in project drill by apache.

the class TestGracefulShutdown method testDrillbitWithSamePortContainsShutdownThread.

// DRILL-6912
@Test
public void testDrillbitWithSamePortContainsShutdownThread() throws Exception {
    ClusterFixtureBuilder fixtureBuilder = ClusterFixture.builder(dirTestWatcher).withLocalZk().configProperty(ExecConstants.ALLOW_LOOPBACK_ADDRESS_BINDING, true).configProperty(ExecConstants.INITIAL_USER_PORT, QueryTestUtil.getFreePortNumber(31170, 300)).configProperty(ExecConstants.INITIAL_BIT_PORT, QueryTestUtil.getFreePortNumber(31180, 300));
    try (ClusterFixture fixture = fixtureBuilder.build();
        Drillbit drillbitWithSamePort = new Drillbit(fixture.config(), fixtureBuilder.configBuilder().getDefinitions(), fixture.serviceSet())) {
        // Assert preconditions :
        // 1. First drillbit instance should be started normally
        // 2. Second instance startup should fail, because ports are occupied by the first one
        assertNotNull("First drillbit instance should be initialized", fixture.drillbit());
        try {
            drillbitWithSamePort.run();
            fail("Invocation of 'drillbitWithSamePort.run()' should throw UserException");
        } catch (UserException e) {
            assertThat(e.getMessage(), containsString("RESOURCE ERROR: Drillbit could not bind to port"));
            // Ensure that drillbit with failed startup may be safely closed
            assertNotNull("Drillbit.gracefulShutdownThread shouldn't be null, otherwise close() may throw NPE (if so, check suppressed exception).", drillbitWithSamePort.getGracefulShutdownThread());
        }
    }
}
Also used : Drillbit(org.apache.drill.exec.server.Drillbit) UserException(org.apache.drill.common.exceptions.UserException) SlowTest(org.apache.drill.categories.SlowTest) Test(org.junit.Test)

Example 53 with Drillbit

use of org.apache.drill.exec.server.Drillbit in project drill by apache.

the class TestGracefulShutdown method testOnlineEndPoints.

/*
  Start multiple drillbits and then shutdown a drillbit. Query the online
  endpoints and check if the drillbit still exists.
   */
@Test
public void testOnlineEndPoints() throws Exception {
    String[] drillbits = { "db1", "db2", "db3" };
    ClusterFixtureBuilder builder = builderWithEnabledPortHunting().withLocalZk().withBits(drillbits);
    try (ClusterFixture cluster = builder.build()) {
        Drillbit drillbit = cluster.drillbit("db2");
        int zkRefresh = drillbit.getContext().getConfig().getInt(ExecConstants.ZK_REFRESH);
        DrillbitEndpoint drillbitEndpoint = drillbit.getRegistrationHandle().getEndPoint();
        cluster.closeDrillbit("db2");
        while (true) {
            Collection<DrillbitEndpoint> drillbitEndpoints = cluster.drillbit().getContext().getClusterCoordinator().getOnlineEndPoints();
            if (!drillbitEndpoints.contains(drillbitEndpoint)) {
                // Success
                return;
            }
            Thread.sleep(zkRefresh);
        }
    }
}
Also used : DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) Drillbit(org.apache.drill.exec.server.Drillbit) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) SlowTest(org.apache.drill.categories.SlowTest) Test(org.junit.Test)

Example 54 with Drillbit

use of org.apache.drill.exec.server.Drillbit in project drill by apache.

the class TestHashJoin method hjWithExchange1.

@Test
public void hjWithExchange1() throws Throwable {
    // Another test for hash join with exchanges
    try (final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
        final Drillbit bit = new Drillbit(CONFIG, serviceSet);
        final DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        // run query.
        bit.run();
        client.connect();
        final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.asCharSource(DrillFileUtils.getResourceAsFile("/join/hj_exchanges1.json"), Charsets.UTF_8).read());
        int count = 0;
        for (final QueryDataBatch b : results) {
            if (b.getHeader().getRowCount() != 0) {
                count += b.getHeader().getRowCount();
            }
            b.release();
        }
        assertEquals(272, count);
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) DrillClient(org.apache.drill.exec.client.DrillClient) SlowTest(org.apache.drill.categories.SlowTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 55 with Drillbit

use of org.apache.drill.exec.server.Drillbit in project drill by apache.

the class TestHashJoin method testHashJoinExprInCondition.

@Test
public void testHashJoinExprInCondition() throws Exception {
    final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
    try (final Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
        final DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        bit1.run();
        client.connect();
        final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.asCharSource(DrillFileUtils.getResourceAsFile("/join/hashJoinExpr.json"), Charsets.UTF_8).read());
        int count = 0;
        for (final QueryDataBatch b : results) {
            if (b.getHeader().getRowCount() != 0) {
                count += b.getHeader().getRowCount();
            }
            b.release();
        }
        assertEquals(10, count);
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) DrillClient(org.apache.drill.exec.client.DrillClient) SlowTest(org.apache.drill.categories.SlowTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

Drillbit (org.apache.drill.exec.server.Drillbit)158 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)132 Test (org.junit.Test)129 DrillClient (org.apache.drill.exec.client.DrillClient)119 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)119 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)79 SlowTest (org.apache.drill.categories.SlowTest)74 ValueVector (org.apache.drill.exec.vector.ValueVector)66 OperatorTest (org.apache.drill.categories.OperatorTest)47 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)28 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)24 DrillConfig (org.apache.drill.common.config.DrillConfig)20 ExecTest (org.apache.drill.exec.ExecTest)13 VectorTest (org.apache.drill.categories.VectorTest)12 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)11 QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)10 StoragePluginRegistry (org.apache.drill.exec.store.StoragePluginRegistry)8 VarBinaryVector (org.apache.drill.exec.vector.VarBinaryVector)7 IOException (java.io.IOException)6 ZookeeperHelper (org.apache.drill.exec.ZookeeperHelper)6