Search in sources :

Example 6 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestQueuesDb method testNonLeafGroup.

@Test
public void testNonLeafGroup() throws Exception {
    Session session = testSessionBuilder().setCatalog("tpch").setSchema("sf100000").setSource("non-leaf").build();
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    InternalResourceGroupManager manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    ReloadingResourceGroupConfigurationManager reloadingConfigurationManager = (ReloadingResourceGroupConfigurationManager) manager.getConfigurationManager();
    int originalSize = getSelectors(queryRunner).size();
    // Add a selector for a non leaf group
    dao.insertSelector(3, 100, "user.*", "(?i).*non-leaf.*", null, null, null);
    reloadingConfigurationManager.load();
    while (getSelectors(queryRunner).size() != originalSize + 1) {
        MILLISECONDS.sleep(500);
    }
    // Submit query with side effect of creating resource groups
    QueryId firstDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
    cancelQuery(queryRunner, firstDashboardQuery);
    waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
    // Submit a query to a non-leaf resource group
    QueryId invalidResourceGroupQuery = createQuery(queryRunner, session, LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, invalidResourceGroupQuery, FAILED);
    assertEquals(queryRunner.getCoordinator().getDispatchManager().getQueryInfo(invalidResourceGroupQuery).getErrorCode(), INVALID_RESOURCE_GROUP.toErrorCode());
}
Also used : ReloadingResourceGroupConfigurationManager(com.facebook.presto.resourceGroups.reloading.ReloadingResourceGroupConfigurationManager) QueryId(com.facebook.presto.spi.QueryId) QueryManager(com.facebook.presto.execution.QueryManager) InternalResourceGroupManager(com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager) H2TestUtil.adhocSession(com.facebook.presto.execution.resourceGroups.db.H2TestUtil.adhocSession) H2TestUtil.dashboardSession(com.facebook.presto.execution.resourceGroups.db.H2TestUtil.dashboardSession) H2TestUtil.rejectingSession(com.facebook.presto.execution.resourceGroups.db.H2TestUtil.rejectingSession) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 7 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestQueryManager method testFailQuery.

@Test(timeOut = 60_000L)
public void testFailQuery() 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) {
        QueryState state = dispatchManager.getQueryInfo(queryId).getState();
        if (state.isDone()) {
            fail("unexpected query state: " + state);
        }
        if (state == RUNNING) {
            break;
        }
        Thread.sleep(100);
    }
    // cancel query
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    queryManager.failQuery(queryId, new PrestoException(GENERIC_INTERNAL_ERROR, "mock exception"));
    QueryInfo queryInfo = queryManager.getFullQueryInfo(queryId);
    assertEquals(queryInfo.getState(), FAILED);
    assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
    assertNotNull(queryInfo.getFailureInfo());
    assertEquals(queryInfo.getFailureInfo().getMessage(), "mock exception");
    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) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryInfo(com.facebook.presto.execution.QueryInfo) Test(org.testng.annotations.Test)

Example 8 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestQueryManager method testQueryScanExceeded.

@Test(timeOut = 60_000L)
public void testQueryScanExceeded() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().setSingleExtraProperty("query.max-scan-raw-input-bytes", "0B").build()) {
        QueryId queryId = createQuery(queryRunner, TEST_SESSION, "SELECT COUNT(*) FROM lineitem");
        waitForQueryState(queryRunner, queryId, FAILED);
        QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
        BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
        assertEquals(queryInfo.getState(), FAILED);
        assertEquals(queryInfo.getErrorCode(), EXCEEDED_SCAN_RAW_BYTES_READ_LIMIT.toErrorCode());
    }
}
Also used : QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryManager(com.facebook.presto.execution.QueryManager) Test(org.testng.annotations.Test)

Example 9 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestQueryManager method testQueryOutputSizeExceeded.

@Test(timeOut = 60_000L)
public void testQueryOutputSizeExceeded() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().setSingleExtraProperty("query.max-output-size", "1B").build()) {
        QueryId queryId = createQuery(queryRunner, TEST_SESSION, "SELECT COUNT(*) FROM lineitem");
        waitForQueryState(queryRunner, queryId, FAILED);
        QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
        BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
        assertEquals(queryInfo.getState(), FAILED);
        assertEquals(queryInfo.getErrorCode(), EXCEEDED_OUTPUT_SIZE_LIMIT.toErrorCode());
    }
}
Also used : QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryManager(com.facebook.presto.execution.QueryManager) Test(org.testng.annotations.Test)

Example 10 with QueryManager

use of com.facebook.presto.execution.QueryManager 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)

Aggregations

QueryManager (com.facebook.presto.execution.QueryManager)16 QueryId (com.facebook.presto.spi.QueryId)15 Test (org.testng.annotations.Test)15 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)10 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)5 Session (com.facebook.presto.Session)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 TestingSessionContext (com.facebook.presto.execution.TestingSessionContext)2 H2ResourceGroupsDao (com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)2 PrestoException (com.facebook.presto.spi.PrestoException)2 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 Threads.threadsNamed (com.facebook.airlift.concurrent.Threads.threadsNamed)1 Logger (com.facebook.airlift.log.Logger)1 Assertions (com.facebook.airlift.testing.Assertions)1 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)1