You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2019/04/18 18:10:18 UTC

[ignite] branch master updated: IGNITE-11754 Fixed memory leak in TxFinishSync - Fixes #6462.

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

agoncharuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a39260  IGNITE-11754 Fixed memory leak in TxFinishSync - Fixes #6462.
3a39260 is described below

commit 3a392609e176e8e5321dc8d18d1d955375d1bc64
Author: Sergey Chugunov <se...@gmail.com>
AuthorDate: Thu Apr 18 21:06:30 2019 +0300

    IGNITE-11754 Fixed memory leak in TxFinishSync - Fixes #6462.
    
    Signed-off-by: Alexey Goncharuk <al...@gmail.com>
---
 .../cache/distributed/GridCacheTxFinishSync.java   | 37 ++++++++++++++++++----
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxFinishSync.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxFinishSync.java
index c903bf3..420e85f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxFinishSync.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTxFinishSync.java
@@ -28,7 +28,6 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
-import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.lang.IgniteFuture;
 import org.jetbrains.annotations.Nullable;
 
@@ -65,9 +64,16 @@ public class GridCacheTxFinishSync<K, V> {
         ThreadFinishSync threadSync = threadMap.get(threadId);
 
         if (threadSync == null)
-            threadSync = F.addIfAbsent(threadMap, threadId, new ThreadFinishSync(threadId));
+            threadMap.put(threadId, threadSync = new ThreadFinishSync(threadId));
 
-        threadSync.onSend(nodeId);
+        synchronized (threadSync) {
+            //thread has to create new ThreadFinishSync
+            //if other thread executing onAckReceived method removed previous threadSync object
+            if (threadMap.get(threadId) == null)
+                threadMap.put(threadId, threadSync = new ThreadFinishSync(threadId));
+
+            threadSync.onSend(nodeId);
+        }
     }
 
     /**
@@ -103,8 +109,14 @@ public class GridCacheTxFinishSync<K, V> {
     public void onAckReceived(UUID nodeId, long threadId) {
         ThreadFinishSync threadSync = threadMap.get(threadId);
 
-        if (threadSync != null)
+        if (threadSync != null) {
             threadSync.onReceive(nodeId);
+
+            synchronized (threadSync) {
+                if (threadSync.isEmpty())
+                    threadMap.remove(threadId);
+            }
+        }
     }
 
     /**
@@ -113,8 +125,14 @@ public class GridCacheTxFinishSync<K, V> {
      * @param nodeId Left node ID.
      */
     public void onNodeLeft(UUID nodeId) {
-        for (ThreadFinishSync threadSync : threadMap.values())
+        for (ThreadFinishSync threadSync : threadMap.values()) {
             threadSync.onNodeLeft(nodeId);
+
+            synchronized (threadSync) {
+                if (threadSync.isEmpty())
+                    threadMap.remove(threadSync);
+            }
+        }
     }
 
     /**
@@ -192,7 +210,7 @@ public class GridCacheTxFinishSync<K, V> {
          * @param nodeId Node ID response received from.
          */
         public void onReceive(UUID nodeId) {
-            TxFinishSync sync = nodeMap.get(nodeId);
+            TxFinishSync sync = nodeMap.remove(nodeId);
 
             if (sync != null)
                 sync.onReceive();
@@ -207,6 +225,13 @@ public class GridCacheTxFinishSync<K, V> {
             if (sync != null)
                 sync.onNodeLeft();
         }
+
+        /**
+         *
+         */
+        private boolean isEmpty() {
+            return nodeMap.isEmpty();
+        }
     }
 
     /**