kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 4681450154083dc1a92b46d6df3e501e276d51653e17c1831ad0fe4b2a23d0d6 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-11-03 10:48 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-11-03 11:32 +01:00 |
| Parents | 3078155ae93f |
1 file changed
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +23 −5
| @@ -1190,19 +1190,37 @@ | ||
| 1190 | 1190 | // Now that the control connection is ready, we have all the information we need about the nodes (datacenter, |
| 1191 | 1191 | // rack...) to initialize the load balancing policy |
| 1192 | 1192 | loadBalancingPolicy().init(Cluster.this, contactPointHosts); |
| 1193 | - for (Host host : downContactPointHosts) | |
| 1193 | + for (Host host : downContactPointHosts) { | |
| 1194 | 1194 | loadBalancingPolicy().onDown(host); |
| 1195 | + for (Host.StateListener listener : listeners) | |
| 1196 | + listener.onDown(host); | |
| 1197 | + } | |
| 1195 | 1198 | |
| 1196 | - // Add the remaining hosts that were discovered by the control connection: | |
| 1197 | 1199 | for (Host host : metadata.allHosts()) { |
| 1200 | + // If the host is down at this stage, it's a contact point that the control connection failed to reach. | |
| 1201 | + // Reconnection attempts are already scheduled, and the LBP and listeners have been notified above. | |
| 1202 | + if (host.state == Host.State.DOWN) continue; | |
| 1203 | + | |
| 1204 | + // Otherwise, we want to do the equivalent of onAdd(). But since we know for sure that no sessions or prepared | |
| 1205 | + // statements exist at this point, we can skip some of the steps (plus this avoids scheduling concurrent pool | |
| 1206 | + // creations if a session is created right after this method returns). | |
| 1207 | + logger.info("New Cassandra host {} added", host); | |
| 1208 | + | |
| 1209 | + if (connectionFactory.protocolVersion == 2 && !supportsProtocolV2(host)) { | |
| 1210 | + logUnsupportedVersionProtocol(host); | |
| 1211 | + continue; | |
| 1212 | + } | |
| 1213 | + | |
| 1198 | 1214 | if (!contactPointHosts.contains(host)) |
| 1199 | 1215 | loadBalancingPolicy().onAdd(host); |
| 1216 | + | |
| 1217 | + host.setUp(); | |
| 1218 | + | |
| 1219 | + for (Host.StateListener listener : listeners) | |
| 1220 | + listener.onAdd(host); | |
| 1200 | 1221 | } |
| 1201 | 1222 | isFullyInit = true; |
| 1202 | 1223 | |
| 1203 | - for (Host host : metadata.allHosts()) | |
| 1204 | - if (host.state != Host.State.DOWN) triggerOnAdd(host); | |
| 1205 | - | |
| 1206 | 1224 | return; |
| 1207 | 1225 | } catch (UnsupportedProtocolVersionException e) { |
| 1208 | 1226 | assert connectionFactory.protocolVersion < 1; |