Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/trino-main/src/main/java/io/trino/memory/MemoryPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import static com.google.common.base.MoreObjects.toStringHelper;
Expand All @@ -53,9 +54,9 @@ public class MemoryPool
@GuardedBy("this")
private NonCancellableMemoryFuture<Void> future;

@GuardedBy("this")
// TODO: It would be better if we just tracked QueryContexts, but their lifecycle is managed by a weak reference, so we can't do that
private final Map<QueryId, Long> queryMemoryReservations = new HashMap<>();
// It is guarded for updates by this, but can be read without holding a lock
private final Map<QueryId, Long> queryMemoryReservations = new ConcurrentHashMap<>();

// This map keeps track of all the tagged allocations, e.g., query-1 -> ['TableScanOperator': 10MB, 'LazyOutputBuffer': 5MB, ...]
@GuardedBy("this")
Expand Down Expand Up @@ -347,7 +348,7 @@ public synchronized long getReservedRevocableBytes()
return reservedRevocableBytes;
}

synchronized long getQueryMemoryReservation(QueryId queryId)
long getQueryMemoryReservation(QueryId queryId)
{
return queryMemoryReservations.getOrDefault(queryId, 0L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public synchronized MemoryPool getMemoryPool()
return memoryPool;
}

public synchronized long getUserMemoryReservation()
public long getUserMemoryReservation()
{
return memoryPool.getQueryMemoryReservation(queryId);
}
Expand Down