Search in sources :

Example 6 with DispatchManager

use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.

the class AbstractTestDistributedQueries method testQueryLoggingCount.

@Test
public void testQueryLoggingCount() {
    QueryManager queryManager = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getQueryManager();
    executeExclusively(() -> {
        assertUntilTimeout(() -> assertEquals(queryManager.getQueries().stream().map(BasicQueryInfo::getQueryId).map(queryManager::getFullQueryInfo).filter(info -> !info.isFinalQueryInfo()).collect(toList()), ImmutableList.of()), new Duration(1, MINUTES));
        // We cannot simply get the number of completed queries as soon as all the queries are completed, because this counter may not be up-to-date at that point.
        // The completed queries counter is updated in a final query info listener, which is called eventually.
        // Therefore, here we wait until the value of this counter gets stable.
        DispatchManager dispatchManager = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getDispatchManager();
        long beforeCompletedQueriesCount = waitUntilStable(() -> dispatchManager.getStats().getCompletedQueries().getTotalCount(), new Duration(5, SECONDS));
        long beforeSubmittedQueriesCount = dispatchManager.getStats().getSubmittedQueries().getTotalCount();
        assertUpdate("CREATE TABLE test_query_logging_count AS SELECT 1 foo_1, 2 foo_2_4", 1);
        assertQuery("SELECT foo_1, foo_2_4 FROM test_query_logging_count", "SELECT 1, 2");
        assertUpdate("DROP TABLE test_query_logging_count");
        assertQueryFails("SELECT * FROM test_query_logging_count", ".*Table .* does not exist");
        // TODO: Figure out a better way of synchronization
        assertUntilTimeout(() -> assertEquals(dispatchManager.getStats().getCompletedQueries().getTotalCount() - beforeCompletedQueriesCount, 4), new Duration(1, MINUTES));
        assertEquals(dispatchManager.getStats().getSubmittedQueries().getTotalCount() - beforeSubmittedQueriesCount, 4);
    });
}
Also used : TestingAccessControlManager.privilege(com.facebook.presto.testing.TestingAccessControlManager.privilege) SELECT_COLUMN(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.SELECT_COLUMN) QUERY_MAX_MEMORY(com.facebook.presto.SystemSessionProperties.QUERY_MAX_MEMORY) MaterializedResult.resultBuilder(com.facebook.presto.testing.MaterializedResult.resultBuilder) Test(org.testng.annotations.Test) Thread.currentThread(java.lang.Thread.currentThread) Duration(io.airlift.units.Duration) Duration.nanosSince(io.airlift.units.Duration.nanosSince) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) CREATE_VIEW(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.CREATE_VIEW) Collections.nCopies(java.util.Collections.nCopies) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Uninterruptibles.sleepUninterruptibly(com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly) String.format(java.lang.String.format) SET_USER(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.SET_USER) Assertions(com.facebook.airlift.testing.Assertions) QueryInfo(com.facebook.presto.execution.QueryInfo) TESTING_CATALOG(com.facebook.presto.testing.TestingSession.TESTING_CATALOG) Optional(java.util.Optional) SystemSessionProperties(com.facebook.presto.SystemSessionProperties) Joiner(com.google.common.base.Joiner) CREATE_VIEW_WITH_SELECT_COLUMNS(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.CREATE_VIEW_WITH_SELECT_COLUMNS) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) MINUTES(java.util.concurrent.TimeUnit.MINUTES) QueryManager(com.facebook.presto.execution.QueryManager) Supplier(java.util.function.Supplier) TestingSession(com.facebook.presto.testing.TestingSession) INFORMATION_SCHEMA(com.facebook.presto.connector.informationSchema.InformationSchemaMetadata.INFORMATION_SCHEMA) ImmutableList(com.google.common.collect.ImmutableList) QueryAssertions.assertContains(com.facebook.presto.tests.QueryAssertions.assertContains) Identity(com.facebook.presto.spi.security.Identity) DROP_COLUMN(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.DROP_COLUMN) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) ADD_COLUMN(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.ADD_COLUMN) RENAME_TABLE(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.RENAME_TABLE) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) DispatchManager(com.facebook.presto.dispatcher.DispatchManager) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Collectors.toList(java.util.stream.Collectors.toList) CREATE_TABLE(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.CREATE_TABLE) MaterializedRow(com.facebook.presto.testing.MaterializedRow) RENAME_COLUMN(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.RENAME_COLUMN) Assert.assertTrue(org.testng.Assert.assertTrue) DROP_TABLE(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.DROP_TABLE) SECONDS(java.util.concurrent.TimeUnit.SECONDS) SET_SESSION(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.SET_SESSION) DispatchManager(com.facebook.presto.dispatcher.DispatchManager) QueryManager(com.facebook.presto.execution.QueryManager) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 7 with DispatchManager

use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.

the class TestQueryRunnerUtil method createQuery.

public static QueryId createQuery(DistributedQueryRunner queryRunner, int coordinator, Session session, String sql) {
    DispatchManager dispatchManager = queryRunner.getCoordinator(coordinator).getDispatchManager();
    getFutureValue(dispatchManager.createQuery(session.getQueryId(), "slug", 0, new TestingSessionContext(session), sql));
    return session.getQueryId();
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager)

Example 8 with DispatchManager

use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.

the class TestQueryRunnerUtil method waitForQueryState.

public static void waitForQueryState(DistributedQueryRunner queryRunner, int coordinator, QueryId queryId, Set<QueryState> expectedQueryStates) throws InterruptedException {
    DispatchManager dispatchManager = queryRunner.getCoordinator(coordinator).getDispatchManager();
    waitForQueryState(dispatchManager, queryId, expectedQueryStates);
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager)

Example 9 with DispatchManager

use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.

the class TestMetadataManager method testMetadataIsClearedAfterQueryCanceled.

@Test
public void testMetadataIsClearedAfterQueryCanceled() throws Exception {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    QueryId queryId = dispatchManager.createQueryId();
    dispatchManager.createQuery(queryId, "slug", 0, new TestingSessionContext(TEST_SESSION), "SELECT * FROM lineitem").get();
    // wait until query starts running
    while (true) {
        BasicQueryInfo queryInfo = dispatchManager.getQueryInfo(queryId);
        if (queryInfo.getState().isDone()) {
            assertEquals(queryInfo.getState(), FAILED);
            throw dispatchManager.getDispatchInfo(queryId).get().getFailureInfo().get().toException();
        }
        if (queryInfo.getState() == RUNNING) {
            break;
        }
        Thread.sleep(100);
    }
    // cancel query
    dispatchManager.cancelQuery(queryId);
    assertEquals(metadataManager.getCatalogsByQueryId().size(), 0);
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager) TestingSessionContext(com.facebook.presto.execution.TestingSessionContext) QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) Test(org.testng.annotations.Test)

Example 10 with DispatchManager

use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.

the class TestQueryManager method testFailQueryPrerun.

@Test(timeOut = 60_000L)
public void testFailQueryPrerun() throws Exception {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    // Create 3 running queries to guarantee queueing
    createQueries(dispatchManager, 3);
    QueryId queryId = dispatchManager.createQueryId();
    dispatchManager.createQuery(queryId, "slug", 0, new TestingSessionContext(TEST_SESSION), "SELECT * FROM lineitem").get();
    assertNotEquals(dispatchManager.getStats().getQueuedQueries(), 0L, "Expected 0 queued queries, found: " + dispatchManager.getStats().getQueuedQueries());
    // wait until it's admitted but fail it before it starts
    while (true) {
        QueryState state = dispatchManager.getQueryInfo(queryId).getState();
        if (state.ordinal() >= RUNNING.ordinal()) {
            fail("unexpected query state: " + state);
        }
        if (state.ordinal() >= QUEUED.ordinal()) {
            // cancel query
            dispatchManager.failQuery(queryId, new PrestoException(GENERIC_USER_ERROR, "mock exception"));
            break;
        }
    }
    QueryState state = dispatchManager.getQueryInfo(queryId).getState();
    assertEquals(state, FAILED);
    // Give the stats a time to update
    Thread.sleep(1000);
    assertEquals(queryManager.getStats().getQueuedQueries(), 0);
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager) TestingSessionContext(com.facebook.presto.execution.TestingSessionContext) QueryId(com.facebook.presto.spi.QueryId) QueryManager(com.facebook.presto.execution.QueryManager) PrestoException(com.facebook.presto.spi.PrestoException) TestQueryRunnerUtil.waitForQueryState(com.facebook.presto.execution.TestQueryRunnerUtil.waitForQueryState) QueryState(com.facebook.presto.execution.QueryState) Test(org.testng.annotations.Test)

Aggregations

DispatchManager (com.facebook.presto.dispatcher.DispatchManager)12 QueryId (com.facebook.presto.spi.QueryId)7 Test (org.testng.annotations.Test)7 QueryManager (com.facebook.presto.execution.QueryManager)5 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 TestingSessionContext (com.facebook.presto.execution.TestingSessionContext)3 InternalResourceGroupManager (com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager)3 ReloadingResourceGroupConfigurationManager (com.facebook.presto.resourceGroups.reloading.ReloadingResourceGroupConfigurationManager)3 QueryInfo (com.facebook.presto.execution.QueryInfo)2 QueryState (com.facebook.presto.execution.QueryState)2 TestQueryRunnerUtil.waitForQueryState (com.facebook.presto.execution.TestQueryRunnerUtil.waitForQueryState)2 PrestoException (com.facebook.presto.spi.PrestoException)2 AfterMethod (org.testng.annotations.AfterMethod)2 Assertions (com.facebook.airlift.testing.Assertions)1 Session (com.facebook.presto.Session)1 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)1 QUERY_MAX_MEMORY (com.facebook.presto.SystemSessionProperties.QUERY_MAX_MEMORY)1 VARCHAR (com.facebook.presto.common.type.VarcharType.VARCHAR)1 INFORMATION_SCHEMA (com.facebook.presto.connector.informationSchema.InformationSchemaMetadata.INFORMATION_SCHEMA)1 TestQueues.createResourceGroupId (com.facebook.presto.execution.TestQueues.createResourceGroupId)1