lancelly commented on code in PR #9149:
URL: https://github.com/apache/iotdb/pull/9149#discussion_r1122554686


##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/memory/MemoryPool.java:
##########
@@ -282,59 +280,61 @@ public synchronized long 
tryComplete(ListenableFuture<Void> future) {
   }
 
   public void free(String queryId, String fragmentInstanceId, String 
planNodeId, long bytes) {
-    List<MemoryReservationFuture<Void>> futureList = new ArrayList<>();
-    synchronized (this) {
-      Validate.notNull(queryId);
-      Validate.isTrue(bytes > 0L);
-
-      Long queryReservedBytes =
-          queryMemoryReservations
-              .getOrDefault(queryId, Collections.emptyMap())
-              .getOrDefault(fragmentInstanceId, Collections.emptyMap())
-              .get(planNodeId);
-      Validate.notNull(queryReservedBytes);
-      Validate.isTrue(bytes <= queryReservedBytes);
-
-      queryReservedBytes -= bytes;
-      queryMemoryReservations
-          .get(queryId)
-          .get(fragmentInstanceId)
-          .put(planNodeId, queryReservedBytes);
+    Validate.notNull(queryId);
+    Validate.isTrue(bytes > 0L);
 
-      reservedBytes -= bytes;
+    Long queryReservedBytes =
+        queryMemoryReservations
+            .getOrDefault(queryId, Collections.emptyMap())
+            .getOrDefault(fragmentInstanceId, Collections.emptyMap())
+            .computeIfPresent(
+                planNodeId,
+                (k, reservedMemory) -> {
+                  if (reservedMemory < bytes) {
+                    throw new IllegalArgumentException("Free more memory than 
has been reserved.");
+                  }
+                  return reservedMemory - bytes;
+                });
+
+    Validate.notNull(queryReservedBytes);

Review Comment:
   It seems queryReservedBytes is always not null now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to