Search in sources :

Example 1 with DispatchManager

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

the class TestResourceGroupPerQueryLimitEnforcement method cancelAllQueriesAfterTest.

@AfterMethod
public void cancelAllQueriesAfterTest() {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    ImmutableList.copyOf(dispatchManager.getQueries()).forEach(queryInfo -> dispatchManager.cancelQuery(queryInfo.getQueryId()));
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager) AfterMethod(org.testng.annotations.AfterMethod)

Example 2 with DispatchManager

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

the class TestQueuesDb method testRejection.

@Test(timeOut = 60_000)
public void testRejection() throws Exception {
    InternalResourceGroupManager manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    ReloadingResourceGroupConfigurationManager reloadingConfigurationManager = (ReloadingResourceGroupConfigurationManager) manager.getConfigurationManager();
    // Verify the query cannot be submitted
    QueryId queryId = createQuery(queryRunner, rejectingSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, queryId, FAILED);
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    assertEquals(dispatchManager.getQueryInfo(queryId).getErrorCode(), QUERY_REJECTED.toErrorCode());
    int selectorCount = getSelectors(queryRunner).size();
    dao.insertSelector(4, 100_000, "user.*", "(?i).*reject.*", null, null, null);
    reloadingConfigurationManager.load();
    assertEquals(getSelectors(queryRunner).size(), selectorCount + 1);
    // Verify the query can be submitted
    queryId = createQuery(queryRunner, rejectingSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, queryId, RUNNING);
    dao.deleteSelector(4, "user.*", "(?i).*reject.*", null);
    reloadingConfigurationManager.load();
    // Verify the query cannot be submitted
    queryId = createQuery(queryRunner, rejectingSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, queryId, FAILED);
}
Also used : ReloadingResourceGroupConfigurationManager(com.facebook.presto.resourceGroups.reloading.ReloadingResourceGroupConfigurationManager) DispatchManager(com.facebook.presto.dispatcher.DispatchManager) QueryId(com.facebook.presto.spi.QueryId) InternalResourceGroupManager(com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager) Test(org.testng.annotations.Test)

Example 3 with DispatchManager

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

the class TestQueuesDb method testSelectorPriority.

@Test(timeOut = 60_000)
public void testSelectorPriority() throws Exception {
    InternalResourceGroupManager manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    ReloadingResourceGroupConfigurationManager reloadingConfigurationManager = (ReloadingResourceGroupConfigurationManager) manager.getConfigurationManager();
    QueryId firstQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstQuery, RUNNING);
    Optional<ResourceGroupId> resourceGroup = queryManager.getFullQueryInfo(firstQuery).getResourceGroupId();
    assertTrue(resourceGroup.isPresent());
    assertEquals(resourceGroup.get().toString(), "global.user-user.dashboard-user");
    // create a new resource group that rejects all queries submitted to it
    dao.insertResourceGroup(10, "reject-all-queries", "1MB", 0, 0, 0, null, null, null, null, null, null, null, null, 3L, TEST_ENVIRONMENT);
    // add a new selector that has a higher priority than the existing dashboard selector and that routes queries to the "reject-all-queries" resource group
    dao.insertSelector(10, 200, "user.*", "(?i).*dashboard.*", null, null, null);
    // reload the configuration
    reloadingConfigurationManager.load();
    QueryId secondQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, secondQuery, FAILED);
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    BasicQueryInfo basicQueryInfo = dispatchManager.getQueryInfo(secondQuery);
    assertEquals(basicQueryInfo.getErrorCode(), QUERY_QUEUE_FULL.toErrorCode());
}
Also used : ReloadingResourceGroupConfigurationManager(com.facebook.presto.resourceGroups.reloading.ReloadingResourceGroupConfigurationManager) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) TestQueues.createResourceGroupId(com.facebook.presto.execution.TestQueues.createResourceGroupId) DispatchManager(com.facebook.presto.dispatcher.DispatchManager) QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryManager(com.facebook.presto.execution.QueryManager) InternalResourceGroupManager(com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager) Test(org.testng.annotations.Test)

Example 4 with DispatchManager

use of com.facebook.presto.dispatcher.DispatchManager 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 5 with DispatchManager

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

the class TestQueryManager method cancelAllQueriesAfterTest.

@AfterMethod
public void cancelAllQueriesAfterTest() {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    ImmutableList.copyOf(dispatchManager.getQueries()).forEach(queryInfo -> dispatchManager.cancelQuery(queryInfo.getQueryId()));
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager) AfterMethod(org.testng.annotations.AfterMethod)

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