diff --git a/changelog/README.md b/changelog/README.md index ed4598f2865..80c2b0c093e 100644 --- a/changelog/README.md +++ b/changelog/README.md @@ -4,6 +4,7 @@ - [improvement] Change default consistency level to LOCAL_QUORUM (JAVA-926) - [bug] Fix implementation of UserType.hashCode() (JAVA-942) +- [improvement] Don't delay UP/ADDED notifications if protocol version = V4 (JAVA-877) ### 3.0.0-alpha3 diff --git a/driver-core/src/main/java/com/datastax/driver/core/Cluster.java b/driver-core/src/main/java/com/datastax/driver/core/Cluster.java index eaacbba9186..a1fba2f4273 100644 --- a/driver-core/src/main/java/com/datastax/driver/core/Cluster.java +++ b/driver-core/src/main/java/com/datastax/driver/core/Cluster.java @@ -2586,26 +2586,31 @@ private ListenableFuture execute(ExceptionCatchingRunnable task) { private ListenableFuture schedule(final ExceptionCatchingRunnable task) { // Cassandra tends to send notifications for new/up nodes a bit early (it is triggered once // gossip is up, but that is before the client-side server is up), so we add a delay - // (otherwise the connection will likely fail and have to be retry which is wasteful). This - // probably should be fixed C* side, after which we'll be able to remove this. - final SettableFuture future = SettableFuture.create(); - scheduledTasksExecutor.schedule(new ExceptionCatchingRunnable() { - public void runMayThrow() throws Exception { - ListenableFuture f = execute(task); - Futures.addCallback(f, new FutureCallback() { - @Override - public void onSuccess(Object result) { - future.set(null); - } + // (otherwise the connection will likely fail and have to be retry which is wasteful). + // This has been fixed by CASSANDRA-8236 and does not apply to protocol versions >= 4 + // and C* versions >= 2.2.0 + if (protocolVersion().compareTo(ProtocolVersion.V4) < 0) { + final SettableFuture future = SettableFuture.create(); + scheduledTasksExecutor.schedule(new ExceptionCatchingRunnable() { + public void runMayThrow() throws Exception { + ListenableFuture f = execute(task); + Futures.addCallback(f, new FutureCallback() { + @Override + public void onSuccess(Object result) { + future.set(null); + } - @Override - public void onFailure(Throwable t) { - future.setException(t); - } - }); - } - }, NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS); - return future; + @Override + public void onFailure(Throwable t) { + future.setException(t); + } + }); + } + }, NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS); + return future; + } else { + return execute(task); + } } // Make sure we call controlConnection.refreshNodeInfo(host)