| 1 | ## Upgrade guide |
| 2 | |
| 3 | The purpose of this guide is to detail changes made by successive |
| 4 | versions of the Java driver. |
| 5 | |
| 6 | ### 3.1.0 |
| 7 | |
| 8 | This version introduces an important change in the default retry behavior: statements that are not idempotent are not |
| 9 | always retried automatically anymore. |
| 10 | |
| 11 | Prior to 2.1.10, idempotence was not considered for retries. This exposed applications to the risk of applying a |
| 12 | non-idempotent statement twice (counter increment, list append...), or to more subtle bugs with lightweight transactions |
| 13 | (see [JAVA-819](https://datastax-oss.atlassian.net/browse/JAVA-819)). |
| 14 | |
| 15 | In 2.1.10 / 3.0.x, we introduced `IdempotenceAwareRetryPolicy`, which considers the `Statement#isIdempotent()` in the |
| 16 | retry decision process. However, for consistency with previous versions, this policy was not enabled by default (in |
| 17 | particular because statements are non-idempotent by default, and we didn't want applications to suddenly stop retrying |
| 18 | queries that were retried before). |
| 19 | |
| 20 | In 3.1.0, the default is now to **not retry** after a write timeout or request error if the statement is not idempotent. |
| 21 | This is handled internally, the retry policy methods are not even invoked in those cases (and therefore |
| 22 | `IdempotenceAwareRetryPolicy` has been deprecated). See the manual section about [retries](../manual/retries/) for more |
| 23 | information. |
| 24 | |
| 25 | In practice, here's what upgrading to 3.1.0 means for you: |
| 26 | |
| 27 | * if you were already handling idempotence in your application, there won't be any change, but you can stop wrapping |
| 28 | your retry policy with `IdempotenceAwareRetryPolicy`; |
| 29 | * otherwise, you might want to review how your code positions the `setIdempotent` flag on statements. In most cases the |
| 30 | driver can't compute in automatically (because it doesn't parse query strings), so it takes a conservative approach |
| 31 | and sets it to `false` by default. If you know the query is idempotent, you should set it to `true` manually. See the |
| 32 | [query idempotence](../manual/idempotence/) section of the manual. |
| 33 | |
| 34 | The driver logs a warning the first time it ignores a non-idempotent request; this warning will be removed in version |
| 35 | 3.2.0. |
| 36 | |
| 37 | |
| 38 | ### 3.0.4 |
| 39 | |
| 40 | The connection pool is now fully non-blocking ([JAVA-893](https://datastax-oss.atlassian.net/browse/JAVA-893)), |
| 41 | which greatly improves asynchronous programming: |
| 42 | |
| 43 | * `Session.executeAsync` won't ever block the user thread anymore; |
| 44 | * you can now safely run async queries on a session connected to a keyspace. |
| 45 | |
| 46 | This new implementation brings a couple of changes: |
| 47 | |
| 48 | * pool saturation is no longer handled by a timeout, but instead by a bounded queue. As a consequence, |
| 49 | `PoolingOptions.setPoolTimeoutMillis` has been deprecated, and replaced by `setMaxQueueSize`; |
| 50 | * a saturated pool will now throw `BusyPoolException` instead of `TimeoutException` (note that this exception is not |
| 51 | rethrown directly to the client, but wrapped in `NoHostAvailableException.getErrors()`). |
| 52 | |
| 53 | |
| 54 | ### 3.0.0 |
| 55 | |
| 56 | This version brings parity with Cassandra 2.2 and 3.0. |
| 57 | |
| 58 | It is **not binary compatible** with the driver's 2.1 branch. |
| 59 | The main changes were introduced by the custom codecs feature (see below). |
| 60 | We've also seized the opportunity to remove code that was deprecated in 2.1. |
| 61 | |
| 62 | 1. The default consistency level in `QueryOptions` is now `LOCAL_ONE`. |
| 63 | 2. [Custom codecs](../manual/custom_codecs/) |
| 64 | ([JAVA-721](https://datastax-oss.atlassian.net/browse/JAVA-721)) |
| 65 | introduce several breaking changes and also modify a few runtime behaviors. |
| 66 | |
| 67 | Here is a detailed list of breaking API changes: |
| 68 | * `TypeCodec` was package-private before and is now public. |
| 69 | * `DataType` has no more references to `TypeCodec`, so methods that dealt with serialization and deserialization of |
| 70 | data types have been removed: |
| 71 | * `ByteBuffer serialize(Object value, ProtocolVersion protocolVersion)` |
| 72 | * `ByteBuffer serializeValue(Object value, ProtocolVersion protocolVersion)` |
| 73 | * `Object deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)` |
| 74 | * `Object deserialize(ByteBuffer bytes, int protocolVersion)` |
| 75 | * `Object parse(String value)` |
| 76 | * `String format(Object value)` |
| 77 | * `Class<?> asJavaClass()` |
| 78 | |
| 79 | These methods must now be invoked on `TypeCodec` directly. To resolve the `TypeCodec` instance for a particular |
| 80 | data type, use `CodecRegistry#codecFor`. |
| 81 | * `GettableByIndexData` (affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`). The following public methods were added: |
| 82 | * `<T> T get(int i, Class<T> targetClass)` |
| 83 | * `<T> T get(int i, TypeToken<T> targetType)` |
| 84 | * `<T> T get(int i, TypeCodec<T> codec)` |
| 85 | * `GettableByNameData` (affects `Row`, `BoundStatement` and `UDTValue`). The following public methods were added: |
| 86 | * `<T> T get(String name, Class<T> targetClass)` |
| 87 | * `<T> T get(String name, TypeToken<T> targetType)` |
| 88 | * `<T> T get(String name, TypeCodec<T> codec)` |
| 89 | * `SettableByIndexData` (affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`). The following public methods were added: |
| 90 | * `<V> T set(int i, V v, Class<V> targetClass)` |
| 91 | * `<V> T set(int i, V v, TypeToken<V> targetType)` |
| 92 | * `<V> T set(int i, V v, TypeCodec<V> codec)` |
| 93 | * `SettableByNameData` (affects `Row`, `BoundStatement` and `UDTValue`). The following public methods were added: |
| 94 | * `<V> T set(String name, V v, Class<V> targetClass)` |
| 95 | * `<V> T set(String name, V v, TypeToken<V> targetType)` |
| 96 | * `<V> T set(String name, V v, TypeCodec<V> codec)` |
| 97 | * `Statement`. The following public methods were modified: |
| 98 | * `getRoutingKey(ProtocolVersion, CodecRegistry)`: both parameters added. |
| 99 | * `RegularStatement`. The following public methods were modified: |
| 100 | * `getValues(ProtocolVersion, CodecRegistry)`: second parameter added. |
| 101 | * `getQueryString(CodecRegistry)` and `hasValues(CodecRegistry)`: parameter added. No-arg versions are still present |
| 102 | and use the default codec registry; refer to the Javadocs for guidance on which version to use. |
| 103 | * `PreparedStatement`. The following public method was added: |
| 104 | * `CodecRegistry getCodecRegistry()`. |
| 105 | * `TupleType`. The following public method was deleted: |
| 106 | * `TupleType of(DataType... types)`; users should now use `Metadata.newTupleType(DataType...)`. |
| 107 | |
| 108 | <p>The driver runtime behavior changes in the following situations:</p> |
| 109 | * By default, the driver now returns _mutable_, _non thread-safe_ instances for CQL collection types; |
| 110 | This affects methods `getList`, `getSet`, `getMap`, `getObject` and `get` for all instances of |
| 111 | `GettableByIndexData` and `GettableByNameData` (`Row`, `BoundStatement`, `TupleValue` and `UDTValue`) |
| 112 | * `RuntimeException`s thrown during serialization or deserialization might not be |
| 113 | the same ones as before, due to the newly-introduced `CodecNotFoundException` |
| 114 | and to the dynamic nature of codec search introduced by JAVA-721. |
| 115 | * `TypeCodec.format(Object)` now returns the CQL keyword `"NULL"` instead of a `null` reference |
| 116 | for `null` inputs. |
| 117 | |
| 118 | 3. The driver now depends on Guava 16.0.1 (instead of 14.0.1). |
| 119 | This update has been mainly motivated by Guava's [Issue #1635](https://code.google.com/p/guava-libraries/issues/detail?id=1635), |
| 120 | which affects `TypeToken`, and hence all `TypeCodec` implementations handling parameterized types. |
| 121 | |
| 122 | 4. `UDTMapper` (the type previously used to convert `@UDT`-annotated |
| 123 | classes to their CQL counterpart) was removed, as well as the |
| 124 | corresponding method `MappingManager#udtMapper`. |
| 125 | |
| 126 | The mapper now uses custom codecs to convert UDTs. See more |
| 127 | explanations [here](../manual/object_mapper/custom_codecs/#implicit-udt-codecs). |
| 128 | |
| 129 | 5. All methods that took the protocol version as an `int` or assumed a |
| 130 | default version have been removed (they were already deprecated in |
| 131 | 2.1): |
| 132 | * `AbstractGettableData(int)` |
| 133 | * `Cluster.Builder#withProtocolVersion(int)` |
| 134 | * in `ProtocolOptions`: |
| 135 | * `NEWEST_SUPPORTED_PROTOCOL_VERSION` (replaced by |
| 136 | `ProtocolVersion#NEWEST_SUPPORTED`) |
| 137 | * `int getProtocolVersion()` |
| 138 | |
| 139 | There are now variants of these methods using the `ProtocolVersion` |
| 140 | enum. In addition, `ProtocolOptions#getProtocolVersionEnum` has been |
| 141 | renamed to `ProtocolOptions#getProtocolVersion`. |
| 142 | |
| 143 | 6. All methods related to the "suspected" host state have been removed |
| 144 | (they had been deprecated in 2.1.6 when the suspicion mechanism was |
| 145 | removed): |
| 146 | * `Host.StateListener#onSuspected()` (was inherited by |
| 147 | `LoadBalancingPolicy`) |
| 148 | * `Host#getInitialReconnectionAttemptFuture()` |
| 149 | |
| 150 | 7. `PoolingOptions#setMinSimultaneousRequestsPerConnectionThreshold(HostDistance, |
| 151 | int)` has been removed. The new connection pool resizing algorithm introduced by |
| 152 | [JAVA-419](https://datastax-oss.atlassian.net/browse/JAVA-419) does not need this |
| 153 | threshold anymore. |
| 154 | |
| 155 | 8. `AddressTranslater` has been renamed to `AddressTranslator`. All |
| 156 | related methods and classes have also been renamed. |
| 157 | |
| 158 | In addition, the `close()` method has been pulled up into |
| 159 | `AddressTranslator`, and `CloseableAddressTranslator` has been removed. |
| 160 | Existing third-party `AddressTranslator` implementations only need |
| 161 | to add an empty `close()` method. |
| 162 | |
| 163 | 9. The `close()` method has been pulled up into `LoadBalancingPolicy`, |
| 164 | and `CloseableLoadBalancingPolicy` has been removed. Existing third-party |
| 165 | `LoadBalancingPolicy` implementations only need to add an empty |
| 166 | `close()` method. |
| 167 | |
| 168 | 10. All pluggable components now have callbacks to detect when they get |
| 169 | associated with a `Cluster` instance: |
| 170 | * `ReconnectionPolicy`, `RetryPolicy`, `AddressTranslator`, |
| 171 | and `TimestampGenerator`: |
| 172 | * `init(Cluster)` |
| 173 | * `close()` |
| 174 | * `Host.StateListener` and `LatencyTracker`: |
| 175 | * `onRegister(Cluster)` |
| 176 | * `onUnregister(Cluster)` |
| 177 | |
| 178 | This gives these components the opportunity to perform |
| 179 | initialization / cleanup tasks. Existing third-party implementations |
| 180 | only need to add empty methods. |
| 181 | |
| 182 | 11. `LoadBalancingPolicy` does not extend `Host.StateListener` anymore: |
| 183 | callback methods (`onUp`, `onDown`, etc.) have been duplicated. This |
| 184 | is unlikely to affect clients. |
| 185 | |
| 186 | 12. [Client-side timestamp generation](../manual/query_timestamps/) is |
| 187 | now the default (provided that [native |
| 188 | protocol](../manual/native_protocol) v3 or higher is in use). The |
| 189 | generator used is `AtomicMonotonicTimestampGenerator`. |
| 190 | |
| 191 | 13. If a DNS name resolves to multiple A-records, |
| 192 | `Cluster.Builder#addContactPoint(String)` will now use all of these |
| 193 | addresses as contact points. This gives you the possibility of |
| 194 | maintaining contact points in DNS configuration, and having a single, |
| 195 | static contact point in your Java code. |
| 196 | |
| 197 | 14. The following methods were added for [Custom payloads](../manual/custom_payloads): |
| 198 | * in `PreparedStatement`: `getIncomingPayload()`, |
| 199 | `getOutgoingPayload()` and |
| 200 | `setOutgoingPayload(Map<String,ByteBuffer>)` |
| 201 | * `AbstractSession#prepareAsync(String, Map<String,ByteBuffer>)` |
| 202 | |
| 203 | Also, note that `AbstractSession#prepareAsync(Statement)` does not |
| 204 | call `AbstractSession#prepareAsync(String)` anymore, they now both |
| 205 | delegate to a protected method. |
| 206 | |
| 207 | This breaks binary compatibility for these two classes; if you have |
| 208 | custom implementations, you will have to adapt them accordingly. |
| 209 | |
| 210 | 15. Getters and setters have been added to "data-container" classes for |
| 211 | new CQL types: |
| 212 | * `getByte`/`setByte` for the `TINYINT` type |
| 213 | * `getShort`/`setShort` for the `SMALLINT` type |
| 214 | * `getTime`/`setTime` for the `TIME` type |
| 215 | * `getDate`/`setDate` for the `DATE` type |
| 216 | |
| 217 | The methods for the `TIMESTAMP` CQL type have been renamed to |
| 218 | `getTimestamp` and `setTimestamp`. |
| 219 | |
| 220 | This affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`. |
| 221 | |
| 222 | 16. New exception types have been added to handle additional server-side |
| 223 | errors introduced in Cassandra 2.2: |
| 224 | * `ReadFailureException` |
| 225 | * `WriteFailureException` |
| 226 | * `FunctionExecutionException` |
| 227 | |
| 228 | This is not a breaking change since all driver exceptions are |
| 229 | unchecked; but clients might decide to handle these errors in a specific |
| 230 | way. |
| 231 | |
| 232 | In addition, `QueryTimeoutException` has been renamed to |
| 233 | `QueryExecutionException` (this is an intermediary class in our |
| 234 | exception hierarchy, it now has new child classes that are not |
| 235 | related to timeouts). |
| 236 | |
| 237 | 17. `ResultSet#fetchMoreResults()` now returns a `ListenableFuture<ResultSet>`. |
| 238 | This makes the API more friendly if you chain transformations on an async |
| 239 | query to process all pages (see `AsyncResultSetTest` in the sources for an |
| 240 | example). |
| 241 | |
| 242 | 18. `Frozen` annotations in the mapper are no longer checked at runtime (see |
| 243 | [JAVA-843](https://datastax-oss.atlassian.net/browse/JAVA-843) for more |
| 244 | explanations). So they become purely informational at this stage. |
| 245 | However it is a good idea to keep using these annotations and make sure |
| 246 | they match the schema, in anticipation for the schema generation features |
| 247 | that will be added in a future version. |
| 248 | |
| 249 | 19. `AsyncInitSession` has been removed, `initAsync()` is now part of the |
| 250 | `Session` interface (the only purpose of the extra interface was to preserve |
| 251 | binary compatibility on the 2.1 branch). |
| 252 | |
| 253 | 20. `TableMetadata.Options` has been made a top-level class and renamed to |
| 254 | `TableOptionsMetadata`. It is now also used by `MaterializedViewMetadata`. |
| 255 | |
| 256 | 21. The mapper annotation `@Enumerated` has been removed, users should now |
| 257 | use the newly-introduced `driver-extras` module to get automatic |
| 258 | enum-to-CQL mappings. Two new codecs provide the same functionality: |
| 259 | `EnumOrdinalCodec` and `EnumNameCodec`: |
| 260 | |
| 261 | ```java |
| 262 | enum Foo {...} |
| 263 | enum Bar {...} |
| 264 | |
| 265 | // register the appropriate codecs |
| 266 | CodecRegistry.DEFAULT_INSTANCE |
| 267 | .register(new EnumOrdinalCodec<Foo>(Foo.class)) |
| 268 | .register(new EnumNameCodec<Bar>(Bar.class)) |
| 269 | |
| 270 | // the following mappings are handled out-of-the-box |
| 271 | @Table |
| 272 | public class MyPojo { |
| 273 | private Foo foo; |
| 274 | private List<Bar> bars; |
| 275 | ... |
| 276 | } |
| 277 | ``` |
| 278 | |
| 279 | 22. The interface `IdempotenceAwarePreparedStatement` has been removed |
| 280 | and now the `PreparedStatement` interface exposes 2 new methods, |
| 281 | `setIdempotent(Boolean)` and `isIdempotent()`. |
| 282 | |
| 283 | 23. `RetryPolicy` and `ExtendedRetryPolicy` (introduced in 2.1.10) |
| 284 | were merged together; as a consequence, `RetryPolicy` now has one |
| 285 | more method: `onRequestError`; see |
| 286 | [JAVA-819](https://datastax-oss.atlassian.net/browse/JAVA-819) for |
| 287 | more information. Furthermore, `FallthroughRetryPolicy` now returns |
| 288 | `RetryDecision.rethrow()` when `onRequestError` is called. |
| 289 | |
| 290 | 24. `DseAuthProvider` has been deprecated and is now replaced by |
| 291 | `DseGSSAPIAuthProvider` for Kerberos authentication. `DsePlainTextAuthProvider` |
| 292 | has been introduced to handle plain text authentication with the |
| 293 | `DseAuthenticator`. |
| 294 | |
| 295 | 25. The constructor of `DCAwareRoundRobinPolicy` is not accessible anymore. You |
| 296 | should use `DCAwareRoundRobinPolicy#builder()` to create new instances. |
| 297 | |
| 298 | 26. `ColumnMetadata.getTable()` has been renamed to `ColumnMetadata.getParent()`. |
| 299 | Also, its return type is now `AbstractTableMetadata` which can be either |
| 300 | a `TableMetadata` object or a `MaterializedViewMetadata` object. |
| 301 | This change is motivated by the fact that a column can now belong to a |
| 302 | table or a materialized view. |
| 303 | |
| 304 | 27. `ColumnMetadata.getIndex()` has been removed. |
| 305 | This is due to the fact that secondary indexes have been completely redesigned |
| 306 | in Cassandra 3.0, and the former one-to-one relationship between a column and its index |
| 307 | has been replaced with a one-to-many relationship between a table and its indexes. |
| 308 | This is reflected in the driver's API by the new methods |
| 309 | `TableMetadata.getIndexes()` and `TableMetadata.getIndex(String name)`. |
| 310 | See [CASSANDRA-9459](https://issues.apache.org/jira/browse/CASSANDRA-9459) and |
| 311 | and [JAVA-1008](https://datastax-oss.atlassian.net/browse/JAVA-1008) for |
| 312 | more details. |
| 313 | Unfortunately, there is no easy way to recover the functionality provided |
| 314 | by the deleted method, _even for Cassandra versions <= 3.0_. |
| 315 | |
| 316 | 28. `IndexMetadata` is now a top-level class and its structure has been deeply modified. |
| 317 | Again, this is due to the fact that secondary indexes have been completely redesigned |
| 318 | in Cassandra 3.0. |
| 319 | |
| 320 | 29. `SSLOptions` has been refactored to allow the option to choose between JDK and Netty-based |
| 321 | SSL implementations. See [JAVA-841](https://datastax-oss.atlassian.net/browse/JAVA-841) and |
| 322 | the [SSL documentation](../manual/ssl) for more details. |
| 323 | |
| 324 | |
| 325 | ### 2.1.8 |
| 326 | |
| 327 | 2.1.8 is binary-compatible with 2.1.7 but introduces a small change in the |
| 328 | driver's behavior: |
| 329 | |
| 330 | 1. The list of contact points provided at startup is now shuffled before trying |
| 331 | to open the control connection, so that multiple clients with the same contact |
| 332 | points don't all pick the same control host. As a result, you can't assume that |
| 333 | the driver will try contact points in a deterministic order. In particular, if |
| 334 | you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter |
| 335 | name, make sure that you only provide local hosts as contact points. |
| 336 | |
| 337 | |
| 338 | ### 2.1.7 |
| 339 | |
| 340 | This version brings a few changes in the driver's behavior; none of them break |
| 341 | binary compatibility. |
| 342 | |
| 343 | 1. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable |
| 344 | exception received from a request. The new behaviour will cause the driver to |
| 345 | process a Retry on a different node at most once, otherwise an exception will |
| 346 | be thrown. This change makes sense in the case where the node tried initially |
| 347 | for the request happens to be isolated from the rest of the cluster (e.g. |
| 348 | because of a network partition) but can still answer to the client normally. |
| 349 | In this case, trying another node has a chance of success. |
| 350 | The previous behaviour was to always throw an exception. |
| 351 | |
| 352 | 2. The following properties in `PoolingOptions` were renamed: |
| 353 | * `MaxSimultaneousRequestsPerConnectionThreshold` to `NewConnectionThreshold` |
| 354 | * `MaxSimultaneousRequestsPerHostThreshold` to `MaxRequestsPerConnection` |
| 355 | |
| 356 | The old getters/setters were deprecated, but they delegate to the new |
| 357 | ones. |
| 358 | |
| 359 | Also, note that the connection pool for protocol v3 can now be configured to |
| 360 | use multiple connections. See [this page](../manual/pooling) for more |
| 361 | information. |
| 362 | |
| 363 | 3. `MappingManager(Session)` will now force the initialization of the `Session` |
| 364 | if needed. This is a change from 2.1.6, where if you gave it an uninitialized |
| 365 | session (created with `Cluster#newSession()` instead of `Cluster#connect()`), |
| 366 | it would only get initialized on the first request. |
| 367 | |
| 368 | If this is a problem for you, `MappingManager(Session, ProtocolVersion)` |
| 369 | preserves the previous behavior (see the API docs for more details). |
| 370 | |
| 371 | 4. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()` |
| 372 | or `raw()` is used to build a value to be inserted in the database. |
| 373 | If you know that the CQL functions or expressions are safe, use |
| 374 | `setIdempotent(true)` on the statement. |
| 375 | |
| 376 | ### 2.1.6 |
| 377 | |
| 378 | See [2.0.10](#2-0-x-to-2-0-10). |
| 379 | |
| 380 | |
| 381 | ### 2.1.2 |
| 382 | |
| 383 | 2.1.2 brings important internal changes with native protocol v3 support, but |
| 384 | the impact on the public API has been kept as low as possible. |
| 385 | |
| 386 | #### User API Changes |
| 387 | |
| 388 | 1. The native protocol version is now modelled as an enum: `ProtocolVersion`. |
| 389 | Most public methods that take it as an argument have a backward-compatible |
| 390 | version that takes an `int` (the exception being `RegularStatement`, |
| 391 | described below). For new code, prefer the enum version. |
| 392 | |
| 393 | #### Internal API Changes |
| 394 | |
| 395 | 1. `RegularStatement.getValues` now takes the protocol version as a |
| 396 | `ProtocolVersion` instead of an `int`. This is transparent for callers |
| 397 | since there is a backward-compatible alternative, but if you happened to |
| 398 | extend the class you'll need to update your implementation. |
| 399 | |
| 400 | 2. `BatchStatement.setSerialConsistencyLevel` now returns `BatchStatement` |
| 401 | instead of `Statement`. Again, this only matters if you extended this |
| 402 | class (if so, it might be a good idea to also have a covariant return in |
| 403 | your child class). |
| 404 | |
| 405 | 3. The constructor of `UnsupportedFeatureException` now takes a |
| 406 | `ProtocolVersion` as a parameter. This should impact few users, as there's |
| 407 | hardly any reason to build instances of that class from client code. |
| 408 | |
| 409 | #### New features |
| 410 | |
| 411 | These features are only active when the native protocol v3 is in use. |
| 412 | |
| 413 | 1. The driver now uses a single connection per host (as opposed to a pool in |
| 414 | 2.1.1). Most options in `PoolingOptions` are ignored, except for a new one |
| 415 | called `maxSimultaneousRequestsPerHostThreshold`. See the class's Javadocs |
| 416 | for detailed explanations. |
| 417 | |
| 418 | 2. You can now provide a default timestamp with each query (but it will be |
| 419 | ignored if the CQL query string already contains a `USING TIMESTAMP` |
| 420 | clause). This can be done on a per-statement basis with |
| 421 | `Statement.setDefaultTimestamp`, or automatically with a |
| 422 | `TimestampGenerator` specified with |
| 423 | `Cluster.Builder.withTimestampGenerator` (two implementations are |
| 424 | provided: `ThreadLocalMonotonicTimestampGenerator` and |
| 425 | `AtomicMonotonicTimestampGenerator`). If you specify both, the statement's |
| 426 | timestamp takes precedence over the generator. By default, the driver has |
| 427 | the same behavior as 2.1.1 (no generator, timestamps are assigned by |
| 428 | Cassandra unless `USING TIMESTAMP` was specified). |
| 429 | |
| 430 | 3. `BatchStatement.setSerialConsistencyLevel` no longer throws an exception, |
| 431 | it will honor the serial consistency level for the batch. |
| 432 | |
| 433 | |
| 434 | ### 2.1.1 |
| 435 | |
| 436 | #### Internal API Changes |
| 437 | |
| 438 | 1. The `ResultSet` interface has a new `wasApplied()` method. This will |
| 439 | only affect clients that provide their own implementation of this interface. |
| 440 | |
| 441 | |
| 442 | ### 2.1.0 |
| 443 | |
| 444 | #### User API Changes |
| 445 | |
| 446 | 1. The `getCaching` method of `TableMetadata#Options` now returns a |
| 447 | `Map` to account for changes to Cassandra 2.1. Also, the |
| 448 | `getIndexInterval` method now returns an `Integer` instead of an `int` |
| 449 | which will be `null` when connected to Cassandra 2.1 nodes. |
| 450 | |
| 451 | 2. `BoundStatement` variables that have not been set explicitly will no |
| 452 | longer default to `null`. Instead, all variables must be bound explicitly, |
| 453 | otherwise the execution of the statement will fail (this also applies to |
| 454 | statements inside of a `BatchStatement`). For variables that map to a |
| 455 | primitive Java type, a new `setToNull` method has been added. |
| 456 | We made this change because the driver might soon distinguish between unset |
| 457 | and null variables, so we don't want clients relying on the "leave unset to |
| 458 | set to `null`" behavior. |
| 459 | |
| 460 | |
| 461 | #### Internal API Changes |
| 462 | |
| 463 | The changes listed in this section should normally not impact end users of the |
| 464 | driver, but rather third-party frameworks and tools. |
| 465 | |
| 466 | 1. The `serialize` and `deserialize` methods in `DataType` now take an |
| 467 | additional parameter: the protocol version. As explained in the javadoc, |
| 468 | if unsure, the proper value to use for this parameter is the protocol version |
| 469 | in use by the driver, i.e. the value returned by |
| 470 | `cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`. |
| 471 | |
| 472 | 2. The `parse` method in `DataType` now returns a Java object, not a |
| 473 | `ByteBuffer`. The previous behavior can be obtained by calling the |
| 474 | `serialize` method on the returned object. |
| 475 | |
| 476 | 3. The `getValues` method of `RegularStatement` now takes the protocol |
| 477 | version as a parameter. As above, the proper value if unsure is almost surely |
| 478 | the protocol version in use |
| 479 | (`cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`). |
| 480 | |
| 481 | |
| 482 | ### 2.0.11 |
| 483 | |
| 484 | 2.0.11 preserves binary compatibility with previous versions. There are a few |
| 485 | changes in the driver's behavior: |
| 486 | |
| 487 | 1. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable |
| 488 | exception received from a request. The new behaviour will cause the driver to |
| 489 | process a Retry on a different node at most once, otherwise an exception will |
| 490 | be thrown. This change makes sense in the case where the node tried initially |
| 491 | for the request happens to be isolated from the rest of the cluster (e.g. |
| 492 | because of a network partition) but can still answer to the client normally. |
| 493 | In this case, trying another node has a chance of success. |
| 494 | The previous behaviour was to always throw an exception. |
| 495 | |
| 496 | 2. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()` |
| 497 | or `raw()` is used to build a value to be inserted in the database. |
| 498 | If you know that the CQL functions or expressions are safe, use |
| 499 | `setIdempotent(true)` on the statement. |
| 500 | |
| 501 | 3. The list of contact points provided at startup is now shuffled before trying |
| 502 | to open the control connection, so that multiple clients with the same contact |
| 503 | points don't all pick the same control host. As a result, you can't assume that |
| 504 | the driver will try contact points in a deterministic order. In particular, if |
| 505 | you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter |
| 506 | name, make sure that you only provide local hosts as contact points. |
| 507 | |
| 508 | |
| 509 | ### <a name="2-0-x-to-2-0-10"></a>2.0.x to 2.0.10 |
| 510 | |
| 511 | We try to avoid breaking changes within a branch (2.0.x to 2.0.y), but |
| 512 | 2.0.10 saw a lot of new features and internal improvements. There is one |
| 513 | breaking change: |
| 514 | |
| 515 | 1. `LatencyTracker#update` now has a different signature and takes two new |
| 516 | parameters: the statement that has been executed (never null), and the exception |
| 517 | thrown while executing the query (or null, if the query executed successfully). |
| 518 | Existing implementations of this interface, once upgraded to the new method |
| 519 | signature, should continue to work as before. |
| 520 | |
| 521 | The following might also be of interest: |
| 522 | |
| 523 | 2. `SocketOptions#getTcpNoDelay()` is now TRUE by default (it was previously undefined). |
| 524 | This reflects the new behavior of Netty (which was upgraded from version 3.9.0 to |
| 525 | 4.0.27): `TCP_NODELAY` is now turned on by default, instead of depending on the OS |
| 526 | default like in previous versions. |
| 527 | |
| 528 | 3. Netty is not shaded anymore in the default Maven artifact. However we publish a |
| 529 | [shaded artifact](../manual/shaded_jar/) under a different classifier. |
| 530 | |
| 531 | 4. The internal initialization sequence of the Cluster object has been slightly changed: |
| 532 | some fields that were previously initialized in the constructor are now set when |
| 533 | the `init()` method is called. In particular, `Cluster#getMetrics()` will return |
| 534 | `null` until the cluster is initialized. |
| 535 | |
| 536 | ### 1.0 to 2.0 |
| 537 | |
| 538 | We used the opportunity of a major version bump to incorporate your feedback |
| 539 | and improve the API, to fix a number of inconsistencies and remove cruft. |
| 540 | Unfortunately this means there are some breaking changes, but the new API should |
| 541 | be both simpler and more complete. |
| 542 | |
| 543 | The following describes the changes for 2.0 that are breaking changes of the |
| 544 | 1.0 API. For ease of use, we distinguish two categories of API changes: the "main" |
| 545 | ones and the "other" ones. |
| 546 | |
| 547 | The "main" API changes are the ones that are either |
| 548 | likely to affect most upgraded apps or are incompatible changes that, even if minor, |
| 549 | will not be detected at compile time. Upgraders are highly encouraged to check |
| 550 | this list of "main" changes while upgrading their application to 2.0 (even |
| 551 | though most applications are likely to be affected by only a handful of |
| 552 | changes). |
| 553 | |
| 554 | The "other" list is, well, other changes: those that are likely to |
| 555 | affect a minor number of applications and will be detected by compile time |
| 556 | errors anyway. It is ok to skip those initially and only come back to them if |
| 557 | you have trouble compiling your application after an upgrade. |
| 558 | |
| 559 | #### Main API changes |
| 560 | |
| 561 | 1. The `Query` class has been renamed into `Statement` (it was confusing |
| 562 | to some that the `BoundStatement` was not a `Statement`). To allow |
| 563 | this, the old `Statement` class has been renamed to `RegularStatement`. |
| 564 | |
| 565 | 2. The `Cluster` and `Session` shutdown API has changed. There is now a |
| 566 | `closeAsync` that is asynchronous but returns a `Future` on the |
| 567 | completion of the shutdown process. There is also a `close` shortcut |
| 568 | that does the same but blocks. Also, `close` now waits for ongoing |
| 569 | queries to complete by default (but you can force the closing of all |
| 570 | connections if you want to). |
| 571 | |
| 572 | 3. `NoHostAvailableException#getErrors` now returns the full exception objects for |
| 573 | each node instead of just a message. In other words, it returns a |
| 574 | `Map<InetAddress, Throwable>` instead of a `Map<InetAddress, String>`. |
| 575 | |
| 576 | 4. `Statement#getConsistencyLevel` (previously `Query#getConsistencyLevel`, see |
| 577 | first point) will now return `null` by default (instead of `CL.ONE`), with the |
| 578 | meaning of "use the default consistency level". |
| 579 | The default consistency level can now be configured through the new `QueryOptions` |
| 580 | object in the cluster `Configuration`. |
| 581 | |
| 582 | 5. The `Metrics` class now uses the Codahale metrics library version 3 (version 2 was |
| 583 | used previously). This new major version of the library has many API changes |
| 584 | compared to its version 2 (see the [release notes](https://dropwizard.github.io/metrics/3.1.0/about/release-notes/) for details), |
| 585 | which can thus impact consumers of the Metrics class. |
| 586 | Furthermore, the default `JmxReporter` now includes a name specific to the |
| 587 | cluster instance (to avoid conflicts when multiple Cluster instances are created |
| 588 | in the same JVM). As a result, tools that were polling JMX info will |
| 589 | have to be updated accordingly. |
| 590 | |
| 591 | 6. The `QueryBuilder#in` method now has the following special case: using |
| 592 | `QueryBuilder.in(QueryBuilder.bindMarker())` will generate the string `IN ?`, |
| 593 | not `IN (?)` as was the case in 1.0. The reasoning being that the former |
| 594 | syntax, made valid by [CASSANDRA-4210](https://issues.apache.org/jira/browse/CASSANDRA-4210) |
| 595 | is a lot more useful than `IN (?)`, as the latter can more simply use an |
| 596 | equality. |
| 597 | Note that if you really want to output `IN (?)` with the query |
| 598 | builder, you can use `QueryBuilder.in(QueryBuilder.raw("?"))`. |
| 599 | |
| 600 | 7. When binding values by name in `BoundStatement` (i.e. using the |
| 601 | `setX(String, X)` methods), if more than one variable have the same name, |
| 602 | then all values corresponding to that variable |
| 603 | name are set instead of just the first occurrence. |
| 604 | |
| 605 | 8. The `QueryBuilder#raw` method does not automatically add quotes anymore, but |
| 606 | rather output its result without any change (as the raw name implies). |
| 607 | This means for instance that `eq("x", raw(foo))` will output `x = foo`, |
| 608 | not `x = 'foo'` (you don't need the raw method to output the latter string). |
| 609 | |
| 610 | 9. The `QueryBuilder` will now sometimes use the new ability to send value as |
| 611 | bytes instead of serializing everything to string. In general the QueryBuilder |
| 612 | will do the right thing, but if you were calling the `getQueryString()` method |
| 613 | on a Statement created with a QueryBuilder (for other reasons than to prepare a query) |
| 614 | then the returned string may contain bind markers in place of some of the values |
| 615 | provided (and in that case, `getValues()` will contain the values corresponding |
| 616 | to those markers). If need be, it is possible to force the old behavior by |
| 617 | using the new `setForceNoValues()` method. |
| 618 | |
| 619 | #### Other API Changes |
| 620 | |
| 621 | 1. Creating a Cluster instance (through `Cluster#buildFrom` or the |
| 622 | `Cluster.Builder#build` method) **does not create any connection right away |
| 623 | anymore** (and thus cannot throw a `NoHostAvailableException` or an |
| 624 | `AuthenticationException`). Instead, the initial contact points are checked |
| 625 | the first time a call to `Cluster#connect` is done. If for some reason you |
| 626 | want to emulate the previous behavior, you can use the new method |
| 627 | `Cluster#init`: `Cluster.builder().build()` in 1.0 is equivalent to |
| 628 | `Cluster.builder().build().init()` in 2.0. |
| 629 | |
| 630 | 2. Methods from `Metadata`, `KeyspaceMetadata` and `TableMetadata` now use by default |
| 631 | case insensitive identifiers (for keyspace, table and column names in |
| 632 | parameter). You can double-quote an identifier if you want it to be a |
| 633 | case sensitive one (as you would do in CQL) and there is a `Metadata.quote` |
| 634 | helper method for that. |
| 635 | |
| 636 | 3. The `TableMetadata#getClusteringKey` method has been renamed |
| 637 | `TableMetadata#getClusteringColumns` to match the "official" vocabulary. |
| 638 | |
| 639 | 4. The `UnavailableException#getConsistency` method has been renamed to |
| 640 | `UnavailableException#getConsistencyLevel` for consistency with the method of |
| 641 | `QueryTimeoutException`. |
| 642 | |
| 643 | 5. The `RegularStatement` class (ex-`Statement` class, see above) must now |
| 644 | implement two additional methods: `RegularStatement#getKeyspace` and |
| 645 | `RegularStatement#getValues`. If you had extended this class, you will have to |
| 646 | implement those new methods, but both can return null if they are not useful |
| 647 | in your case. |
| 648 | |
| 649 | 6. The `Cluster.Initializer` interface should now implement 2 new methods: |
| 650 | `Cluster.Initializer#getInitialListeners` (which can return an empty |
| 651 | collection) and `Cluster.Initializer#getClusterName` (which can return null). |
| 652 | |
| 653 | 7. The `Metadata#getReplicas` method now takes 2 arguments. On top of the |
| 654 | partition key, you must now provide the keyspace too. The previous behavior |
| 655 | was buggy: it's impossible to properly return the full list of replica for a |
| 656 | partition key without knowing the keyspace since replication may depend on |
| 657 | the keyspace). |
| 658 | |
| 659 | 8. The method `LoadBalancingPolicy#newQueryPlan()` method now takes the currently |
| 660 | logged keyspace as 2nd argument. This information is necessary to do proper |
| 661 | token aware balancing (see preceding point). |
| 662 | |
| 663 | 9. The `ResultSetFuture#set` and `ResultSetFuture#setException` methods have been |
| 664 | removed (from the public API at least). They were never meant to be exposed |
| 665 | publicly: a `resultSetFuture` is always set by the driver itself and should |
| 666 | not be set manually. |
| 667 | |
| 668 | 10. The deprecated since 1.0.2 `Host.HealthMonitor` class has been removed. You |
| 669 | will now need to use `Host#isUp` and `Cluster#register` if you were using that |
| 670 | class. |
| 671 | |
| 672 | #### Features available only with Cassandra 2.0 |
| 673 | |
| 674 | This section details the biggest additions to 2.0 API wise. It is not an |
| 675 | exhaustive list of new features in 2.0. |
| 676 | |
| 677 | 1. The new `BatchStatement` class allows to group any type of insert Statements |
| 678 | (`BoundStatement` or `RegularStatement`) for execution as a batch. For instance, |
| 679 | you can do something like: |
| 680 | |
| 681 | ```java |
| 682 | List<String> values = ...; |
| 683 | PreparedStatement ps = session.prepare("INSERT INTO myTable(value) VALUES (?)"); |
| 684 | BatchStatement bs = new BatchStatement(); |
| 685 | for (String value : values) |
| 686 | bs.add(ps.bind(value)); |
| 687 | session.execute(bs); |
| 688 | ``` |
| 689 | |
| 690 | 2. `SimpleStatement` can now take a list of values in addition to the query. This |
| 691 | allows to do the equivalent of a prepare+execute but with only one round-trip |
| 692 | to the server and without keeping the prepared statement after the |
| 693 | execution. |
| 694 | |
| 695 | This is typically useful if a given query should be executed only |
| 696 | once (i.e. you don't want to prepare it) but you also don't want to |
| 697 | serialize all values into strings. Shortcut `Session#execute()` and |
| 698 | `Session#executeAsync()` methods are also provided so you that you can do: |
| 699 | |
| 700 | ```java |
| 701 | String imgName = ...; |
| 702 | ByteBuffer imgBytes = ...; |
| 703 | session.execute("INSERT INTO images(name, bytes) VALUES (?, ?)", imgName, imgBytes); |
| 704 | ``` |
| 705 | |
| 706 | 3. SELECT queries are now "paged" under the hood. In other words, if a query |
| 707 | yields a very large result, only the beginning of the `ResultSet` will be fetched |
| 708 | initially, the rest being fetched "on-demand". In practice, this means that: |
| 709 | |
| 710 | ```java |
| 711 | for (Row r : session.execute("SELECT * FROM mytable")) |
| 712 | ... process r ... |
| 713 | ``` |
| 714 | |
| 715 | should not timeout or OOM the server anymore even if "mytable" contains a lot |
| 716 | of data. In general paging should be transparent for the application (as in |
| 717 | the example above), but the implementation provides a number of knobs to |
| 718 | fine tune the behavior of that paging: |
| 719 | * the size of each "page" can be set per-query (`Statement#setFetchSize()`) |
| 720 | * the `ResultSet` object provides 2 methods to check the state of paging |
| 721 | (`ResultSet#getAvailableWithoutFetching` and `ResultSet#isFullyFetched`) |
| 722 | as well as a mean to force the pre-fetching of the next page (`ResultSet#fetchMoreResults`). |