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;
}
Aggregations