You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "lancelly (via GitHub)" <gi...@apache.org> on 2023/03/02 03:10:37 UTC

[GitHub] [iotdb] lancelly commented on a diff in pull request #9149: [IOTDB-5586] Reduce the scope of lock in MemoryPool

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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org