kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a3674bcf4e77af2015d3e89e354f7611b0b1864430d2a9d7932a9d799fe062ca |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-12-07 18:41 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-12-07 18:41 +01:00 |
| Parents | e795c27abebd, 727384fa3b03 |
4 files changed
modified changelog/README.md +1 −3
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | |
| 17 | 17 | - [improvement] JAVA-989: Include keyspace name when invalid replication found when generating token map. |
| 18 | 18 | - [improvement] JAVA-664: Reduce heap consumption for TokenMap. |
| 19 | +- [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing. | |
| 19 | 20 | |
| 20 | 21 | |
| 21 | 22 | ### 3.0.0-alpha5 |
| @@ -249,7 +250,6 @@ | ||
| 249 | 250 | Merged from 2.0 branch: |
| 250 | 251 | |
| 251 | 252 | - [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing. |
| 252 | -- [bug] JAVA-995: Defunct connection even if initializing. | |
| 253 | 253 | |
| 254 | 254 | |
| 255 | 255 | ### 2.1.9 |
| @@ -574,8 +574,6 @@ | ||
| 574 | 574 | ### 2.0.13 (in progress) |
| 575 | 575 | |
| 576 | 576 | - [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing. |
| 577 | -- [bug] JAVA-995: Defunct connection even if initializing. | |
| 578 | - | |
| 579 | 577 | |
| 580 | 578 | ### 2.0.12 |
| 581 | 579 |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +1 −1
| @@ -1063,7 +1063,7 @@ | ||
| 1063 | 1063 | public void operationComplete(ChannelFuture future) throws Exception { |
| 1064 | 1064 | // If we've closed the channel client side then we don't really want to defunct the connection, but |
| 1065 | 1065 | // if there is remaining thread waiting on us, we still want to wake them up |
| 1066 | - if (isClosed()) { | |
| 1066 | + if (!isInitialized || isClosed()) { | |
| 1067 | 1067 | dispatcher.errorOutAllHandler(new TransportException(address, "Channel has been closed")); |
| 1068 | 1068 | // we still want to force so that the future completes |
| 1069 | 1069 | Connection.this.closeAsync().force(); |
modified features/async/README.md +48 −0
| @@ -42,6 +42,54 @@ | ||
| 42 | 42 | }); |
| 43 | 43 | ``` |
| 44 | 44 | |
| 45 | +### Async paging | |
| 46 | + | |
| 47 | +If you consume a `ResultSet` in a callback, be aware that iterating the | |
| 48 | +rows will trigger synchronous queries as you page through the results. | |
| 49 | +To avoid this, use [getAvailableWithoutFetching] to limit the iteration | |
| 50 | +to the current page, and [fetchMoreResults] to get a future to the next | |
| 51 | +page (see also the section on [paging](../paging/)). | |
| 52 | +Here is a full example: | |
| 53 | + | |
| 54 | +[getAvailableWithoutFetching]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/ResultSet.html#getAvailableWithoutFetching-- | |
| 55 | +[fetchMoreResults]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/ResultSet.html#fetchMoreResults-- | |
| 56 | + | |
| 57 | +```java | |
| 58 | +Statement statement = new SimpleStatement("select * from foo").setFetchSize(20); | |
| 59 | +ListenableFuture<ResultSet> future = Futures.transform( | |
| 60 | + session.executeAsync(statement), | |
| 61 | + iterate(1)); | |
| 62 | + | |
| 63 | +private static AsyncFunction<ResultSet, ResultSet> iterate(final int page) { | |
| 64 | + return new AsyncFunction<ResultSet, ResultSet>() { | |
| 65 | + @Override | |
| 66 | + public ListenableFuture<ResultSet> apply(ResultSet rs) throws Exception { | |
| 67 | + | |
| 68 | + // How far we can go without triggering the blocking fetch: | |
| 69 | + int remainingInPage = rs.getAvailableWithoutFetching(); | |
| 70 | + | |
| 71 | + System.out.printf("Starting page %d (%d rows)%n", page, remainingInPage); | |
| 72 | + | |
| 73 | + for (Row row : rs) { | |
| 74 | + System.out.printf("[page %d - %d] row = %s%n", page, remainingInPage, row); | |
| 75 | + if (--remainingInPage == 0) | |
| 76 | + break; | |
| 77 | + } | |
| 78 | + System.out.printf("Done page %d%n", page); | |
| 79 | + | |
| 80 | + boolean wasLastPage = rs.getExecutionInfo().getPagingState() == null; | |
| 81 | + if (wasLastPage) { | |
| 82 | + System.out.println("Done iterating"); | |
| 83 | + return Futures.immediateFuture(rs); | |
| 84 | + } else { | |
| 85 | + ListenableFuture<ResultSet> future = rs.fetchMoreResults(); | |
| 86 | + return Futures.transform(future, iterate(page + 1)); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + }; | |
| 90 | +} | |
| 91 | +``` | |
| 92 | + | |
| 45 | 93 | ### Good practices |
| 46 | 94 | |
| 47 | 95 | If your callback is slow, consider providing a separate executor. |
modified features/paging/README.md +5 −0
| @@ -93,6 +93,11 @@ | ||
| 93 | 93 | } |
| 94 | 94 | ``` |
| 95 | 95 | |
| 96 | +If you use paging with the async API, you'll also want to use those | |
| 97 | +methods to avoid triggering synchronous fetches unintentionally; see | |
| 98 | +[async paging](../async/#async-paging). | |
| 99 | + | |
| 100 | + | |
| 96 | 101 | ### Saving and reusing the paging state |
| 97 | 102 | |
| 98 | 103 | Sometimes it is convenient to save the paging state in order to restore |