use of com.facebook.presto.memory.ClusterMemoryPool in project presto by prestodb.
the class ResourceManagerClusterStateProvider method getClusterMemoryPoolInfoInternal.
private Map<MemoryPoolId, ClusterMemoryPoolInfo> getClusterMemoryPoolInfoInternal() {
List<MemoryInfo> memoryInfos = nodeStatuses.values().stream().map(nodeStatus -> nodeStatus.getNodeStatus().getMemoryInfo()).collect(toImmutableList());
int queriesAssignedToGeneralPool = 0;
int queriesAssignedToReservedPool = 0;
Query largestGeneralPoolQuery = null;
for (CoordinatorQueriesState nodeQueryState : nodeQueryStates.values()) {
for (Query query : nodeQueryState.getActiveQueries()) {
MemoryPoolId memoryPool = query.getBasicQueryInfo().getMemoryPool();
if (GENERAL_POOL.equals(memoryPool)) {
queriesAssignedToGeneralPool = Math.incrementExact(queriesAssignedToGeneralPool);
if (!resourceOvercommit(query.getBasicQueryInfo().getSession().toSession(sessionPropertyManager))) {
largestGeneralPoolQuery = getLargestMemoryQuery(Optional.ofNullable(largestGeneralPoolQuery), query);
}
} else if (RESERVED_POOL.equals(memoryPool)) {
queriesAssignedToReservedPool = Math.incrementExact(queriesAssignedToReservedPool);
} else {
throw new IllegalArgumentException("Unrecognized memory pool: " + memoryPool);
}
}
}
ImmutableMap.Builder<MemoryPoolId, ClusterMemoryPoolInfo> memoryPoolInfos = ImmutableMap.builder();
ClusterMemoryPool pool = new ClusterMemoryPool(GENERAL_POOL);
pool.update(memoryInfos, queriesAssignedToGeneralPool);
ClusterMemoryPoolInfo clusterInfo = pool.getClusterInfo(Optional.ofNullable(largestGeneralPoolQuery).map(Query::getQueryId));
memoryPoolInfos.put(GENERAL_POOL, clusterInfo);
if (isReservedPoolEnabled) {
pool = new ClusterMemoryPool(RESERVED_POOL);
pool.update(memoryInfos, queriesAssignedToReservedPool);
memoryPoolInfos.put(RESERVED_POOL, pool.getClusterInfo());
}
return memoryPoolInfos.build();
}
Aggregations