Elffuss BraidHub

kikocis/java-driver public

Fix bug when SUSPECT reconnection succeeds, but one of the pooled connections fails while bringing the node back up (JAVA-577).
Changesete4b963e48dcf307907a68a036f33dad6e2b411f067fda3d37723b00ecb976573
Authorolim7t <omichallat+github@gmail.com> · 2014-12-14 19:02 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-12-14 20:57 +01:00
Parents45a7e96c0cf9

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -12,6 +12,8 @@
1212 - [bug] Avoid deadlock when multiple connections to the same host get write
1313 errors (JAVA-557)
1414 - [improvement] Make shuffle=true the default for TokenAwarePolicy (JAVA-504)
15+- [bug] Fix bug when SUSPECT reconnection succeeds, but one of the pooled
16+ connections fails while bringing the node back up (JAVA-577)
1517
1618
1719 2.0.8:
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +17 −4
@@ -26,6 +26,7 @@
2626 import java.util.concurrent.atomic.AtomicReference;
2727
2828 import com.google.common.annotations.VisibleForTesting;
29+import com.google.common.base.Function;
2930 import com.google.common.base.Predicates;
3031 import com.google.common.collect.*;
3132 import com.google.common.util.concurrent.*;
@@ -1501,15 +1502,23 @@
15011502 host.initialReconnectionAttempt.set(executor.submit(new ExceptionCatchingRunnable() {
15021503 @Override
15031504 public void runMayThrow() throws InterruptedException, ExecutionException {
1505+ boolean success;
15041506 try {
15051507 // TODO: as for the ReconnectionHandler, we could avoid "wasting" this connection
15061508 connectionFactory.open(host).closeAsync();
15071509 // Note that we want to do the pool creation on this thread because we want that
15081510 // when onUp return, the host is ready for querying
15091511 onUp(host, MoreExecutors.sameThreadExecutor());
1512+ // If one of the connections in onUp failed, it signaled the error and triggerd onDown,
1513+ // but onDown aborted because this reconnection attempt was in progress (JAVA-577).
1514+ // Test the state now to check than onUp succeeded (we know it's up-to-date since onUp was
1515+ // executed synchronously).
1516+ success = host.state == Host.State.UP;
15101517 } catch (Exception e) {
1511- onDown(host, false, true);
1518+ success = false;
15121519 }
1520+ if (!success)
1521+ onDown(host, false, true);
15131522 }
15141523 }));
15151524
@@ -1531,19 +1540,23 @@
15311540 if (isClosed())
15321541 return;
15331542
1534- // If we're SUSPECT and not the task validating the suspection, then some other task is
1543+ // If we're SUSPECT and not the task validating the suspicion, then some other task is
15351544 // already checking to verify if the node is really down (or if it's simply that the
15361545 // connections where broken). So just skip this in that case.
1537- if (!isSuspectedVerification && host.state == Host.State.SUSPECT)
1546+ if (!isSuspectedVerification && host.state == Host.State.SUSPECT) {
1547+ logger.debug("Aborting onDown because a reconnection is running on SUSPECT host {}", host);
15381548 return;
1549+ }
15391550
15401551 // Note: we don't want to skip that method if !host.isUp() because we set isUp
15411552 // late in onUp, and so we can rely on isUp if there is an error during onUp.
15421553 // But if there is a reconnection attempt in progress already, then we know
15431554 // we've already gone through that method since the last successful onUp(), so
15441555 // we're good skipping it.
1545- if (host.reconnectionAttempt.get() != null)
1556+ if (host.reconnectionAttempt.get() != null) {
1557+ logger.debug("Aborting onDown because a reconnection is running on DOWN host {}", host);
15461558 return;
1559+ }
15471560
15481561 // Remember if we care about this node at all. We must call this before
15491562 // we've signalled the load balancing policy, since most policy will always