You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2023/04/11 09:52:51 UTC

[iotdb] 01/01: fix npe when deregister fragmentInstance

This is an automated email from the ASF dual-hosted git repository.

xiangweiwei pushed a commit to branch deregisterNPE
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit e4369a1454d3e7e0ccd9bef3306e6f123cee8182
Author: Alima777 <wx...@gmail.com>
AuthorDate: Tue Apr 11 17:52:35 2023 +0800

    fix npe when deregister fragmentInstance
---
 .../iotdb/db/mpp/execution/memory/MemoryPool.java  | 28 +++++++++++-----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/memory/MemoryPool.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/memory/MemoryPool.java
index f72d935514..fc92b2f725 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/memory/MemoryPool.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/execution/memory/MemoryPool.java
@@ -26,12 +26,11 @@ import org.apache.iotdb.tsfile.utils.Pair;
 import com.google.common.util.concurrent.AbstractFuture;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import javax.annotation.Nullable;
 import org.apache.commons.lang3.Validate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.annotation.Nullable;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -172,19 +171,20 @@ public class MemoryPool {
    */
   public void deRegisterFragmentInstanceToQueryMemoryMap(
       String queryId, String fragmentInstanceId) {
-    Map<String, Long> planNodeRelatedMemory =
-        queryMemoryReservations.get(queryId).get(fragmentInstanceId);
-    for (Long memoryReserved : planNodeRelatedMemory.values()) {
-      if (memoryReserved != 0) {
-        throw new MemoryLeakException(
-            "PlanNode related memory is not zero when deregister fragment instance from query memory pool.");
+    Map<String, Map<String, Long>> queryRelatedMemory = queryMemoryReservations.get(queryId);
+    if (queryRelatedMemory != null) {
+      Map<String, Long> fragmentRelatedMemory = queryRelatedMemory.get(fragmentInstanceId);
+      for (Long memoryReserved : fragmentRelatedMemory.values()) {
+        if (memoryReserved != 0) {
+          throw new MemoryLeakException(
+              "PlanNode related memory is not zero when deregister fragment instance from query memory pool.");
+        }
       }
-    }
-    synchronized (queryMemoryReservations) {
-      Map<String, Map<String, Long>> queryRelatedMemory = queryMemoryReservations.get(queryId);
-      queryRelatedMemory.remove(fragmentInstanceId);
-      if (queryRelatedMemory.isEmpty()) {
-        queryMemoryReservations.remove(queryId);
+      synchronized (queryMemoryReservations) {
+        queryRelatedMemory.remove(fragmentInstanceId);
+        if (queryRelatedMemory.isEmpty()) {
+          queryMemoryReservations.remove(queryId);
+        }
       }
     }
   }