Elffuss BraidHub

kikocis/java-driver public

Mark failing contact points down in control connection init (JAVA-522).
Changeset3078155ae93f4593c1af39c7bafbebf76222098770592c72a4a263e48d6f84dc
Authorolim7t <omichallat+github@gmail.com> · 2014-10-31 12:40 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-11-03 11:28 +01:00
Parentsa56267f89c4b

Browse the files at this changeset

3 files changed

modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +15 −1
@@ -1180,9 +1180,19 @@
11801180 if (connectionFactory.protocolVersion < 0)
11811181 connectionFactory.protocolVersion = 2;
11821182
1183+ // The control connection can mark hosts down if it failed to connect to them, separate them
1184+ Set<Host> downContactPointHosts = Sets.newHashSet();
1185+ for (Host host : contactPointHosts)
1186+ if (host.state == Host.State.DOWN)
1187+ downContactPointHosts.add(host);
1188+ contactPointHosts.removeAll(downContactPointHosts);
1189+
11831190 // Now that the control connection is ready, we have all the information we need about the nodes (datacenter,
11841191 // rack...) to initialize the load balancing policy
11851192 loadBalancingPolicy().init(Cluster.this, contactPointHosts);
1193+ for (Host host : downContactPointHosts)
1194+ loadBalancingPolicy().onDown(host);
1195+
11861196 // Add the remaining hosts that were discovered by the control connection:
11871197 for (Host host : metadata.allHosts()) {
11881198 if (!contactPointHosts.contains(host))
@@ -1191,7 +1201,7 @@
11911201 isFullyInit = true;
11921202
11931203 for (Host host : metadata.allHosts())
1194- triggerOnAdd(host);
1204+ if (host.state != Host.State.DOWN) triggerOnAdd(host);
11951205
11961206 return;
11971207 } catch (UnsupportedProtocolVersionException e) {
@@ -1524,6 +1534,10 @@
15241534
15251535 // Note: we basically waste the first successful reconnection, but it's probably not a big deal
15261536 logger.debug("{} is down, scheduling connection retries", host);
1537+ startPeriodicReconnectionAttempt(host, isHostAddition);
1538+ }
1539+
1540+ void startPeriodicReconnectionAttempt(final Host host, final boolean isHostAddition) {
15271541 new AbstractReconnectionHandler(reconnectionExecutor, reconnectionPolicy().newSchedule(), host.reconnectionAttempt) {
15281542
15291543 protected Connection tryReconnect() throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException {
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +6 −0
@@ -186,6 +186,12 @@
186186 return tryConnect(host, isInitialConnection);
187187 } catch (ConnectionException e) {
188188 errors = logError(host, e, errors, iter);
189+ if (isInitialConnection) {
190+ // Mark the host down right away so that we don't try it again during the initialization process.
191+ // We don't call cluster.triggerOnDown because it does a bunch of other things we don't want to do here (notify LBP, etc.)
192+ host.setDown();
193+ cluster.startPeriodicReconnectionAttempt(host, true);
194+ }
189195 } catch (ExecutionException e) {
190196 errors = logError(host, e.getCause(), errors, iter);
191197 } catch (UnsupportedProtocolVersionException e) {
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +2 −1
@@ -67,7 +67,8 @@
6767 // Create pool to initial nodes (and wait for them to be created)
6868 for (Host host : cluster.getMetadata().allHosts()) {
6969 try {
70- maybeAddPool(host, executor()).get();
70+ if (host.state != Host.State.DOWN)
71+ maybeAddPool(host, executor()).get();
7172 } catch (ExecutionException e) {
7273 // This is not supposed to happen
7374 throw new DriverInternalError(e);