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