use of io.trino.spi.QueryId in project trino by trinodb.
the class TestMetadataManager method testMetadataIsClearedAfterQueryCanceled.
@Test
public void testMetadataIsClearedAfterQueryCanceled() throws Exception {
DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
QueryId queryId = dispatchManager.createQueryId();
dispatchManager.createQuery(queryId, Slug.createNew(), TestingSessionContext.fromSession(TEST_SESSION), "SELECT * FROM lineitem").get();
// wait until query starts running
while (true) {
BasicQueryInfo queryInfo = dispatchManager.getQueryInfo(queryId);
if (queryInfo.getState().isDone()) {
assertEquals(queryInfo.getState(), FAILED);
throw dispatchManager.getDispatchInfo(queryId).get().getFailureInfo().get().toException();
}
if (queryInfo.getState() == RUNNING) {
break;
}
Thread.sleep(100);
}
// cancel query
dispatchManager.cancelQuery(queryId);
assertEquals(metadataManager.getActiveQueryIds().size(), 0);
}
use of io.trino.spi.QueryId in project trino by trinodb.
the class TestMemoryManager method testOutOfMemoryKiller.
@Test(timeOut = 240_000, expectedExceptions = ExecutionException.class, expectedExceptionsMessageRegExp = ".*Query killed because the cluster is out of memory. Please try again in a few minutes.")
public void testOutOfMemoryKiller() throws Exception {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("query.low-memory-killer.delay", "5s").put("query.low-memory-killer.policy", "total-reservation").buildOrThrow();
try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
// Reserve all the memory
QueryId fakeQueryId = new QueryId("fake");
for (TestingTrinoServer server : queryRunner.getServers()) {
MemoryPool memoryPool = server.getLocalMemoryManager().getMemoryPool();
assertTrue(memoryPool.tryReserve(fakeQueryId, "test", memoryPool.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")));
}
// Wait for one of the queries to die
waitForQueryToBeKilled(queryRunner);
for (TestingTrinoServer server : queryRunner.getServers()) {
MemoryPool pool = server.getLocalMemoryManager().getMemoryPool();
assertTrue(pool.getReservedBytes() > 0);
// Free up the entire pool
pool.free(fakeQueryId, "test", pool.getMaxBytes());
assertTrue(pool.getFreeBytes() > 0);
}
for (Future<?> query : queryFutures) {
query.get();
}
}
}
use of io.trino.spi.QueryId in project trino by trinodb.
the class TestEnvironments method testEnvironment1.
@Test(timeOut = 240_000)
public void testEnvironment1() throws Exception {
String dbConfigUrl = getDbConfigUrl();
H2ResourceGroupsDao dao = getDao(dbConfigUrl);
try (DistributedQueryRunner runner = createQueryRunner(dbConfigUrl, dao, TEST_ENVIRONMENT)) {
QueryId firstQuery = createQuery(runner, adhocSession(), LONG_LASTING_QUERY);
waitForQueryState(runner, firstQuery, RUNNING);
QueryId secondQuery = createQuery(runner, adhocSession(), LONG_LASTING_QUERY);
waitForQueryState(runner, secondQuery, RUNNING);
}
}
use of io.trino.spi.QueryId in project trino by trinodb.
the class TestQueuesDb method testQueryTypeBasedSelection.
@Test
public void testQueryTypeBasedSelection() throws InterruptedException {
Session session = testSessionBuilder().setCatalog("tpch").setSchema("sf100000").build();
QueryId queryId = createQuery(queryRunner, session, "EXPLAIN " + LONG_LASTING_QUERY);
waitForQueryState(queryRunner, queryId, ImmutableSet.of(RUNNING, FINISHED));
Optional<ResourceGroupId> resourceGroupId = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(queryId).getResourceGroupId();
assertTrue(resourceGroupId.isPresent(), "Query should have a resource group");
assertEquals(resourceGroupId.get(), createResourceGroupId("explain"));
}
use of io.trino.spi.QueryId in project trino by trinodb.
the class TestQueuesDb method testRejection.
@Test(timeOut = 60_000)
public void testRejection() throws Exception {
InternalResourceGroupManager<?> manager = queryRunner.getCoordinator().getResourceGroupManager().get();
DbResourceGroupConfigurationManager dbConfigurationManager = (DbResourceGroupConfigurationManager) manager.getConfigurationManager();
// Verify the query cannot be submitted
QueryId queryId = createQuery(queryRunner, rejectingSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, queryId, FAILED);
DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
assertEquals(dispatchManager.getQueryInfo(queryId).getErrorCode(), QUERY_REJECTED.toErrorCode());
int selectorCount = getSelectors(queryRunner).size();
dao.insertSelector(4, 100_000, "user.*", null, "(?i).*reject.*", null, null, null);
dbConfigurationManager.load();
assertEquals(getSelectors(queryRunner).size(), selectorCount + 1);
// Verify the query can be submitted
queryId = createQuery(queryRunner, rejectingSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, queryId, RUNNING);
dao.deleteSelector(4, "user.*", "(?i).*reject.*", null);
dbConfigurationManager.load();
// Verify the query cannot be submitted
queryId = createQuery(queryRunner, rejectingSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, queryId, FAILED);
}
Aggregations