use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class TestMemoryPools method testMoveQuery.
@Test
public void testMoveQuery() {
QueryId testQuery = new QueryId("test_query");
MemoryPool pool1 = new MemoryPool(new MemoryPoolId("test"), new DataSize(1000, BYTE));
MemoryPool pool2 = new MemoryPool(new MemoryPoolId("test"), new DataSize(1000, BYTE));
pool1.reserve(testQuery, "test_tag", 10);
Map<String, Long> allocations = pool1.getTaggedMemoryAllocations(testQuery);
assertEquals(allocations, ImmutableMap.of("test_tag", 10L));
pool1.moveQuery(testQuery, pool2);
assertNull(pool1.getTaggedMemoryAllocations(testQuery));
allocations = pool2.getTaggedMemoryAllocations(testQuery);
assertEquals(allocations, ImmutableMap.of("test_tag", 10L));
assertEquals(pool1.getFreeBytes(), 1000);
assertEquals(pool2.getFreeBytes(), 990);
pool2.free(testQuery, "test", 10);
assertEquals(pool2.getFreeBytes(), 1000);
}
use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class LocalQueryProvider method getQuery.
public Query getQuery(QueryId queryId, String slug) {
Query query = queries.get(queryId);
if (query != null) {
if (!query.isSlugValid(slug)) {
throw notFound("Query not found");
}
return query;
}
// this is the first time the query has been accessed on this coordinator
Session session;
try {
if (!queryManager.isQuerySlugValid(queryId, slug)) {
throw notFound("Query not found");
}
session = queryManager.getQuerySession(queryId);
} catch (NoSuchElementException e) {
throw notFound("Query not found");
}
query = queries.computeIfAbsent(queryId, id -> {
ExchangeClient exchangeClient = exchangeClientSupplier.get(new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), LocalQueryProvider.class.getSimpleName()));
return Query.create(session, slug, queryManager, transactionManager, exchangeClient, responseExecutor, timeoutExecutor, blockEncodingSerde, retryCircuitBreaker);
});
return query;
}
use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class TestSourcePartitionedScheduler method createSqlStageExecution.
private SqlStageExecution createSqlStageExecution(SubPlan tableScanPlan, NodeTaskMap nodeTaskMap) {
StageId stageId = new StageId(new QueryId("query"), 0);
SqlStageExecution stage = SqlStageExecution.createSqlStageExecution(new StageExecutionId(stageId, 0), tableScanPlan.getFragment(), new MockRemoteTaskFactory(queryExecutor, scheduledExecutor), TEST_SESSION, true, nodeTaskMap, queryExecutor, new NoOpFailureDetector(), new SplitSchedulerStats(), new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty()));
stage.setOutputBuffers(createInitialEmptyOutputBuffers(PARTITIONED).withBuffer(OUT, 0).withNoMoreBufferIds());
return stage;
}
use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class TestQueryContext method testSetMemoryPool.
@Test(dataProvider = "testSetMemoryPoolOptions")
public void testSetMemoryPool(boolean useReservedPool) {
QueryId secondQuery = new QueryId("second");
MemoryPool reservedPool = new MemoryPool(RESERVED_POOL, new DataSize(10, BYTE));
long secondQueryMemory = reservedPool.getMaxBytes() - 1;
if (useReservedPool) {
assertTrue(reservedPool.reserve(secondQuery, "test", secondQueryMemory).isDone());
}
try (LocalQueryRunner localQueryRunner = new LocalQueryRunner(TEST_SESSION)) {
QueryContext queryContext = new QueryContext(new QueryId("query"), new DataSize(10, BYTE), new DataSize(20, BYTE), new DataSize(10, BYTE), new DataSize(1, GIGABYTE), new MemoryPool(GENERAL_POOL, new DataSize(10, BYTE)), new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(0, BYTE), new SpillSpaceTracker(new DataSize(0, BYTE)), listJsonCodec(TaskMemoryReservationSummary.class));
// Use memory
queryContext.getQueryMemoryContext().initializeLocalMemoryContexts("test");
LocalMemoryContext userMemoryContext = queryContext.getQueryMemoryContext().localUserMemoryContext();
LocalMemoryContext revocableMemoryContext = queryContext.getQueryMemoryContext().localRevocableMemoryContext();
assertTrue(userMemoryContext.setBytes(3).isDone());
assertTrue(revocableMemoryContext.setBytes(5).isDone());
queryContext.setMemoryPool(reservedPool);
if (useReservedPool) {
reservedPool.free(secondQuery, "test", secondQueryMemory);
}
// Free memory
userMemoryContext.close();
revocableMemoryContext.close();
}
}
use of com.facebook.presto.spi.QueryId in project presto by prestodb.
the class TestQueryContext method testMoveTaggedAllocations.
@Test
public void testMoveTaggedAllocations() {
MemoryPool generalPool = new MemoryPool(GENERAL_POOL, new DataSize(10_000, BYTE));
MemoryPool reservedPool = new MemoryPool(RESERVED_POOL, new DataSize(10_000, BYTE));
QueryId queryId = new QueryId("query");
QueryContext queryContext = createQueryContext(queryId, generalPool);
TaskStateMachine taskStateMachine = new TaskStateMachine(TaskId.valueOf("queryid.0.0.0"), TEST_EXECUTOR);
TaskContext taskContext = queryContext.addTaskContext(taskStateMachine, TEST_SESSION, Optional.of(PLAN_FRAGMENT.getRoot()), false, false, false, false, false);
DriverContext driverContext = taskContext.addPipelineContext(0, false, false, false).addDriverContext();
OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId("test"), "test");
// allocate some memory in the general pool
LocalMemoryContext memoryContext = operatorContext.aggregateUserMemoryContext().newLocalMemoryContext("test_context");
memoryContext.setBytes(1_000);
Map<String, Long> allocations = generalPool.getTaggedMemoryAllocations(queryId);
assertEquals(allocations, ImmutableMap.of("test_context", 1_000L));
queryContext.setMemoryPool(reservedPool);
assertNull(generalPool.getTaggedMemoryAllocations(queryId));
allocations = reservedPool.getTaggedMemoryAllocations(queryId);
assertEquals(allocations, ImmutableMap.of("test_context", 1_000L));
assertEquals(generalPool.getFreeBytes(), 10_000);
assertEquals(reservedPool.getFreeBytes(), 9_000);
memoryContext.close();
assertEquals(generalPool.getFreeBytes(), 10_000);
assertEquals(reservedPool.getFreeBytes(), 10_000);
}
Aggregations