kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 2f29ae9aea6b4c9f9f57471df6d0d72f4e887521ffa0902a33112ec8422c4dfc |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-02-06 23:52 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-02-11 12:29 +01:00 |
| Parents | 0707b5d7e98b |
1 file changed
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +9 −1
| @@ -314,11 +314,12 @@ | ||
| 314 | 314 | if (this.keyspace != null && this.keyspace.equals(keyspace)) |
| 315 | 315 | return; |
| 316 | 316 | |
| 317 | + Future future = null; | |
| 317 | 318 | try { |
| 318 | 319 | logger.trace("{} Setting keyspace {}", this, keyspace); |
| 319 | 320 | long timeout = factory.getConnectTimeoutMillis(); |
| 320 | 321 | // Note: we quote the keyspace below, because the name is the one coming from Cassandra, so it's in the right case already |
| 321 | - Future future = write(new Requests.Query("USE \"" + keyspace + '"')); | |
| 322 | + future = write(new Requests.Query("USE \"" + keyspace + '"')); | |
| 322 | 323 | Message.Response response = Uninterruptibles.getUninterruptibly(future, timeout, TimeUnit.MILLISECONDS); |
| 323 | 324 | switch (response.type) { |
| 324 | 325 | case RESULT: |
| @@ -336,9 +337,16 @@ | ||
| 336 | 337 | } catch (ConnectionException e) { |
| 337 | 338 | throw defunct(e); |
| 338 | 339 | } catch (TimeoutException e) { |
| 340 | + // We've given up waiting on the future, but it's still running. Cancel to make sure that the request timeout logic | |
| 341 | + // (readTimeout) will not kick in, because that would release the connection. This will work since connectTimeout is | |
| 342 | + // generally lower than readTimeout (and if not, we'll get an ExecutionException and defunct below). | |
| 343 | + future.cancel(true); | |
| 339 | 344 | logger.warn(String.format("Timeout while setting keyspace on connection to %s. This should not happen but is not critical (it will retried)", address)); |
| 345 | + // Rethrow so that the caller will not try to use the connection, but do not defunct as we don't want to mark down | |
| 346 | + throw new ConnectionException(address, "Timeout while setting keyspace on connection"); | |
| 340 | 347 | } catch (BusyConnectionException e) { |
| 341 | 348 | logger.warn(String.format("Tried to set the keyspace on busy connection to %s. This should not happen but is not critical (it will retried)", address)); |
| 349 | + throw new ConnectionException(address, "Tried to set the keyspace on busy connection"); | |
| 342 | 350 | } catch (ExecutionException e) { |
| 343 | 351 | throw defunct(new ConnectionException(address, "Error while setting keyspace", e)); |
| 344 | 352 | } |