Repository: incubator-geode
Updated Branches:
  refs/heads/develop 15450f5c3 -> 0a96cbd9a


GEODE-2064: Added check for system shutdown while handlling connect exception

While message send in progress, if the system gets shutdown (forced disconnect),
the send (message delivery to peers) reports connect exception and ignores
detecting/throwing SystemDisconnect exception.

This results in client missing an event and resulting in data mismatch between
client and server.

Made changes to throw "DistributedSystemDisconnectedException" if system is
shutting down. This will result in caller to retry the operation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/0a96cbd9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/0a96cbd9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/0a96cbd9

Branch: refs/heads/develop
Commit: 0a96cbd9ade0023a68d1487c90e892978ded79cc
Parents: 15450f5
Author: Anil <[email protected]>
Authored: Mon Nov 7 12:20:53 2016 -0800
Committer: Anil <[email protected]>
Committed: Mon Nov 7 12:29:08 2016 -0800

----------------------------------------------------------------------
 .../membership/gms/mgr/GMSMembershipManager.java | 10 ++++++++++
 .../gms/mgr/GMSMembershipManagerJUnitTest.java   | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0a96cbd9/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
 
b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
index a4691f4..cf17025 100644
--- 
a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
+++ 
b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
@@ -1702,6 +1702,16 @@ public class GMSMembershipManager implements 
MembershipManager, Manager {
         throw ex; // see bug 41416
       }
     } catch (ConnectExceptions ex) {
+      // Check if the connect exception is due to system shutting down.
+      if (shutdownInProgress()) {
+        if (services.getShutdownCause() != null) {
+          throw new DistributedSystemDisconnectedException("DistributedSystem 
is shutting down",
+              services.getShutdownCause());
+        } else {
+          throw new DistributedSystemDisconnectedException();
+        }
+      }
+
       if (allDestinations)
         return null;
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0a96cbd9/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManagerJUnitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManagerJUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManagerJUnitTest.java
index bae1ddc..1578753 100644
--- 
a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManagerJUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManagerJUnitTest.java
@@ -34,6 +34,7 @@ import 
org.apache.geode.internal.admin.remote.AlertListenerMessage;
 import org.apache.geode.internal.admin.remote.RemoteTransportConfig;
 import org.apache.geode.internal.tcp.ConnectExceptions;
 import org.apache.geode.test.junit.categories.UnitTest;
+import org.assertj.core.api.Assertions;
 import org.jgroups.util.UUID;
 import org.junit.After;
 import org.junit.Before;
@@ -335,6 +336,24 @@ public class GMSMembershipManagerJUnitTest {
         isA(DistributionMessage.class), anyInt(), anyInt());
   }
 
+  @Test
+  public void testDirectChannelSendFailureDueToForcedDisconnect() throws 
Exception {
+    setUpDirectChannelMock();
+    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
+    InternalDistributedMember[] recipients =
+        new InternalDistributedMember[] {mockMembers[2], mockMembers[3]};
+    m.setRecipients(Arrays.asList(recipients));
+    Set<InternalDistributedMember> failures = 
manager.directChannelSend(recipients, m, null);
+    manager.setShutdown();
+    ConnectExceptions exception = new ConnectExceptions();
+    exception.addFailure(recipients[0], new Exception("testing"));
+    when(dc.send(any(GMSMembershipManager.class), any(mockMembers.getClass()),
+        any(DistributionMessage.class), anyInt(), 
anyInt())).thenThrow(exception);
+    Assertions.assertThatThrownBy(() -> {
+      manager.directChannelSend(recipients, m, null);
+    }).isInstanceOf(DistributedSystemDisconnectedException.class);
+  }
+
   /**
    * This test ensures that the membership manager can accept an ID that does 
not have a UUID and
    * replace it with one that does have a UUID from the current membership 
view.

Reply via email to