From 556c5987dfdb63f07b501e990c1cfd8e422be3a8 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Tue, 16 Apr 2019 18:25:38 +0300 Subject: [PATCH 1/5] IGNITE_11754 another approach to fix memory leak --- .../distributed/GridCacheTxFinishSync.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 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 c903bf329cc26..69e521a381043 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 @@ -103,8 +103,14 @@ public void onDisconnected(IgniteFuture reconnectFut) { 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.nodeMap.isEmpty()) + threadMap.remove(threadId); + } + } } /** @@ -138,29 +144,31 @@ private ThreadFinishSync(long threadId) { * @param nodeId Node ID request being sent to. */ public void onSend(UUID nodeId) { - TxFinishSync sync = nodeMap.get(nodeId); + synchronized (this) { + TxFinishSync sync = nodeMap.get(nodeId); - if (sync == null) { - sync = new TxFinishSync(nodeId, threadId); + if (sync == null) { + sync = new TxFinishSync(nodeId, threadId); - TxFinishSync old = nodeMap.put(nodeId, sync); + TxFinishSync old = nodeMap.put(nodeId, sync); - assert old == null : "Only user thread can add sync objects to the map."; + assert old == null : "Only user thread can add sync objects to the map."; - // Recheck discovery only if added new sync. - if (cctx.discovery().node(nodeId) == null) { - sync.onNodeLeft(); + // Recheck discovery only if added new sync. + if (cctx.discovery().node(nodeId) == null) { + sync.onNodeLeft(); - nodeMap.remove(nodeId); - } - else if (cctx.kernalContext().clientDisconnected()) { - sync.onDisconnected(cctx.kernalContext().cluster().clientReconnectFuture()); + nodeMap.remove(nodeId); + } + else if (cctx.kernalContext().clientDisconnected()) { + sync.onDisconnected(cctx.kernalContext().cluster().clientReconnectFuture()); - nodeMap.remove(nodeId); + nodeMap.remove(nodeId); + } } - } - sync.onSend(); + sync.onSend(); + } } /** @@ -192,7 +200,7 @@ public void onDisconnected(IgniteFuture reconnectFut) { * @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(); From 2bf8139a0fe7674e1bece77cd8b2ab2e90a2ecc5 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Wed, 17 Apr 2019 16:58:08 +0300 Subject: [PATCH 2/5] IGNITE_11754 race between onFinishedSend and onAckReceived is closed --- .../distributed/GridCacheTxFinishSync.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 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 69e521a381043..64834769e4134 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 @@ -65,9 +65,16 @@ public void onFinishSend(UUID nodeId, long threadId) { 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); + } } /** @@ -144,31 +151,29 @@ private ThreadFinishSync(long threadId) { * @param nodeId Node ID request being sent to. */ public void onSend(UUID nodeId) { - synchronized (this) { - TxFinishSync sync = nodeMap.get(nodeId); - - if (sync == null) { - sync = new TxFinishSync(nodeId, threadId); + TxFinishSync sync = nodeMap.get(nodeId); - TxFinishSync old = nodeMap.put(nodeId, sync); + if (sync == null) { + sync = new TxFinishSync(nodeId, threadId); - assert old == null : "Only user thread can add sync objects to the map."; + TxFinishSync old = nodeMap.put(nodeId, sync); - // Recheck discovery only if added new sync. - if (cctx.discovery().node(nodeId) == null) { - sync.onNodeLeft(); + assert old == null : "Only user thread can add sync objects to the map."; - nodeMap.remove(nodeId); - } - else if (cctx.kernalContext().clientDisconnected()) { - sync.onDisconnected(cctx.kernalContext().cluster().clientReconnectFuture()); + // Recheck discovery only if added new sync. + if (cctx.discovery().node(nodeId) == null) { + sync.onNodeLeft(); - nodeMap.remove(nodeId); - } + nodeMap.remove(nodeId); } + else if (cctx.kernalContext().clientDisconnected()) { + sync.onDisconnected(cctx.kernalContext().cluster().clientReconnectFuture()); - sync.onSend(); + nodeMap.remove(nodeId); + } } + + sync.onSend(); } /** From 637783c0699b23e8046e739ca01ca7ae06a0f4d0 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 18 Apr 2019 09:34:40 +0300 Subject: [PATCH 3/5] IGNITE_11754 master branch merged --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e1586e6ed3c77..fd739b6d57a3f 100644 --- a/pom.xml +++ b/pom.xml @@ -397,15 +397,15 @@ - - + + - + From 3e836f010c2a9979af47c201ba3bdce24721dcce Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 18 Apr 2019 13:16:20 +0300 Subject: [PATCH 4/5] IGNITE-11754 check and remove (if needed) from threadSync map on nodeLeft event --- .../distributed/GridCacheTxFinishSync.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 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 64834769e4134..420e85f780bc9 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.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; @@ -114,7 +113,7 @@ public void onAckReceived(UUID nodeId, long threadId) { threadSync.onReceive(nodeId); synchronized (threadSync) { - if (threadSync.nodeMap.isEmpty()) + if (threadSync.isEmpty()) threadMap.remove(threadId); } } @@ -126,8 +125,14 @@ public void onAckReceived(UUID nodeId, long threadId) { * @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); + } + } } /** @@ -220,6 +225,13 @@ public void onNodeLeft(UUID nodeId) { if (sync != null) sync.onNodeLeft(); } + + /** + * + */ + private boolean isEmpty() { + return nodeMap.isEmpty(); + } } /** From 103b771c5f433fe1912474f2597fa8c966d2d006 Mon Sep 17 00:00:00 2001 From: Sergey Chugunov Date: Thu, 18 Apr 2019 13:18:16 +0300 Subject: [PATCH 5/5] IGNITE-11754 pom.xml changes revert --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index fd739b6d57a3f..e1586e6ed3c77 100644 --- a/pom.xml +++ b/pom.xml @@ -397,15 +397,15 @@ - - + + - +