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());
}
}
}
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());
}
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();
}
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;
}
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());
}
Aggregations