Search in sources :

Example 1 with TraversingQueryContextVisitor

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

the class MemoryRevokingSchedulerUtils method getMemoryAlreadyBeingRevoked.

public static long getMemoryAlreadyBeingRevoked(Collection<TaskContext> taskContexts, long targetRevokingLimit) {
    TraversingQueryContextVisitor<Void, Long> visitor = new TraversingQueryContextVisitor<Void, Long>() {

        @Override
        public Long visitOperatorContext(OperatorContext operatorContext, Void context) {
            if (operatorContext.isMemoryRevokingRequested()) {
                return operatorContext.getReservedRevocableBytes();
            }
            return 0L;
        }

        @Override
        public Long mergeResults(List<Long> childrenResults) {
            return childrenResults.stream().mapToLong(i -> i).sum();
        }
    };
    long currentRevoking = 0;
    for (TaskContext taskContext : taskContexts) {
        currentRevoking += taskContext.accept(visitor, null);
        if (currentRevoking > targetRevokingLimit) {
            // Return early, target value exceeded and revoking will not occur
            return currentRevoking;
        }
    }
    return currentRevoking;
}
Also used : TaskContext(com.facebook.presto.operator.TaskContext) List(java.util.List) TraversingQueryContextVisitor(com.facebook.presto.memory.TraversingQueryContextVisitor) Collection(java.util.Collection) OperatorContext(com.facebook.presto.operator.OperatorContext) TaskContext(com.facebook.presto.operator.TaskContext) TraversingQueryContextVisitor(com.facebook.presto.memory.TraversingQueryContextVisitor) OperatorContext(com.facebook.presto.operator.OperatorContext) List(java.util.List)

Aggregations

TraversingQueryContextVisitor (com.facebook.presto.memory.TraversingQueryContextVisitor)1 OperatorContext (com.facebook.presto.operator.OperatorContext)1 TaskContext (com.facebook.presto.operator.TaskContext)1 Collection (java.util.Collection)1 List (java.util.List)1