use of com.facebook.presto.operator.DriverContext in project presto by prestodb.
the class TestOrcBatchPageSourceMemoryTracking method testScanFilterAndProjectOperator.
@Test
public void testScanFilterAndProjectOperator() {
// Numbers used in assertions in this test may change when implementation is modified,
// feel free to change them if they break in the future
DriverContext driverContext = testPreparer.newDriverContext();
SourceOperator operator = testPreparer.newScanFilterAndProjectOperator(driverContext);
assertEquals(driverContext.getSystemMemoryUsage(), 0);
int totalRows = 0;
while (totalRows < NUM_ROWS) {
assertFalse(operator.isFinished());
Page page = operator.getOutput();
assertNotNull(page);
assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 90_000L, 619999L);
totalRows += page.getPositionCount();
}
// done... in the current implementation finish is not set until output returns a null page
assertNull(operator.getOutput());
assertTrue(operator.isFinished());
assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 0L, 500L);
}
use of com.facebook.presto.operator.DriverContext in project presto by prestodb.
the class TestOrcBatchPageSourceMemoryTracking method testTableScanOperator.
@Test
public void testTableScanOperator() {
// Numbers used in assertions in this test may change when implementation is modified,
// feel free to change them if they break in the future
DriverContext driverContext = testPreparer.newDriverContext();
SourceOperator operator = testPreparer.newTableScanOperator(driverContext);
assertEquals(driverContext.getSystemMemoryUsage(), 0);
int totalRows = 0;
while (totalRows < 20000) {
assertFalse(operator.isFinished());
Page page = operator.getOutput();
assertNotNull(page);
page.getBlock(1);
assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 390000L, 619999L);
totalRows += page.getPositionCount();
}
while (totalRows < 40000) {
assertFalse(operator.isFinished());
Page page = operator.getOutput();
assertNotNull(page);
page.getBlock(1);
assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 390000L, 619999L);
totalRows += page.getPositionCount();
}
while (totalRows < NUM_ROWS) {
assertFalse(operator.isFinished());
Page page = operator.getOutput();
assertNotNull(page);
page.getBlock(1);
assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 430000L, 459999L);
totalRows += page.getPositionCount();
}
assertFalse(operator.isFinished());
assertNull(operator.getOutput());
assertTrue(operator.isFinished());
assertEquals(driverContext.getSystemMemoryUsage(), 0);
}
use of com.facebook.presto.operator.DriverContext 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);
}
use of com.facebook.presto.operator.DriverContext in project presto by prestodb.
the class PrestoSparkTaskExecution method enqueueDriverSplitRunner.
private synchronized void enqueueDriverSplitRunner(boolean forceRunSplit, List<DriverSplitRunner> runners) {
// schedule driver to be executed
List<ListenableFuture<?>> finishedFutures = taskExecutor.enqueueSplits(taskHandle, forceRunSplit, runners);
checkState(finishedFutures.size() == runners.size(), "Expected %s futures but got %s", runners.size(), finishedFutures.size());
// when driver completes, update state and fire events
for (int i = 0; i < finishedFutures.size(); i++) {
ListenableFuture<?> finishedFuture = finishedFutures.get(i);
final DriverSplitRunner splitRunner = runners.get(i);
// record new driver
remainingDrivers.incrementAndGet();
Futures.addCallback(finishedFuture, new FutureCallback<Object>() {
@Override
public void onSuccess(Object result) {
try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
// record driver is finished
remainingDrivers.decrementAndGet();
checkTaskCompletion();
splitMonitor.splitCompletedEvent(taskId, getDriverStats());
}
}
@Override
public void onFailure(Throwable cause) {
try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
taskStateMachine.failed(cause);
// record driver is finished
remainingDrivers.decrementAndGet();
// fire failed event with cause
splitMonitor.splitFailedEvent(taskId, getDriverStats(), cause);
}
}
private DriverStats getDriverStats() {
DriverContext driverContext = splitRunner.getDriverContext();
DriverStats driverStats;
if (driverContext != null) {
driverStats = driverContext.getDriverStats();
} else {
// split runner did not start successfully
driverStats = new DriverStats();
}
return driverStats;
}
}, notificationExecutor);
}
}
Aggregations