Search in sources :

Example 6 with BasicQueryInfo

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

the class TestMemoryManager method testNoLeak.

private void testNoLeak(@Language("SQL") String query) throws Exception {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("task.verbose-stats", "true").buildOrThrow();
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
        executor.submit(() -> queryRunner.execute(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) BasicQueryInfo(io.trino.server.BasicQueryInfo) TestingTrinoServer(io.trino.server.testing.TestingTrinoServer)

Example 7 with BasicQueryInfo

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

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();
    DbResourceGroupConfigurationManager dbConfigurationManager = (DbResourceGroupConfigurationManager) 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(8, "reject-all-queries", "1MB", 0, 0, 0, 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(8, 200, "user.*", null, "(?i).*dashboard.*", null, null, null);
    // reload the configuration
    dbConfigurationManager.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 : DbResourceGroupConfigurationManager(io.trino.plugin.resourcegroups.db.DbResourceGroupConfigurationManager) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) TestQueues.createResourceGroupId(io.trino.execution.TestQueues.createResourceGroupId) DispatchManager(io.trino.dispatcher.DispatchManager) QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) Test(org.testng.annotations.Test)

Example 8 with BasicQueryInfo

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

the class QuerySystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    checkState(dispatchManager.isPresent(), "Query system table can return results only on coordinator");
    List<BasicQueryInfo> queries = dispatchManager.get().getQueries();
    queries = filterQueries(((FullConnectorSession) session).getSession().getIdentity(), queries, accessControl);
    Builder table = InMemoryRecordSet.builder(QUERY_TABLE);
    for (BasicQueryInfo queryInfo : queries) {
        Optional<QueryInfo> fullQueryInfo = dispatchManager.get().getFullQueryInfo(queryInfo.getQueryId());
        if (fullQueryInfo.isEmpty()) {
            continue;
        }
        QueryStats queryStats = fullQueryInfo.get().getQueryStats();
        table.addRow(queryInfo.getQueryId().toString(), queryInfo.getState().toString(), queryInfo.getSession().getUser(), queryInfo.getSession().getSource().orElse(null), queryInfo.getQuery(), queryInfo.getResourceGroupId().map(QuerySystemTable::resourceGroupIdToBlock).orElse(null), toMillis(queryStats.getQueuedTime()), toMillis(queryStats.getAnalysisTime()), toMillis(queryStats.getPlanningTime()), toTimestampWithTimeZoneMillis(queryStats.getCreateTime()), toTimestampWithTimeZoneMillis(queryStats.getExecutionStartTime()), toTimestampWithTimeZoneMillis(queryStats.getLastHeartbeat()), toTimestampWithTimeZoneMillis(queryStats.getEndTime()), Optional.ofNullable(queryInfo.getErrorType()).map(Enum::name).orElse(null), Optional.ofNullable(queryInfo.getErrorCode()).map(ErrorCode::getName).orElse(null));
    }
    return table.build().cursor();
}
Also used : QueryStats(io.trino.execution.QueryStats) BasicQueryInfo(io.trino.server.BasicQueryInfo) TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) BlockBuilder(io.trino.spi.block.BlockBuilder) ErrorCode(io.trino.spi.ErrorCode) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo)

Example 9 with BasicQueryInfo

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

the class FailedDispatchQueryFactory method createFailedDispatchQuery.

public FailedDispatchQuery createFailedDispatchQuery(Session session, String query, Optional<String> preparedQuery, Optional<ResourceGroupId> resourceGroup, Throwable throwable) {
    FailedDispatchQuery failedDispatchQuery = new FailedDispatchQuery(session, query, preparedQuery, locationFactory.createQueryLocation(session.getQueryId()), resourceGroup, throwable, executor);
    BasicQueryInfo queryInfo = failedDispatchQuery.getBasicQueryInfo();
    queryMonitor.queryCreatedEvent(queryInfo);
    queryMonitor.queryImmediateFailureEvent(queryInfo, toFailure(throwable));
    return failedDispatchQuery;
}
Also used : BasicQueryInfo(io.trino.server.BasicQueryInfo)

Example 10 with BasicQueryInfo

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

the class LocalDispatchQuery method getDispatchInfo.

@Override
public DispatchInfo getDispatchInfo() {
    // observe submitted before getting the state, to ensure a failed query stat is visible
    boolean dispatched = submitted.isDone();
    BasicQueryInfo queryInfo = stateMachine.getBasicQueryInfo(Optional.empty());
    if (queryInfo.getState() == QueryState.FAILED) {
        ExecutionFailureInfo failureInfo = stateMachine.getFailureInfo().orElseGet(() -> toFailure(new TrinoException(GENERIC_INTERNAL_ERROR, "Query failed for an unknown reason")));
        return DispatchInfo.failed(failureInfo, queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getQueuedTime());
    }
    if (dispatched) {
        return DispatchInfo.dispatched(new LocalCoordinatorLocation(), queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getQueuedTime());
    }
    return DispatchInfo.queued(queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getQueuedTime());
}
Also used : BasicQueryInfo(io.trino.server.BasicQueryInfo) TrinoException(io.trino.spi.TrinoException) ExecutionFailureInfo(io.trino.execution.ExecutionFailureInfo)

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