Search in sources :

Example 11 with BasicQueryInfo

use of io.trino.server.BasicQueryInfo in project trino by trinodb.

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(io.trino.server.BasicQueryInfo) DateTime(org.joda.time.DateTime)

Example 12 with BasicQueryInfo

use of io.trino.server.BasicQueryInfo in project trino by trinodb.

the class UiQueryResource method failQuery.

private Response failQuery(QueryId queryId, TrinoException queryException, HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
    requireNonNull(queryId, "queryId is null");
    try {
        BasicQueryInfo queryInfo = dispatchManager.getQueryInfo(queryId);
        checkCanKillQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queryInfo.getSession().toIdentity(), accessControl);
        // check before killing to provide the proper error code (this is racy)
        if (queryInfo.getState().isDone()) {
            return Response.status(Status.CONFLICT).build();
        }
        dispatchManager.failQuery(queryId, queryException);
        return Response.status(Status.ACCEPTED).build();
    } catch (AccessDeniedException e) {
        throw new ForbiddenException();
    } catch (NoSuchElementException e) {
        return Response.status(Status.GONE).build();
    }
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) BasicQueryInfo(io.trino.server.BasicQueryInfo) NoSuchElementException(java.util.NoSuchElementException)

Example 13 with BasicQueryInfo

use of io.trino.server.BasicQueryInfo in project trino by trinodb.

the class TestMemoryManager method testClusterPools.

@Test(timeOut = 240_000)
public void testClusterPools() throws Exception {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("task.verbose-stats", "true").buildOrThrow();
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
        // Reserve all the memory
        QueryId fakeQueryId = new QueryId("fake");
        for (TestingTrinoServer server : queryRunner.getServers()) {
            MemoryPool pool = server.getLocalMemoryManager().getMemoryPool();
            assertTrue(pool.tryReserve(fakeQueryId, "test", pool.getMaxBytes()));
        }
        List<Future<?>> queryFutures = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            queryFutures.add(executor.submit(() -> queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk")));
        }
        ClusterMemoryManager memoryManager = queryRunner.getCoordinator().getClusterMemoryManager();
        ClusterMemoryPool clusterPool = memoryManager.getPool();
        assertNotNull(clusterPool);
        // Wait for the pools to become blocked
        while (clusterPool.getBlockedNodes() != 2) {
            MILLISECONDS.sleep(10);
        }
        // Ger query infos for both queries
        List<BasicQueryInfo> currentQueryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        while (currentQueryInfos.size() != 2) {
            MILLISECONDS.sleep(10);
            currentQueryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        }
        // Make sure the queries are blocked
        for (BasicQueryInfo info : currentQueryInfos) {
            assertFalse(info.getState().isDone());
        }
        while (!currentQueryInfos.stream().allMatch(TestMemoryManager::isBlockedWaitingForMemory)) {
            MILLISECONDS.sleep(10);
            currentQueryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
            for (BasicQueryInfo info : currentQueryInfos) {
                assertFalse(info.getState().isDone());
            }
        }
        // Release the memory in the memory pool
        for (TestingTrinoServer server : queryRunner.getServers()) {
            MemoryPool pool = server.getLocalMemoryManager().getMemoryPool();
            // Free up the entire pool
            pool.free(fakeQueryId, "test", pool.getMaxBytes());
            assertTrue(pool.getFreeBytes() > 0);
        }
        // Make sure both queries finish now that there's memory free in the memory pool.
        for (Future<?> query : queryFutures) {
            query.get();
        }
        for (BasicQueryInfo info : queryRunner.getCoordinator().getQueryManager().getQueries()) {
            assertEquals(info.getState(), FINISHED);
        }
        // Make sure we didn't leak any memory on the workers
        for (TestingTrinoServer worker : queryRunner.getServers()) {
            MemoryPool pool = worker.getLocalMemoryManager().getMemoryPool();
            assertEquals(pool.getMaxBytes(), pool.getFreeBytes());
        }
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) TestingTrinoServer(io.trino.server.testing.TestingTrinoServer) Test(org.testng.annotations.Test)

Example 14 with BasicQueryInfo

use of io.trino.server.BasicQueryInfo in project trino by trinodb.

the class TestMemoryManager method waitForQueryToBeKilled.

private void waitForQueryToBeKilled(DistributedQueryRunner queryRunner) throws InterruptedException {
    while (true) {
        for (BasicQueryInfo info : queryRunner.getCoordinator().getQueryManager().getQueries()) {
            if (info.getState().isDone()) {
                assertNotNull(info.getErrorCode());
                assertEquals(info.getErrorCode(), CLUSTER_OUT_OF_MEMORY.toErrorCode());
                return;
            }
        }
        MILLISECONDS.sleep(10);
    }
}
Also used : BasicQueryInfo(io.trino.server.BasicQueryInfo)

Example 15 with BasicQueryInfo

use of io.trino.server.BasicQueryInfo in project trino by trinodb.

the class AbstractDistributedEngineOnlyQueries method testQueryTransitionsToRunningState.

@Test(timeOut = 10_000)
public void testQueryTransitionsToRunningState() {
    String query = format(// use random marker in query for unique matching below
    "SELECT count(*) c_%s FROM lineitem CROSS JOIN lineitem CROSS JOIN lineitem", randomTableSuffix());
    DistributedQueryRunner queryRunner = getDistributedQueryRunner();
    ListenableFuture<?> queryFuture = Futures.submit(() -> queryRunner.execute(getSession(), query), executorService);
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    assertEventually(() -> {
        List<BasicQueryInfo> queryInfos = queryManager.getQueries().stream().filter(q -> q.getQuery().equals(query)).collect(toImmutableList());
        assertThat(queryInfos).hasSize(1);
        assertThat(queryInfos.get(0).getState()).isEqualTo(RUNNING);
        // we are good. Let's kill the query
        queryManager.cancelQuery(queryInfos.get(0).getQueryId());
    });
    assertThatThrownBy(queryFuture::get).hasMessageContaining("Query was canceled");
}
Also used : AfterClass(org.testng.annotations.AfterClass) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Language(org.intellij.lang.annotations.Language) QueryManager(io.trino.execution.QueryManager) BasicQueryInfo(io.trino.server.BasicQueryInfo) BeforeClass(org.testng.annotations.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RUNNING(io.trino.execution.QueryState.RUNNING) Test(org.testng.annotations.Test) String.format(java.lang.String.format) BROADCAST(io.trino.sql.planner.OptimizerConfig.JoinDistributionType.BROADCAST) ENABLE_DYNAMIC_FILTERING(io.trino.SystemSessionProperties.ENABLE_DYNAMIC_FILTERING) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Assert.assertEventually(io.trino.testing.assertions.Assert.assertEventually) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Pattern(java.util.regex.Pattern) ExecutorService(java.util.concurrent.ExecutorService) TestTable.randomTableSuffix(io.trino.testing.sql.TestTable.randomTableSuffix) Session(io.trino.Session) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) Test(org.testng.annotations.Test)

Aggregations

BasicQueryInfo (io.trino.server.BasicQueryInfo)20 Test (org.testng.annotations.Test)10 QueryId (io.trino.spi.QueryId)7 QueryManager (io.trino.execution.QueryManager)6 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)5 DispatchManager (io.trino.dispatcher.DispatchManager)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 Session (io.trino.Session)3 TestingTrinoServer (io.trino.server.testing.TestingTrinoServer)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 QueryState (io.trino.execution.QueryState)2 ResourceSecurity (io.trino.server.security.ResourceSecurity)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 SECONDS (java.util.concurrent.TimeUnit.SECONDS)2 GET (javax.ws.rs.GET)2