Elffuss BraidHub

kikocis/java-driver public

Don't connect to nodes that are ignored by the load balancing policy

JAVA-270 #fixes
Changesetf34fbd38244733ba9474c48d2696371b13782d4964aa4f222c844bdc4d5f0925
AuthorSylvain Lebresne <sylvain@datastax.com> · 2014-02-25 17:42 +01:00
CommitterSylvain Lebresne <sylvain@datastax.com> · 2014-02-25 17:42 +01:00
Parents4561005cff1a

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -14,6 +14,8 @@
1414 - [bug] Use date string in query build to work-around CASSANDRA-6718 (JAVA-264)
1515 - [bug] Always return the PreparedStatement object that is cache internally (JAVA-263)
1616 - [bug] Fix race when multiple connect are done in parallel (JAVA-261)
17+- [bug] Don't connect at all to nodes that are ignored by the load balancing
18+ policy (JAVA-270)
1719
1820
1921 1.0.5:
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +17 −1
@@ -1020,6 +1020,23 @@
10201020 if (isShutdown.get())
10211021 return;
10221022
1023+ // Adds to the load balancing first and foremost, as doing so might change the decision
1024+ // it will make for distance() on that node (not likely but we leave that possibility).
1025+ // This does mean the policy may start returning that node for query plan, but as long
1026+ // as no pools have been created (below) this will be ignored by RequestHandler so it's fine.
1027+ loadBalancingPolicy().onAdd(host);
1028+
1029+ // Next, if the host should be ignored, well, ignore it.
1030+ if (loadBalancingPolicy().distance(host) == HostDistance.IGNORED) {
1031+ // We still mark the node UP though as it should be (and notifiy the listeners).
1032+ // We'll mark it down if we have a notification anyway and we've documented that especially
1033+ // for IGNORED hosts, the isUp() method was a best effort guess
1034+ host.setUp();
1035+ for (Host.StateListener listener : listeners)
1036+ listener.onAdd(host);
1037+ return;
1038+ }
1039+
10231040 try {
10241041 prepareAllQueries(host);
10251042 } catch (InterruptedException e) {
@@ -1027,7 +1044,6 @@
10271044 // Don't propagate because we don't want to prevent other listener to run
10281045 }
10291046
1030- loadBalancingPolicy().onAdd(host);
10311047 controlConnection.onAdd(host);
10321048
10331049 List<ListenableFuture<Boolean>> futures = new ArrayList<ListenableFuture<Boolean>>(sessions.size());