use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class TestQueues method testTooManyQueries.
@Test(timeOut = 240_000)
public void testTooManyQueries() throws Exception {
String dbConfigUrl = getDbConfigUrl();
H2ResourceGroupsDao dao = getDao(dbConfigUrl);
try (DistributedQueryRunner queryRunner = createQueryRunner(dbConfigUrl, dao)) {
QueryId firstDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
QueryId secondDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
QueryId thirdDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, thirdDashboardQuery, FAILED);
// Allow one more query to run and resubmit third query
dao.updateResourceGroup(3, "user-${USER}", "1MB", 3, 4, null, null, null, null, null, 1L);
dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 2, null, null, null, null, null, 3L);
waitForQueryState(queryRunner, secondDashboardQuery, RUNNING);
thirdDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
// Lower running queries in dashboard resource groups and wait until groups are reconfigured
dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 1, null, null, null, null, null, 3L);
ResourceGroupManager manager = queryRunner.getCoordinator().getResourceGroupManager().get();
do {
MILLISECONDS.sleep(500);
} while (manager.getResourceGroupInfo(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("global"), "user-user"), "dashboard-user")).getMaxRunningQueries() != 1);
// Cancel query and verify that third query is still queued
cancelQuery(queryRunner, firstDashboardQuery);
waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
MILLISECONDS.sleep(2000);
waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
}
}
use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class TestQueues method testRejection.
@Test(timeOut = 240_000)
public void testRejection() throws Exception {
String dbConfigUrl = getDbConfigUrl();
H2ResourceGroupsDao dao = getDao(dbConfigUrl);
try (DistributedQueryRunner queryRunner = createQueryRunner(dbConfigUrl, dao)) {
// Verify the query cannot be submitted
QueryId queryId = createQuery(queryRunner, newRejectionSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, queryId, FAILED);
QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
assertEquals(queryManager.getQueryInfo(queryId).getErrorCode(), QUERY_REJECTED.toErrorCode());
int selectorCount = getSelectors(queryRunner).size();
dao.insertSelector(4, "user.*", "(?i).*reject.*");
assertEquals(dao.getSelectors().size(), selectorCount + 1);
//MILLISECONDS.sleep(2000);
do {
MILLISECONDS.sleep(500);
} while (getSelectors(queryRunner).size() == selectorCount);
// Verify the query can be submitted
queryId = createQuery(queryRunner, newRejectionSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, queryId, RUNNING);
dao.deleteSelector(4, "user.*", "(?i).*reject.*");
do {
MILLISECONDS.sleep(500);
} while (getSelectors(queryRunner).size() != selectorCount);
// Verify the query cannot be submitted
queryId = createQuery(queryRunner, newRejectionSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, queryId, FAILED);
}
}
use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class TestQueues method testTwoQueriesAtSameTime.
@Test(timeOut = 240_000)
public void testTwoQueriesAtSameTime() throws Exception {
String dbConfigUrl = getDbConfigUrl();
H2ResourceGroupsDao dao = getDao(dbConfigUrl);
try (DistributedQueryRunner queryRunner = createQueryRunner(dbConfigUrl, dao)) {
QueryId firstDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
QueryId secondDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
ImmutableSet<QueryState> queuedOrRunning = ImmutableSet.of(QUEUED, RUNNING);
waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
}
}
use of com.facebook.presto.spi.QueryId in project presto by prestodb.
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").build();
try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
// Reserve all the memory
QueryId fakeQueryId = new QueryId("fake");
for (TestingPrestoServer server : queryRunner.getServers()) {
for (MemoryPool pool : server.getLocalMemoryManager().getPools()) {
assertTrue(pool.tryReserve(fakeQueryId, 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 reservedPool;
while ((reservedPool = memoryManager.getPools().get(RESERVED_POOL)) == null) {
MILLISECONDS.sleep(10);
}
ClusterMemoryPool generalPool = memoryManager.getPools().get(GENERAL_POOL);
assertNotNull(generalPool);
// Wait for the queries to start running and get assigned to the expected pools
while (generalPool.getAssignedQueries() != 1 || reservedPool.getAssignedQueries() != 1 || generalPool.getBlockedNodes() != 2 || reservedPool.getBlockedNodes() != 2) {
MILLISECONDS.sleep(10);
}
// Make sure the queries are blocked
List<QueryInfo> currentQueryInfos = queryRunner.getCoordinator().getQueryManager().getAllQueryInfo();
for (QueryInfo info : currentQueryInfos) {
assertFalse(info.getState().isDone());
}
assertEquals(currentQueryInfos.size(), 2);
// Check that the pool information propagated to the query objects
assertNotEquals(currentQueryInfos.get(0).getMemoryPool(), currentQueryInfos.get(1).getMemoryPool());
while (!allQueriesBlocked(currentQueryInfos)) {
MILLISECONDS.sleep(10);
currentQueryInfos = queryRunner.getCoordinator().getQueryManager().getAllQueryInfo();
for (QueryInfo info : currentQueryInfos) {
assertFalse(info.getState().isDone());
}
}
// Release the memory in the reserved pool and the system pool
for (TestingPrestoServer server : queryRunner.getServers()) {
MemoryPool reserved = server.getLocalMemoryManager().getPool(RESERVED_POOL);
// Free up the entire pool
reserved.free(fakeQueryId, reserved.getMaxBytes());
assertTrue(reserved.getFreeBytes() > 0);
MemoryPool system = server.getLocalMemoryManager().getPool(SYSTEM_POOL);
// Free up the entire pool
system.free(fakeQueryId, system.getMaxBytes());
assertTrue(system.getFreeBytes() > 0);
}
// This also checks that the query in the general pool is successfully moved to the reserved pool.
for (Future<?> query : queryFutures) {
query.get();
}
List<QueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getAllQueryInfo();
for (QueryInfo info : queryInfos) {
assertEquals(info.getState(), FINISHED);
}
// Make sure we didn't leak any memory on the workers
for (TestingPrestoServer worker : queryRunner.getServers()) {
MemoryPool reserved = worker.getLocalMemoryManager().getPool(RESERVED_POOL);
assertEquals(reserved.getMaxBytes(), reserved.getFreeBytes());
MemoryPool general = worker.getLocalMemoryManager().getPool(GENERAL_POOL);
// Free up the memory we reserved earlier
general.free(fakeQueryId, general.getMaxBytes());
assertEquals(general.getMaxBytes(), general.getFreeBytes());
MemoryPool system = worker.getLocalMemoryManager().getPool(SYSTEM_POOL);
assertEquals(system.getMaxBytes(), system.getFreeBytes());
}
}
}
use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class InformationSchemaPageSourceProvider method getInternalTable.
private InternalTable getInternalTable(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, ConnectorSplit connectorSplit, List<ColumnHandle> columns) {
InformationSchemaTransactionHandle transaction = (InformationSchemaTransactionHandle) transactionHandle;
InformationSchemaSplit split = (InformationSchemaSplit) connectorSplit;
requireNonNull(columns, "columns is null");
InformationSchemaTableHandle handle = split.getTableHandle();
Map<String, NullableValue> filters = split.getFilters();
Session session = Session.builder(metadata.getSessionPropertyManager()).setTransactionId(transaction.getTransactionId()).setQueryId(new QueryId(connectorSession.getQueryId())).setIdentity(connectorSession.getIdentity()).setSource("information_schema").setCatalog(// default catalog is not be used
"").setSchema(// default schema is not be used
"").setTimeZoneKey(connectorSession.getTimeZoneKey()).setLocale(connectorSession.getLocale()).setStartTime(connectorSession.getStartTime()).build();
return getInformationSchemaTable(session, handle.getCatalogName(), handle.getSchemaTableName(), filters);
}
Aggregations