BUG-8494: do not attempt to reconnect ReconnectingClientConnection 88/58388/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 3 Jun 2017 02:16:00 +0000 (04:16 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Jun 2017 08:20:30 +0000 (10:20 +0200)
If we are in reconnect state, we should never attempt to initiate
reconnection, as that would leave us without the timer running --
which is a problem since we need to be timing out requests which
are queued even as we are attempting to reconnect to the backend.

Change-Id: Ic955a2e5b743617c26cc72815df94d0c4584704c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 584be7bf6b41f2f8b01dd718aba8d3b6cf7426ef)

opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/AbstractClientConnection.java
opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ReconnectingClientConnection.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AbstractClientConnectionTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ConnectedClientConnectionTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ReconnectingClientConnectionTest.java

index 9844225..abd6680 100644 (file)
@@ -217,7 +217,7 @@ public abstract class AbstractClientConnection<T extends BackendInfo> {
             if (delay >= DEBUG_DELAY_NANOS) {
                 if (delay > MAX_DELAY_NANOS) {
                     LOG.info("Capping {} throttle delay from {} to {} seconds", this,
-                        TimeUnit.NANOSECONDS.toSeconds(delay), MAX_DELAY_SECONDS);
+                        TimeUnit.NANOSECONDS.toSeconds(delay), MAX_DELAY_SECONDS, new Throwable());
                     delay = MAX_DELAY_NANOS;
                 }
                 if (LOG.isDebugEnabled()) {
index b59c9e3..6a3ba27 100644 (file)
@@ -29,10 +29,16 @@ public final class ReconnectingClientConnection<T extends BackendInfo> extends A
         this.cause = Preconditions.checkNotNull(cause);
     }
 
+    @Override
+    long backendSilentTicks(final long now) {
+        // We do not want to reconnect this connection, as we need the timer to to keep running
+        return 0;
+    }
+
     @Override
     ClientActorBehavior<T> lockedReconnect(final ClientActorBehavior<T> current, final RequestException cause) {
         this.cause = Preconditions.checkNotNull(cause);
-        LOG.debug("Skipping reconnect of already-reconnecting connection {}", this);
+        LOG.warn("Skipping reconnect of already-reconnecting connection {}", this);
         return current;
     }
 
index 9fd3a21..3a2abbe 100644 (file)
@@ -117,15 +117,6 @@ public abstract class AbstractClientConnectionTest<T extends AbstractClientConne
         Assert.assertFalse(timeout.isPresent());
     }
 
-    @Test
-    public void testCheckTimeoutConnectionTimeouted() throws Exception {
-        final Consumer<Response<?, ?>> callback = mock(Consumer.class);
-        connection.sendRequest(createRequest(replyToProbe.ref()), callback);
-        final long now = context.ticker().read() + ConnectedClientConnection.BACKEND_ALIVE_TIMEOUT_NANOS;
-        final Optional<Long> timeout = connection.checkTimeout(now);
-        Assert.assertNull(timeout);
-    }
-
     @Test
     public void testCheckTimeout() throws Exception {
         final Consumer<Response<?, ?>> callback = mock(Consumer.class);
index e66512d..29cac23 100644 (file)
@@ -12,13 +12,26 @@ import static org.mockito.Matchers.same;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import java.util.Optional;
+import java.util.function.Consumer;
+import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 import org.opendaylight.controller.cluster.access.concepts.RequestException;
+import org.opendaylight.controller.cluster.access.concepts.Response;
 
 public class ConnectedClientConnectionTest
         extends AbstractClientConnectionTest<ConnectedClientConnection<BackendInfo>, BackendInfo> {
 
+    @Test
+    public void testCheckTimeoutConnectionTimedout() throws Exception {
+        final Consumer<Response<?, ?>> callback = mock(Consumer.class);
+        connection.sendRequest(createRequest(replyToProbe.ref()), callback);
+        final long now = context.ticker().read() + ConnectedClientConnection.BACKEND_ALIVE_TIMEOUT_NANOS;
+        final Optional<Long> timeout = connection.checkTimeout(now);
+        Assert.assertNull(timeout);
+    }
+
     @Override
     protected ConnectedClientConnection<BackendInfo> createConnection() {
         final BackendInfo backend = new BackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, 10);
index b36dd7c..a281b12 100644 (file)
@@ -12,6 +12,7 @@ import static org.mockito.Mockito.after;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import java.util.Optional;
 import java.util.function.Consumer;
 import org.junit.Assert;
 import org.junit.Test;
@@ -29,6 +30,16 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier
 public class ReconnectingClientConnectionTest
         extends AbstractClientConnectionTest<ReconnectingClientConnection<BackendInfo>, BackendInfo> {
 
+    @Test
+    public void testCheckTimeoutConnectionTimedout() throws Exception {
+        final Consumer<Response<?, ?>> callback = mock(Consumer.class);
+        connection.sendRequest(createRequest(replyToProbe.ref()), callback);
+        final long now = context.ticker().read() + ConnectedClientConnection.BACKEND_ALIVE_TIMEOUT_NANOS;
+        final Optional<Long> timeout = connection.checkTimeout(now);
+        Assert.assertNotNull(timeout);
+        Assert.assertTrue(timeout.isPresent());
+    }
+
     @Override
     protected ReconnectingClientConnection<BackendInfo> createConnection() {
         final BackendInfo backend = new BackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, 10);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.