kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 0707b5d7e98b4733c33498a6e34e7f221c3fe578540acf292669079064da3170 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-02-06 13:44 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-02-11 12:28 +01:00 |
| Parents | 3b424b26e723 |
4 files changed
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +1 −1
| @@ -833,7 +833,7 @@ | ||
| 833 | 833 | public boolean onTimeout(Connection connection, long latency, int retryCount) { |
| 834 | 834 | assert connection != null; // We always timeout on a specific connection, so this shouldn't be null |
| 835 | 835 | this.address = connection.address; |
| 836 | - super.setException(new ConnectionException(connection.address, "Operation timed out")); | |
| 836 | + super.setException(new OperationTimedOutException(connection.address)); | |
| 837 | 837 | return true; |
| 838 | 838 | } |
| 839 | 839 |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +1 −1
| @@ -141,7 +141,7 @@ | ||
| 141 | 141 | public boolean onTimeout(Connection connection, long latency, int retryCount) { |
| 142 | 142 | // This is only called for internal calls (i.e, when the future is not wrapped in RequestHandler). |
| 143 | 143 | // So just set an exception for the final result, which should be handled correctly by said internal call. |
| 144 | - setException(new ConnectionException(connection.address, "Operation timed out")); | |
| 144 | + setException(new OperationTimedOutException(connection.address)); | |
| 145 | 145 | return true; |
| 146 | 146 | } |
| 147 | 147 |
added driver-core/src/main/java/com/datastax/driver/core/OperationTimedOutException.java +13 −0
| @@ -0,0 +1,13 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import java.net.InetSocketAddress; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Thrown on a client-side timeout, i.e. when the client didn't hear back from the server within | |
| 7 | + * {@link SocketOptions#getReadTimeoutMillis()}. | |
| 8 | + */ | |
| 9 | +class OperationTimedOutException extends ConnectionException { | |
| 10 | + public OperationTimedOutException(InetSocketAddress address) { | |
| 11 | + super(address, "Operation timed out"); | |
| 12 | + } | |
| 13 | +} |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +4 −1
| @@ -516,6 +516,7 @@ | ||
| 516 | 516 | // Let's not wait too long if we can't get a connection. Things |
| 517 | 517 | // will fix themselves once the user tries a query anyway. |
| 518 | 518 | PooledConnection c = null; |
| 519 | + boolean timedOut = false; | |
| 519 | 520 | try { |
| 520 | 521 | c = entry.getValue().borrowConnection(200, TimeUnit.MILLISECONDS); |
| 521 | 522 | c.write(new Requests.Prepare(query)).get(); |
| @@ -529,8 +530,10 @@ | ||
| 529 | 530 | // We shouldn't really get exception while preparing a |
| 530 | 531 | // query, so log this (but ignore otherwise as it's not a big deal) |
| 531 | 532 | logger.error(String.format("Unexpected error while preparing query (%s) on %s", query, entry.getKey()), e); |
| 533 | + // If the query timed out, that already released the connection | |
| 534 | + timedOut = e.getCause() instanceof OperationTimedOutException; | |
| 532 | 535 | } finally { |
| 533 | - if (c != null) | |
| 536 | + if (c != null && !timedOut) | |
| 534 | 537 | c.release(); |
| 535 | 538 | } |
| 536 | 539 | } |