Search in sources :

Example 1 with VoidTraversingQueryContextVisitor

use of com.facebook.presto.memory.VoidTraversingQueryContextVisitor in project presto by prestodb.

the class MemoryRevokingScheduler method requestRevoking.

private void requestRevoking(MemoryPoolId memoryPoolId, ArrayList<SqlTask> sqlTasks, long remainingBytesToRevoke) {
    VoidTraversingQueryContextVisitor<AtomicLong> visitor = new VoidTraversingQueryContextVisitor<AtomicLong>() {

        @Override
        public Void visitPipelineContext(PipelineContext pipelineContext, AtomicLong remainingBytesToRevoke) {
            if (remainingBytesToRevoke.get() <= 0) {
                // exit immediately if no work needs to be done
                return null;
            }
            return super.visitPipelineContext(pipelineContext, remainingBytesToRevoke);
        }

        @Override
        public Void visitOperatorContext(OperatorContext operatorContext, AtomicLong remainingBytesToRevoke) {
            if (remainingBytesToRevoke.get() > 0) {
                long revokedBytes = operatorContext.requestMemoryRevoking();
                if (revokedBytes > 0) {
                    remainingBytesToRevoke.addAndGet(-revokedBytes);
                    log.debug("memoryPool=%s: requested revoking %s; remaining %s", memoryPoolId, revokedBytes, remainingBytesToRevoke.get());
                }
            }
            return null;
        }
    };
    // Sort the tasks into their traversal order
    log.debug("Ordering by %s", spillingStrategy);
    sortTasksToTraversalOrder(sqlTasks, spillingStrategy);
    AtomicLong remainingBytesToRevokeAtomic = new AtomicLong(remainingBytesToRevoke);
    for (SqlTask task : sqlTasks) {
        Optional<TaskContext> taskContext = task.getTaskContext();
        if (taskContext.isPresent()) {
            taskContext.get().accept(visitor, remainingBytesToRevokeAtomic);
            if (remainingBytesToRevokeAtomic.get() <= 0) {
                // No further revoking required
                return;
            }
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TaskContext(com.facebook.presto.operator.TaskContext) VoidTraversingQueryContextVisitor(com.facebook.presto.memory.VoidTraversingQueryContextVisitor) PipelineContext(com.facebook.presto.operator.PipelineContext) OperatorContext(com.facebook.presto.operator.OperatorContext)

Aggregations

VoidTraversingQueryContextVisitor (com.facebook.presto.memory.VoidTraversingQueryContextVisitor)1 OperatorContext (com.facebook.presto.operator.OperatorContext)1 PipelineContext (com.facebook.presto.operator.PipelineContext)1 TaskContext (com.facebook.presto.operator.TaskContext)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1