You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by zh...@apache.org on 2020/11/14 01:58:19 UTC

[geode] branch feature/GEODE-8706 created (now 903be88)

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

zhouxj pushed a change to branch feature/GEODE-8706
in repository https://gitbox.apache.org/repos/asf/geode.git.


      at 903be88  GEODE-8706: getConnection should get readLock to sync with destroyConnection

This branch includes the following new commits:

     new 903be88  GEODE-8706: getConnection should get readLock to sync with destroyConnection

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[geode] 01/01: GEODE-8706: getConnection should get readLock to sync with destroyConnection

Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zhouxj pushed a commit to branch feature/GEODE-8706
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 903be88a43d058e379dbd8a77e9f254065ab8968
Author: zhouxh <gz...@pivotal.io>
AuthorDate: Fri Nov 13 17:55:17 2020 -0800

    GEODE-8706: getConnection should get readLock to sync with destroyConnection
---
 .../wan/GatewaySenderEventRemoteDispatcher.java    | 41 ++++++++++++++--------
 ...atewaySenderEventRemoteDispatcherJUnitTest.java |  1 +
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java b/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
index 8717674..ecdc297 100644
--- a/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
+++ b/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.Logger;
 
 import org.apache.geode.CancelException;
 import org.apache.geode.GemFireIOException;
+import org.apache.geode.annotations.VisibleForTesting;
 import org.apache.geode.cache.RegionDestroyedException;
 import org.apache.geode.cache.client.ServerConnectivityException;
 import org.apache.geode.cache.client.ServerOperationException;
@@ -280,6 +281,11 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
     }
   }
 
+  @VisibleForTesting
+  ReentrantReadWriteLock getConnectionLifeCycleLock() {
+    return this.connectionLifeCycleLock;
+  }
+
   /**
    * Acquires or adds a new <code>Connection</code> to the corresponding <code>Gateway</code>
    *
@@ -294,23 +300,28 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
     // IF the connection is null
     // OR the connection's ServerLocation doesn't match with the one stored in sender
     // THEN initialize the connection
-    if (!this.sender.isParallel()) {
-      if (this.connection == null || this.connection.isDestroyed()
-          || this.connection.getServer() == null
-          || !this.connection.getServer().equals(this.sender.getServerLocation())) {
-        if (logger.isDebugEnabled()) {
-          logger.debug(
-              "Initializing new connection as serverLocation of old connection is : {} and the serverLocation to connect is {}",
-              ((this.connection == null) ? "null" : this.connection.getServer()),
-              this.sender.getServerLocation());
+    getConnectionLifeCycleLock().readLock().lock();
+    try {
+      if (!this.sender.isParallel()) {
+        if (this.connection == null || this.connection.isDestroyed()
+            || this.connection.getServer() == null
+            || !this.connection.getServer().equals(this.sender.getServerLocation())) {
+          if (logger.isDebugEnabled()) {
+            logger.debug(
+                "Initializing new connection as serverLocation of old connection is : {} and the serverLocation to connect is {}",
+                ((this.connection == null) ? "null" : this.connection.getServer()),
+                this.sender.getServerLocation());
+          }
+          // Initialize the connection
+          initializeConnection();
+        }
+      } else {
+        if (this.connection == null || this.connection.isDestroyed()) {
+          initializeConnection();
         }
-        // Initialize the connection
-        initializeConnection();
-      }
-    } else {
-      if (this.connection == null || this.connection.isDestroyed()) {
-        initializeConnection();
       }
+    } finally {
+      getConnectionLifeCycleLock().readLock().unlock();
     }
 
     // Here we might wait on a connection to another server if I was secondary
diff --git a/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java b/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java
index d0360d1..7cfe1f5 100644
--- a/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java
+++ b/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcherJUnitTest.java
@@ -75,5 +75,6 @@ public class GatewaySenderEventRemoteDispatcherJUnitTest {
     doNothing().when(dispatcher).initializeConnection();
     Connection newConnection = dispatcher.getConnection(true);
     verify(dispatcher, times(1)).initializeConnection();
+    verify(dispatcher, times(2)).getConnectionLifeCycleLock();
   }
 }