kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 3078155ae93f4593c1af39c7bafbebf76222098770592c72a4a263e48d6f84dc |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-31 12:40 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-11-03 11:28 +01:00 |
| Parents | a56267f89c4b |
3 files changed
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +15 −1
| @@ -1180,9 +1180,19 @@ | ||
| 1180 | 1180 | if (connectionFactory.protocolVersion < 0) |
| 1181 | 1181 | connectionFactory.protocolVersion = 2; |
| 1182 | 1182 | |
| 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 | + | |
| 1183 | 1190 | // Now that the control connection is ready, we have all the information we need about the nodes (datacenter, |
| 1184 | 1191 | // rack...) to initialize the load balancing policy |
| 1185 | 1192 | loadBalancingPolicy().init(Cluster.this, contactPointHosts); |
| 1193 | + for (Host host : downContactPointHosts) | |
| 1194 | + loadBalancingPolicy().onDown(host); | |
| 1195 | + | |
| 1186 | 1196 | // Add the remaining hosts that were discovered by the control connection: |
| 1187 | 1197 | for (Host host : metadata.allHosts()) { |
| 1188 | 1198 | if (!contactPointHosts.contains(host)) |
| @@ -1191,7 +1201,7 @@ | ||
| 1191 | 1201 | isFullyInit = true; |
| 1192 | 1202 | |
| 1193 | 1203 | for (Host host : metadata.allHosts()) |
| 1194 | - triggerOnAdd(host); | |
| 1204 | + if (host.state != Host.State.DOWN) triggerOnAdd(host); | |
| 1195 | 1205 | |
| 1196 | 1206 | return; |
| 1197 | 1207 | } catch (UnsupportedProtocolVersionException e) { |
| @@ -1524,6 +1534,10 @@ | ||
| 1524 | 1534 | |
| 1525 | 1535 | // Note: we basically waste the first successful reconnection, but it's probably not a big deal |
| 1526 | 1536 | logger.debug("{} is down, scheduling connection retries", host); |
| 1537 | + startPeriodicReconnectionAttempt(host, isHostAddition); | |
| 1538 | + } | |
| 1539 | + | |
| 1540 | + void startPeriodicReconnectionAttempt(final Host host, final boolean isHostAddition) { | |
| 1527 | 1541 | new AbstractReconnectionHandler(reconnectionExecutor, reconnectionPolicy().newSchedule(), host.reconnectionAttempt) { |
| 1528 | 1542 | |
| 1529 | 1543 | 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 @@ | ||
| 186 | 186 | return tryConnect(host, isInitialConnection); |
| 187 | 187 | } catch (ConnectionException e) { |
| 188 | 188 | 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 | + } | |
| 189 | 195 | } catch (ExecutionException e) { |
| 190 | 196 | errors = logError(host, e.getCause(), errors, iter); |
| 191 | 197 | } catch (UnsupportedProtocolVersionException e) { |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +2 −1
| @@ -67,7 +67,8 @@ | ||
| 67 | 67 | // Create pool to initial nodes (and wait for them to be created) |
| 68 | 68 | for (Host host : cluster.getMetadata().allHosts()) { |
| 69 | 69 | try { |
| 70 | - maybeAddPool(host, executor()).get(); | |
| 70 | + if (host.state != Host.State.DOWN) | |
| 71 | + maybeAddPool(host, executor()).get(); | |
| 71 | 72 | } catch (ExecutionException e) { |
| 72 | 73 | // This is not supposed to happen |
| 73 | 74 | throw new DriverInternalError(e); |