kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 7704c9cd2ab647886cf4bbb9f0258b5453cf6d1ed45bdc6f97aae71b676f66d6 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-09-27 19:05 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-09-27 19:05 +02:00 |
| Parents | b179b5053c92 |
2 files changed
modified driver-core/CHANGELOG.rst +0 −1
| @@ -5,7 +5,6 @@ | ||
| 5 | 5 | ------ |
| 6 | 6 | |
| 7 | 7 | - [bug] Handle null pool in PooledConnection.release (JAVA-449) |
| 8 | -- [bug] Prevent concurrent retries of the same query (JAVA-449) | |
| 9 | 8 | - [improvement] Defunct connection on request timeout (JAVA-425) |
| 10 | 9 | - [improvement] Try next host when we get a SERVER_ERROR (JAVA-426) |
| 11 | 10 |
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +18 −33
| @@ -24,9 +24,8 @@ | ||
| 24 | 24 | import java.util.Iterator; |
| 25 | 25 | import java.util.List; |
| 26 | 26 | import java.util.Map; |
| 27 | -import java.util.concurrent.*; | |
| 28 | -import java.util.concurrent.locks.Lock; | |
| 29 | -import java.util.concurrent.locks.ReentrantLock; | |
| 27 | +import java.util.concurrent.TimeUnit; | |
| 28 | +import java.util.concurrent.TimeoutException; | |
| 30 | 29 | |
| 31 | 30 | import com.codahale.metrics.Timer; |
| 32 | 31 | import org.slf4j.Logger; |
| @@ -72,10 +71,6 @@ | ||
| 72 | 71 | private final Timer.Context timerContext; |
| 73 | 72 | private final long startTime; |
| 74 | 73 | |
| 75 | - // Tracks whether there is a retry already in progress | |
| 76 | - private final Lock retryLock = new ReentrantLock(); | |
| 77 | - private Future<?> currentRetry; // guarded by retryLock | |
| 78 | - | |
| 79 | 74 | public RequestHandler(SessionManager manager, Callback callback, Statement statement) { |
| 80 | 75 | this.manager = manager; |
| 81 | 76 | this.callback = callback; |
| @@ -167,34 +162,24 @@ | ||
| 167 | 162 | } |
| 168 | 163 | |
| 169 | 164 | private void retry(final boolean retryCurrent, ConsistencyLevel newConsistencyLevel) { |
| 170 | - try { | |
| 171 | - // We lock to prevent two retries from launching concurrently | |
| 172 | - retryLock.lock(); | |
| 173 | - | |
| 174 | - if (currentRetry != null && !currentRetry.isDone()) | |
| 175 | - return; | |
| 176 | - | |
| 177 | - final Host h = current; | |
| 178 | - this.retryConsistencyLevel = newConsistencyLevel; | |
| 179 | - | |
| 180 | - // We should not retry on the current thread as this will be an IO thread. | |
| 181 | - currentRetry = manager.executor().submit(new Runnable() { | |
| 182 | - @Override | |
| 183 | - public void run() { | |
| 184 | - try { | |
| 185 | - if (retryCurrent) { | |
| 186 | - if (query(h)) | |
| 187 | - return; | |
| 188 | - } | |
| 189 | - sendRequest(); | |
| 190 | - } catch (Exception e) { | |
| 191 | - setFinalException(null, new DriverInternalError("Unexpected exception while retrying query", e)); | |
| 165 | + final Host h = current; | |
| 166 | + this.retryConsistencyLevel = newConsistencyLevel; | |
| 167 | + | |
| 168 | + // We should not retry on the current thread as this will be an IO thread. | |
| 169 | + manager.executor().execute(new Runnable() { | |
| 170 | + @Override | |
| 171 | + public void run() { | |
| 172 | + try { | |
| 173 | + if (retryCurrent) { | |
| 174 | + if (query(h)) | |
| 175 | + return; | |
| 192 | 176 | } |
| 177 | + sendRequest(); | |
| 178 | + } catch (Exception e) { | |
| 179 | + setFinalException(null, new DriverInternalError("Unexpected exception while retrying query", e)); | |
| 193 | 180 | } |
| 194 | - }); | |
| 195 | - } finally { | |
| 196 | - retryLock.unlock(); | |
| 197 | - } | |
| 181 | + } | |
| 182 | + }); | |
| 198 | 183 | } |
| 199 | 184 | |
| 200 | 185 | public void cancel() { |