kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 270420cb6eb6748acaa8022a5cace3dd090187dca980ea87323f2fef1ea7d590 |
|---|---|
| Author | Sylvain Lebresne <sylvain@datastax.com> · 2014-03-20 11:22 +01:00 |
| Committer | Sylvain Lebresne <sylvain@datastax.com> · 2014-03-20 11:22 +01:00 |
| Parents | 0f1528ccd351 |
3 files changed
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +0 −1
| @@ -221,4 +221,3 @@ | ||
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | - |
modified driver-core/src/main/java/com/datastax/driver/core/PooledConnection.java +1 −2
| @@ -33,8 +33,7 @@ | ||
| 33 | 33 | * Return the pooled connection to it's pool. |
| 34 | 34 | * The connection should generally not be reuse after that. |
| 35 | 35 | */ |
| 36 | - public void release() | |
| 37 | - { | |
| 36 | + public void release() { | |
| 38 | 37 | pool.returnConnection(this); |
| 39 | 38 | } |
| 40 | 39 | } |
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +51 −31
| @@ -160,11 +160,15 @@ | ||
| 160 | 160 | manager.executor().execute(new Runnable() { |
| 161 | 161 | @Override |
| 162 | 162 | public void run() { |
| 163 | - if (retryCurrent) { | |
| 164 | - if (query(h)) | |
| 165 | - return; | |
| 163 | + try { | |
| 164 | + if (retryCurrent) { | |
| 165 | + if (query(h)) | |
| 166 | + return; | |
| 167 | + } | |
| 168 | + sendRequest(); | |
| 169 | + } catch (Exception e) { | |
| 170 | + setFinalException(null, new DriverInternalError("Unexpected exception while retrying query", e)); | |
| 166 | 171 | } |
| 167 | - sendRequest(); | |
| 168 | 172 | } |
| 169 | 173 | }); |
| 170 | 174 | } |
| @@ -196,33 +200,40 @@ | ||
| 196 | 200 | } |
| 197 | 201 | |
| 198 | 202 | private void setFinalResult(Connection connection, Message.Response response) { |
| 199 | - if (timerContext != null) | |
| 200 | - timerContext.stop(); | |
| 201 | - | |
| 202 | - ExecutionInfo info = current.defaultExecutionInfo; | |
| 203 | - if (triedHosts != null) | |
| 204 | - { | |
| 205 | - triedHosts.add(current); | |
| 206 | - info = new ExecutionInfo(triedHosts); | |
| 203 | + try { | |
| 204 | + if (timerContext != null) | |
| 205 | + timerContext.stop(); | |
| 206 | + | |
| 207 | + ExecutionInfo info = current.defaultExecutionInfo; | |
| 208 | + if (triedHosts != null) | |
| 209 | + { | |
| 210 | + triedHosts.add(current); | |
| 211 | + info = new ExecutionInfo(triedHosts); | |
| 212 | + } | |
| 213 | + if (retryConsistencyLevel != null) | |
| 214 | + info = info.withAchievedConsistency(retryConsistencyLevel); | |
| 215 | + callback.onSet(connection, response, info, System.nanoTime() - startTime); | |
| 216 | + } catch (Exception e) { | |
| 217 | + callback.onException(connection, new DriverInternalError("Unexpected exception while setting final result from " + response, e), System.nanoTime() - startTime); | |
| 207 | 218 | } |
| 208 | - if (retryConsistencyLevel != null) | |
| 209 | - info = info.withAchievedConsistency(retryConsistencyLevel); | |
| 210 | - callback.onSet(connection, response, info, System.nanoTime() - startTime); | |
| 211 | 219 | } |
| 212 | 220 | |
| 213 | 221 | private void setFinalException(Connection connection, Exception exception) { |
| 214 | - if (timerContext != null) | |
| 215 | - timerContext.stop(); | |
| 216 | - callback.onException(connection, exception, System.nanoTime() - startTime); | |
| 222 | + try { | |
| 223 | + if (timerContext != null) | |
| 224 | + timerContext.stop(); | |
| 225 | + } finally { | |
| 226 | + callback.onException(connection, exception, System.nanoTime() - startTime); | |
| 227 | + } | |
| 217 | 228 | } |
| 218 | 229 | |
| 219 | 230 | @Override |
| 220 | 231 | public void onSet(Connection connection, Message.Response response, long latency) { |
| 221 | - if (connection instanceof PooledConnection) | |
| 222 | - ((PooledConnection)connection).release(); | |
| 223 | - | |
| 224 | 232 | Host queriedHost = current; |
| 225 | 233 | try { |
| 234 | + if (connection instanceof PooledConnection) | |
| 235 | + ((PooledConnection)connection).release(); | |
| 236 | + | |
| 226 | 237 | switch (response.type) { |
| 227 | 238 | case RESULT: |
| 228 | 239 | setFinalResult(connection, response); |
| @@ -405,11 +416,12 @@ | ||
| 405 | 416 | |
| 406 | 417 | @Override |
| 407 | 418 | public void onException(Connection connection, Exception exception, long latency) { |
| 408 | - if (connection instanceof PooledConnection) | |
| 409 | - ((PooledConnection)connection).release(); | |
| 410 | 419 | |
| 411 | 420 | Host queriedHost = current; |
| 412 | 421 | try { |
| 422 | + if (connection instanceof PooledConnection) | |
| 423 | + ((PooledConnection)connection).release(); | |
| 424 | + | |
| 413 | 425 | if (exception instanceof ConnectionException) { |
| 414 | 426 | if (metricsEnabled()) |
| 415 | 427 | metrics().getErrorMetrics().getConnectionErrors().inc(); |
| @@ -420,6 +432,9 @@ | ||
| 420 | 432 | } |
| 421 | 433 | |
| 422 | 434 | setFinalException(connection, exception); |
| 435 | + } catch (Exception e) { | |
| 436 | + // This shouldn't happen, but if it does, we want to signal the callback, not let him hang indefinitively | |
| 437 | + setFinalException(null, new DriverInternalError("An unexpected error happened while handling exception " + exception, e)); | |
| 423 | 438 | } finally { |
| 424 | 439 | if (queriedHost != null) |
| 425 | 440 | manager.cluster.manager.reportLatency(queriedHost, latency); |
| @@ -428,15 +443,20 @@ | ||
| 428 | 443 | |
| 429 | 444 | @Override |
| 430 | 445 | public void onTimeout(Connection connection, long latency) { |
| 431 | - if (connection instanceof PooledConnection) | |
| 432 | - ((PooledConnection)connection).release(); | |
| 433 | - | |
| 434 | 446 | Host queriedHost = current; |
| 435 | - logError(connection.address, "Timeout during read"); | |
| 436 | - retry(false, null); | |
| 437 | - | |
| 438 | - if (queriedHost != null) | |
| 439 | - manager.cluster.manager.reportLatency(queriedHost, latency); | |
| 447 | + try { | |
| 448 | + if (connection instanceof PooledConnection) | |
| 449 | + ((PooledConnection)connection).release(); | |
| 450 | + | |
| 451 | + logError(connection.address, "Timeout during read"); | |
| 452 | + retry(false, null); | |
| 453 | + } catch (Exception e) { | |
| 454 | + // This shouldn't happen, but if it does, we want to signal the callback, not let him hang indefinitively | |
| 455 | + setFinalException(null, new DriverInternalError("An unexpected error happened while handling timeout", e)); | |
| 456 | + } finally { | |
| 457 | + if (queriedHost != null) | |
| 458 | + manager.cluster.manager.reportLatency(queriedHost, latency); | |
| 459 | + } | |
| 440 | 460 | } |
| 441 | 461 | |
| 442 | 462 | interface Callback extends Connection.ResponseCallback { |