kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 6ded3837992cedd62bbff6f0ef28cab4a097a35090676488a9b9f1c3c4873e33 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-08-06 16:30 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-08-28 12:14 +02:00 |
| Parents | 6d032b5eb9c1 |
3 files changed
modified changelog/README.md +1 −0
| @@ -43,6 +43,7 @@ | ||
| 43 | 43 | creation (JAVA-821, JAVA-822) |
| 44 | 44 | - [improvement] Use parallel calls when re-preparing statement on other |
| 45 | 45 | hosts (JAVA-725) |
| 46 | +- [bug] Don't use connection timeout for unrelated internal queries (JAVA-629) | |
| 46 | 47 | |
| 47 | 48 | Merged from 2.0.10_fixes branch: |
| 48 | 49 |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +16 −18
| @@ -439,26 +439,28 @@ | ||
| 439 | 439 | if (this.keyspace != null && this.keyspace.equals(keyspace)) |
| 440 | 440 | return; |
| 441 | 441 | |
| 442 | - ListenableFuture<Void> future = null; | |
| 443 | 442 | try { |
| 444 | - long timeout = factory.getConnectTimeoutMillis(); | |
| 445 | - future = setKeyspaceAsync(keyspace); | |
| 446 | - Uninterruptibles.getUninterruptibly(future, timeout, TimeUnit.MILLISECONDS); | |
| 443 | + Uninterruptibles.getUninterruptibly(setKeyspaceAsync(keyspace)); | |
| 447 | 444 | } catch (ConnectionException e) { |
| 448 | 445 | throw defunct(e); |
| 449 | - } catch (TimeoutException e) { | |
| 450 | - // We've given up waiting on the future, but it's still running. Cancel to make sure that the request timeout logic | |
| 451 | - // (readTimeout) will not kick in, because that would release the connection. This will work since connectTimeout is | |
| 452 | - // generally lower than readTimeout (and if not, we'll get an ExecutionException and defunct below). | |
| 453 | - future.cancel(true); | |
| 454 | - logger.warn(String.format("Timeout while setting keyspace on connection to %s. This should not happen but is not critical (it will retried)", address)); | |
| 455 | - // Rethrow so that the caller will not try to use the connection, but do not defunct as we don't want to mark down | |
| 456 | - throw new ConnectionException(address, "Timeout while setting keyspace on connection"); | |
| 457 | 446 | } catch (BusyConnectionException e) { |
| 458 | - 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)); | |
| 447 | + logger.warn("Tried to set the keyspace on busy connection to {}. " | |
| 448 | + + "This should not happen but is not critical (it will be retried)", address); | |
| 459 | 449 | throw new ConnectionException(address, "Tried to set the keyspace on busy connection"); |
| 460 | 450 | } catch (ExecutionException e) { |
| 461 | - throw defunct(new ConnectionException(address, "Error while setting keyspace", e.getCause())); | |
| 451 | + Throwable cause = e.getCause(); | |
| 452 | + if (cause instanceof OperationTimedOutException) { | |
| 453 | + // The timeout logic released the connection, but that's wrong since we did not borrow it in the first place. | |
| 454 | + // JAVA-901 will fix this, in the meantime make sure the inFlight count is not off by one. | |
| 455 | + inFlight.incrementAndGet(); | |
| 456 | + | |
| 457 | + // Rethrow so that the caller doesn't try to use the connection, but do not defunct as we don't want to mark down | |
| 458 | + logger.warn("Timeout while setting keyspace on connection to {}. " | |
| 459 | + + "This should not happen but is not critical (it will be retried)", address); | |
| 460 | + throw new ConnectionException(address, "Timeout while setting keyspace on connection"); | |
| 461 | + } else { | |
| 462 | + throw defunct(new ConnectionException(address, "Error while setting keyspace", cause)); | |
| 463 | + } | |
| 462 | 464 | } |
| 463 | 465 | } |
| 464 | 466 | |
| @@ -793,10 +795,6 @@ | ||
| 793 | 795 | return g; |
| 794 | 796 | } |
| 795 | 797 | |
| 796 | - public long getConnectTimeoutMillis() { | |
| 797 | - return configuration.getSocketOptions().getConnectTimeoutMillis(); | |
| 798 | - } | |
| 799 | - | |
| 800 | 798 | public long getReadTimeoutMillis() { |
| 801 | 799 | return configuration.getSocketOptions().getReadTimeoutMillis(); |
| 802 | 800 | } |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +0 −13
| @@ -473,19 +473,6 @@ | ||
| 473 | 473 | onDown(host); |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - void setKeyspace(String keyspace) { | |
| 477 | - long timeout = configuration().getSocketOptions().getConnectTimeoutMillis(); | |
| 478 | - try { | |
| 479 | - Future<?> future = executeQuery(new Requests.Query("use " + keyspace), Statement.DEFAULT); | |
| 480 | - // Note: using the connection timeout isn't perfectly correct, we should probably change that someday | |
| 481 | - Uninterruptibles.getUninterruptibly(future, timeout, TimeUnit.MILLISECONDS); | |
| 482 | - } catch (TimeoutException e) { | |
| 483 | - throw new DriverInternalError(String.format("No responses after %d milliseconds while setting current keyspace. This should not happen, unless you have setup a very low connection timeout.", timeout)); | |
| 484 | - } catch (ExecutionException e) { | |
| 485 | - throw DriverThrowables.propagateCause(e); | |
| 486 | - } | |
| 487 | - } | |
| 488 | - | |
| 489 | 476 | Message.Request makeRequestMessage(Statement statement, ByteBuffer pagingState) { |
| 490 | 477 | |
| 491 | 478 | ConsistencyLevel consistency = statement.getConsistencyLevel(); |