Search in sources :

Example 11 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class TestBrutalShutdown method testRetryCircuitBreaker.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS)
public void testRetryCircuitBreaker() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(ImmutableMap.of("global-query-retry-failure-limit", "2"))) {
        queryRetryOnShutdown(TINY_SESSION, queryRunner, executor, 10);
        int totalSuccessfulRetryQueries = 0;
        List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        for (BasicQueryInfo info : queryInfos) {
            if (info.getQuery().contains("-- retry query")) {
                assertEquals(info.getState(), FINISHED);
                totalSuccessfulRetryQueries++;
            }
        }
        assertLessThanOrEqual(totalSuccessfulRetryQueries, 2);
    }
}
Also used : BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) Test(org.testng.annotations.Test)

Example 12 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo 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 13 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class ClusterMemoryLeakDetector method isLeaked.

private static boolean isLeaked(Map<QueryId, BasicQueryInfo> queryIdToInfo, QueryId queryId) {
    BasicQueryInfo queryInfo = queryIdToInfo.get(queryId);
    if (queryInfo == null) {
        return true;
    }
    DateTime queryEndTime = queryInfo.getQueryStats().getEndTime();
    if (queryInfo.getState() == RUNNING || queryEndTime == null) {
        return false;
    }
    return secondsBetween(queryEndTime, now()).getSeconds() >= DEFAULT_LEAK_CLAIM_DELTA_SEC;
}
Also used : BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) DateTime(org.joda.time.DateTime)

Example 14 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class TestQueryInterceptor method testMultiplePostPreprocess.

@Test
public void testMultiplePostPreprocess() throws Exception {
    String extra = "queryInterceptors=" + TestPostProcess1QueryInterceptor.class.getName() + ";" + TestPostProcess1QueryInterceptor.class.getName();
    try (Connection connection = createConnection(extra)) {
        try (Statement statement = connection.createStatement()) {
            try (ResultSet ignored = statement.executeQuery("select * from tpch.sf1000.orders")) {
                assertEquals(qm.getQueries().size(), 3);
            }
        }
    }
    // Add sleep because deletes are sent async
    Thread.sleep(1000);
    List<BasicQueryInfo> queries = qm.getQueries();
    assertEquals(queries.stream().filter(query -> query.getState() == QueryState.FAILED).count(), 3);
}
Also used : Statement(java.sql.Statement) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.testng.annotations.Test)

Example 15 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class TestQueryInterceptor method testBasicPostPreprocess.

@Test
public void testBasicPostPreprocess() throws Exception {
    String extra = "queryInterceptors=" + TestPostProcess1QueryInterceptor.class.getName();
    try (Connection connection = createConnection(extra)) {
        try (Statement statement = connection.createStatement()) {
            try (ResultSet ignored = statement.executeQuery("select * from tpch.sf1000.orders")) {
                assertEquals(qm.getQueries().size(), 2);
            }
        }
    }
    // Add sleep because deletes are sent async
    Thread.sleep(1000);
    List<BasicQueryInfo> queries = qm.getQueries();
    assertEquals(queries.stream().filter(query -> query.getState() == QueryState.FAILED).count(), 2);
}
Also used : Statement(java.sql.Statement) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.testng.annotations.Test)

Aggregations

BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)32 Test (org.testng.annotations.Test)19 QueryId (com.facebook.presto.spi.QueryId)12 QueryManager (com.facebook.presto.execution.QueryManager)9 TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)4 Session (com.facebook.presto.Session)3 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)3 ExecutionFailureInfo (com.facebook.presto.execution.ExecutionFailureInfo)3 QueryInfo (com.facebook.presto.execution.QueryInfo)3 PrestoException (com.facebook.presto.spi.PrestoException)3 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)3 ImmutableList (com.google.common.collect.ImmutableList)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Assertions (com.facebook.airlift.testing.Assertions)1 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)1 QUERY_MAX_MEMORY (com.facebook.presto.SystemSessionProperties.QUERY_MAX_MEMORY)1