Elffuss BraidHub

kikocis/java-driver public

Fix bug in prevention against concurrent retries (JAVA-449).
Changesetda7a01eee420c6b0e1dcb60deddbb0da98bf11b476d9ac529813980b33d64bab
Authorolim7t <omichallat+github@gmail.com> · 2014-09-25 00:19 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-09-25 09:12 +02:00
Parents1dbe77eef4e5

Browse the files at this changeset

1 file changed

modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +14 −1
@@ -28,6 +28,8 @@
2828 import java.util.concurrent.locks.Lock;
2929 import java.util.concurrent.locks.ReentrantLock;
3030
31+import com.google.common.util.concurrent.Futures;
32+
3133 import com.codahale.metrics.Timer;
3234 import org.slf4j.Logger;
3335 import org.slf4j.LoggerFactory;
@@ -115,6 +117,9 @@
115117 }
116118
117119 private boolean query(Host host) {
120+ // Reset this because we use it later to detect if a failure occurred before or after the request was sent
121+ connectionHandler = null;
122+
118123 currentPool = manager.pools.get(host);
119124 if (currentPool == null || currentPool.isClosed())
120125 return false;
@@ -171,7 +176,15 @@
171176 // We lock to prevent two retries from launching concurrently
172177 retryLock.lock();
173178
174- if (currentRetry != null && !currentRetry.isDone())
179+ // If we have no handler, this means the error that triggered this retry occurred while
180+ // sending the query to Cassandra. In that case, the retry might occur synchronously with
181+ // the error (see Connection#writeHandler).
182+ // But if this error already occurred on a retry, the previous retry is in currentRetry
183+ // and is not finished (since it's waiting for this method to complete), but we don't
184+ // want to ignore the second retry.
185+ boolean isSynchronousRetry = connectionHandler == null;
186+
187+ if (currentRetry != null && !currentRetry.isDone() && !isSynchronousRetry)
175188 return;
176189
177190 final Host h = current;