Elffuss BraidHub

kikocis/java-driver public

Don't trigger onAdd in Cluster.Manager.init (JAVA-522).
Changeset4681450154083dc1a92b46d6df3e501e276d51653e17c1831ad0fe4b2a23d0d6
Authorolim7t <omichallat+github@gmail.com> · 2014-11-03 10:48 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-11-03 11:32 +01:00
Parents3078155ae93f

Browse the files at this changeset

1 file changed

modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +23 −5
@@ -1190,19 +1190,37 @@
11901190 // Now that the control connection is ready, we have all the information we need about the nodes (datacenter,
11911191 // rack...) to initialize the load balancing policy
11921192 loadBalancingPolicy().init(Cluster.this, contactPointHosts);
1193- for (Host host : downContactPointHosts)
1193+ for (Host host : downContactPointHosts) {
11941194 loadBalancingPolicy().onDown(host);
1195+ for (Host.StateListener listener : listeners)
1196+ listener.onDown(host);
1197+ }
11951198
1196- // Add the remaining hosts that were discovered by the control connection:
11971199 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+
11981214 if (!contactPointHosts.contains(host))
11991215 loadBalancingPolicy().onAdd(host);
1216+
1217+ host.setUp();
1218+
1219+ for (Host.StateListener listener : listeners)
1220+ listener.onAdd(host);
12001221 }
12011222 isFullyInit = true;
12021223
1203- for (Host host : metadata.allHosts())
1204- if (host.state != Host.State.DOWN) triggerOnAdd(host);
1205-
12061224 return;
12071225 } catch (UnsupportedProtocolVersionException e) {
12081226 assert connectionFactory.protocolVersion < 1;