Search in sources :

Example 1 with VoidTraversingQueryContextVisitor

use of io.trino.memory.VoidTraversingQueryContextVisitor in project trino by trinodb.

the class MemoryRevokingScheduler method requestRevoking.

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

        @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("requested revoking %s; remaining %s", revokedBytes, remainingBytesToRevoke.get());
                }
            }
            return null;
        }
    };
    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(io.trino.operator.TaskContext) VoidTraversingQueryContextVisitor(io.trino.memory.VoidTraversingQueryContextVisitor) PipelineContext(io.trino.operator.PipelineContext) OperatorContext(io.trino.operator.OperatorContext)

Aggregations

VoidTraversingQueryContextVisitor (io.trino.memory.VoidTraversingQueryContextVisitor)1 OperatorContext (io.trino.operator.OperatorContext)1 PipelineContext (io.trino.operator.PipelineContext)1 TaskContext (io.trino.operator.TaskContext)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1