| 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 | ### 2.1.8 |
| 7 | |
| 8 | 2.1.8 is binary-compatible with 2.1.7 but introduces a small change in the |
| 9 | driver's behavior: |
| 10 | |
| 11 | 1. The list of contact points provided at startup is now shuffled before trying |
| 12 | to open the control connection, so that multiple clients with the same contact |
| 13 | points don't all pick the same control host. As a result, you can't assume that |
| 14 | the driver will try contact points in a deterministic order. In particular, if |
| 15 | you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter |
| 16 | name, make sure that you only provide local hosts as contact points. |
| 17 | |
| 18 | |
| 19 | ### 2.1.7 |
| 20 | |
| 21 | This version brings a few changes in the driver's behavior; none of them break |
| 22 | binary compatibility. |
| 23 | |
| 24 | 1. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable |
| 25 | exception received from a request. The new behaviour will cause the driver to |
| 26 | process a Retry on a different node at most once, otherwise an exception will |
| 27 | be thrown. This change makes sense in the case where the node tried initially |
| 28 | for the request happens to be isolated from the rest of the cluster (e.g. |
| 29 | because of a network partition) but can still answer to the client normally. |
| 30 | In this case, trying another node has a chance of success. |
| 31 | The previous behaviour was to always throw an exception. |
| 32 | |
| 33 | 2. The following properties in `PoolingOptions` were renamed: |
| 34 | * `MaxSimultaneousRequestsPerConnectionThreshold` to `NewConnectionThreshold` |
| 35 | * `MaxSimultaneousRequestsPerHostThreshold` to `MaxRequestsPerConnection` |
| 36 | |
| 37 | The old getters/setters were deprecated, but they delegate to the new |
| 38 | ones. |
| 39 | |
| 40 | Also, note that the connection pool for protocol v3 can now be configured to |
| 41 | use multiple connections. See [this page](../manual/pooling) for more |
| 42 | information. |
| 43 | |
| 44 | 3. `MappingManager(Session)` will now force the initialization of the `Session` |
| 45 | if needed. This is a change from 2.1.6, where if you gave it an uninitialized |
| 46 | session (created with `Cluster#newSession()` instead of `Cluster#connect()`), |
| 47 | it would only get initialized on the first request. |
| 48 | |
| 49 | If this is a problem for you, `MappingManager(Session, ProtocolVersion)` |
| 50 | preserves the previous behavior (see the API docs for more details). |
| 51 | |
| 52 | 4. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()` |
| 53 | or `raw()` is used to build a value to be inserted in the database. |
| 54 | If you know that the CQL functions or expressions are safe, use |
| 55 | `setIdempotent(true)` on the statement. |
| 56 | |
| 57 | ### 2.1.6 |
| 58 | |
| 59 | See [2.0.10](#2-0-x-to-2-0-10). |
| 60 | |
| 61 | |
| 62 | ### 2.1.2 |
| 63 | |
| 64 | 2.1.2 brings important internal changes with native protocol v3 support, but |
| 65 | the impact on the public API has been kept as low as possible. |
| 66 | |
| 67 | #### User API Changes |
| 68 | |
| 69 | 1. The native protocol version is now modelled as an enum: `ProtocolVersion`. |
| 70 | Most public methods that take it as an argument have a backward-compatible |
| 71 | version that takes an `int` (the exception being `RegularStatement`, |
| 72 | described below). For new code, prefer the enum version. |
| 73 | |
| 74 | #### Internal API Changes |
| 75 | |
| 76 | 1. `RegularStatement.getValues` now takes the protocol version as a |
| 77 | `ProtocolVersion` instead of an `int`. This is transparent for callers |
| 78 | since there is a backward-compatible alternative, but if you happened to |
| 79 | extend the class you'll need to update your implementation. |
| 80 | |
| 81 | 2. `BatchStatement.setSerialConsistencyLevel` now returns `BatchStatement` |
| 82 | instead of `Statement`. Again, this only matters if you extended this |
| 83 | class (if so, it might be a good idea to also have a covariant return in |
| 84 | your child class). |
| 85 | |
| 86 | 3. The constructor of `UnsupportedFeatureException` now takes a |
| 87 | `ProtocolVersion` as a parameter. This should impact few users, as there's |
| 88 | hardly any reason to build instances of that class from client code. |
| 89 | |
| 90 | #### New features |
| 91 | |
| 92 | These features are only active when the native protocol v3 is in use. |
| 93 | |
| 94 | 1. The driver now uses a single connection per host (as opposed to a pool in |
| 95 | 2.1.1). Most options in `PoolingOptions` are ignored, except for a new one |
| 96 | called `maxSimultaneousRequestsPerHostThreshold`. See the class's Javadocs |
| 97 | for detailed explanations. |
| 98 | |
| 99 | 2. You can now provide a default timestamp with each query (but it will be |
| 100 | ignored if the CQL query string already contains a `USING TIMESTAMP` |
| 101 | clause). This can be done on a per-statement basis with |
| 102 | `Statement.setDefaultTimestamp`, or automatically with a |
| 103 | `TimestampGenerator` specified with |
| 104 | `Cluster.Builder.withTimestampGenerator` (two implementations are |
| 105 | provided: `ThreadLocalMonotonicTimestampGenerator` and |
| 106 | `AtomicMonotonicTimestampGenerator`). If you specify both, the statement's |
| 107 | timestamp takes precedence over the generator. By default, the driver has |
| 108 | the same behavior as 2.1.1 (no generator, timestamps are assigned by |
| 109 | Cassandra unless `USING TIMESTAMP` was specified). |
| 110 | |
| 111 | 3. `BatchStatement.setSerialConsistencyLevel` no longer throws an exception, |
| 112 | it will honor the serial consistency level for the batch. |
| 113 | |
| 114 | |
| 115 | ### 2.1.1 |
| 116 | |
| 117 | #### Internal API Changes |
| 118 | |
| 119 | 1. The `ResultSet` interface has a new `wasApplied()` method. This will |
| 120 | only affect clients that provide their own implementation of this interface. |
| 121 | |
| 122 | |
| 123 | ### 2.1.0 |
| 124 | |
| 125 | #### User API Changes |
| 126 | |
| 127 | 1. The `getCaching` method of `TableMetadata#Options` now returns a |
| 128 | `Map` to account for changes to Cassandra 2.1. Also, the |
| 129 | `getIndexInterval` method now returns an `Integer` instead of an `int` |
| 130 | which will be `null` when connected to Cassandra 2.1 nodes. |
| 131 | |
| 132 | 2. `BoundStatement` variables that have not been set explicitly will no |
| 133 | longer default to `null`. Instead, all variables must be bound explicitly, |
| 134 | otherwise the execution of the statement will fail (this also applies to |
| 135 | statements inside of a `BatchStatement`). For variables that map to a |
| 136 | primitive Java type, a new `setToNull` method has been added. |
| 137 | We made this change because the driver might soon distinguish between unset |
| 138 | and null variables, so we don't want clients relying on the "leave unset to |
| 139 | set to `null`" behavior. |
| 140 | |
| 141 | |
| 142 | #### Internal API Changes |
| 143 | |
| 144 | The changes listed in this section should normally not impact end users of the |
| 145 | driver, but rather third-party frameworks and tools. |
| 146 | |
| 147 | 1. The `serialize` and `deserialize` methods in `DataType` now take an |
| 148 | additional parameter: the protocol version. As explained in the javadoc, |
| 149 | if unsure, the proper value to use for this parameter is the protocol version |
| 150 | in use by the driver, i.e. the value returned by |
| 151 | `cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`. |
| 152 | |
| 153 | 2. The `parse` method in `DataType` now returns a Java object, not a |
| 154 | `ByteBuffer`. The previous behavior can be obtained by calling the |
| 155 | `serialize` method on the returned object. |
| 156 | |
| 157 | 3. The `getValues` method of `RegularStatement` now takes the protocol |
| 158 | version as a parameter. As above, the proper value if unsure is almost surely |
| 159 | the protocol version in use |
| 160 | (`cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`). |
| 161 | |
| 162 | |
| 163 | ### 2.0.11 |
| 164 | |
| 165 | 2.0.11 preserves binary compatibility with previous versions. There are a few |
| 166 | changes in the driver's behavior: |
| 167 | |
| 168 | 1. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable |
| 169 | exception received from a request. The new behaviour will cause the driver to |
| 170 | process a Retry on a different node at most once, otherwise an exception will |
| 171 | be thrown. This change makes sense in the case where the node tried initially |
| 172 | for the request happens to be isolated from the rest of the cluster (e.g. |
| 173 | because of a network partition) but can still answer to the client normally. |
| 174 | In this case, trying another node has a chance of success. |
| 175 | The previous behaviour was to always throw an exception. |
| 176 | |
| 177 | 2. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()` |
| 178 | or `raw()` is used to build a value to be inserted in the database. |
| 179 | If you know that the CQL functions or expressions are safe, use |
| 180 | `setIdempotent(true)` on the statement. |
| 181 | |
| 182 | 3. The list of contact points provided at startup is now shuffled before trying |
| 183 | to open the control connection, so that multiple clients with the same contact |
| 184 | points don't all pick the same control host. As a result, you can't assume that |
| 185 | the driver will try contact points in a deterministic order. In particular, if |
| 186 | you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter |
| 187 | name, make sure that you only provide local hosts as contact points. |
| 188 | |
| 189 | |
| 190 | ### <a name="2-0-x-to-2-0-10"></a>2.0.x to 2.0.10 |
| 191 | |
| 192 | We try to avoid breaking changes within a branch (2.0.x to 2.0.y), but |
| 193 | 2.0.10 saw a lot of new features and internal improvements. There is one |
| 194 | breaking change: |
| 195 | |
| 196 | 1. `LatencyTracker#update` now has a different signature and takes two new |
| 197 | parameters: the statement that has been executed (never null), and the exception |
| 198 | thrown while executing the query (or null, if the query executed successfully). |
| 199 | Existing implementations of this interface, once upgraded to the new method |
| 200 | signature, should continue to work as before. |
| 201 | |
| 202 | The following might also be of interest: |
| 203 | |
| 204 | 2. `SocketOptions#getTcpNoDelay()` is now TRUE by default (it was previously undefined). |
| 205 | This reflects the new behavior of Netty (which was upgraded from version 3.9.0 to |
| 206 | 4.0.27): `TCP_NODELAY` is now turned on by default, instead of depending on the OS |
| 207 | default like in previous versions. |
| 208 | |
| 209 | 3. Netty is not shaded anymore in the default Maven artifact. However we publish a |
| 210 | [shaded artifact](../manual/shaded_jar/) under a different classifier. |
| 211 | |
| 212 | 4. The internal initialization sequence of the Cluster object has been slightly changed: |
| 213 | some fields that were previously initialized in the constructor are now set when |
| 214 | the `init()` method is called. In particular, `Cluster#getMetrics()` will return |
| 215 | `null` until the cluster is initialized. |
| 216 | |
| 217 | ### 1.0 to 2.0 |
| 218 | |
| 219 | We used the opportunity of a major version bump to incorporate your feedback |
| 220 | and improve the API, to fix a number of inconsistencies and remove cruft. |
| 221 | Unfortunately this means there are some breaking changes, but the new API should |
| 222 | be both simpler and more complete. |
| 223 | |
| 224 | The following describes the changes for 2.0 that are breaking changes of the |
| 225 | 1.0 API. For ease of use, we distinguish two categories of API changes: the "main" |
| 226 | ones and the "other" ones. |
| 227 | |
| 228 | The "main" API changes are the ones that are either |
| 229 | likely to affect most upgraded apps or are incompatible changes that, even if minor, |
| 230 | will not be detected at compile time. Upgraders are highly encouraged to check |
| 231 | this list of "main" changes while upgrading their application to 2.0 (even |
| 232 | though most applications are likely to be affected by only a handful of |
| 233 | changes). |
| 234 | |
| 235 | The "other" list is, well, other changes: those that are likely to |
| 236 | affect a minor number of applications and will be detected by compile time |
| 237 | errors anyway. It is ok to skip those initially and only come back to them if |
| 238 | you have trouble compiling your application after an upgrade. |
| 239 | |
| 240 | #### Main API changes |
| 241 | |
| 242 | 1. The `Query` class has been renamed into `Statement` (it was confusing |
| 243 | to some that the `BoundStatement` was not a `Statement`). To allow |
| 244 | this, the old `Statement` class has been renamed to `RegularStatement`. |
| 245 | |
| 246 | 2. The `Cluster` and `Session` shutdown API has changed. There is now a |
| 247 | `closeAsync` that is asynchronous but returns a `Future` on the |
| 248 | completion of the shutdown process. There is also a `close` shortcut |
| 249 | that does the same but blocks. Also, `close` now waits for ongoing |
| 250 | queries to complete by default (but you can force the closing of all |
| 251 | connections if you want to). |
| 252 | |
| 253 | 3. `NoHostAvailableException#getErrors` now returns the full exception objects for |
| 254 | each node instead of just a message. In other words, it returns a |
| 255 | `Map<InetAddress, Throwable>` instead of a `Map<InetAddress, String>`. |
| 256 | |
| 257 | 4. `Statement#getConsistencyLevel` (previously `Query#getConsistencyLevel`, see |
| 258 | first point) will now return `null` by default (instead of `CL.ONE`), with the |
| 259 | meaning of "use the default consistency level". |
| 260 | The default consistency level can now be configured through the new `QueryOptions` |
| 261 | object in the cluster `Configuration`. |
| 262 | |
| 263 | 5. The `Metrics` class now uses the Codahale metrics library version 3 (version 2 was |
| 264 | used previously). This new major version of the library has many API changes |
| 265 | compared to its version 2 (see the [release notes](https://dropwizard.github.io/metrics/3.1.0/about/release-notes/) for details), |
| 266 | which can thus impact consumers of the Metrics class. |
| 267 | Furthermore, the default `JmxReporter` now includes a name specific to the |
| 268 | cluster instance (to avoid conflicts when multiple Cluster instances are created |
| 269 | in the same JVM). As a result, tools that were polling JMX info will |
| 270 | have to be updated accordingly. |
| 271 | |
| 272 | 6. The `QueryBuilder#in` method now has the following special case: using |
| 273 | `QueryBuilder.in(QueryBuilder.bindMarker())` will generate the string `IN ?`, |
| 274 | not `IN (?)` as was the case in 1.0. The reasoning being that the former |
| 275 | syntax, made valid by [CASSANDRA-4210](https://issues.apache.org/jira/browse/CASSANDRA-4210) |
| 276 | is a lot more useful than `IN (?)`, as the latter can more simply use an |
| 277 | equality. |
| 278 | Note that if you really want to output `IN (?)` with the query |
| 279 | builder, you can use `QueryBuilder.in(QueryBuilder.raw("?"))`. |
| 280 | |
| 281 | 7. When binding values by name in `BoundStatement` (i.e. using the |
| 282 | `setX(String, X)` methods), if more than one variable have the same name, |
| 283 | then all values corresponding to that variable |
| 284 | name are set instead of just the first occurrence. |
| 285 | |
| 286 | 8. The `QueryBuilder#raw` method does not automatically add quotes anymore, but |
| 287 | rather output its result without any change (as the raw name implies). |
| 288 | This means for instance that `eq("x", raw(foo))` will output `x = foo`, |
| 289 | not `x = 'foo'` (you don't need the raw method to output the latter string). |
| 290 | |
| 291 | 9. The `QueryBuilder` will now sometimes use the new ability to send value as |
| 292 | bytes instead of serializing everything to string. In general the QueryBuilder |
| 293 | will do the right thing, but if you were calling the `getQueryString()` method |
| 294 | on a Statement created with a QueryBuilder (for other reasons than to prepare a query) |
| 295 | then the returned string may contain bind markers in place of some of the values |
| 296 | provided (and in that case, `getValues()` will contain the values corresponding |
| 297 | to those markers). If need be, it is possible to force the old behavior by |
| 298 | using the new `setForceNoValues()` method. |
| 299 | |
| 300 | #### Other API Changes |
| 301 | |
| 302 | 1. Creating a Cluster instance (through `Cluster#buildFrom` or the |
| 303 | `Cluster.Builder#build` method) **does not create any connection right away |
| 304 | anymore** (and thus cannot throw a `NoHostAvailableException` or an |
| 305 | `AuthenticationException`). Instead, the initial contact points are checked |
| 306 | the first time a call to `Cluster#connect` is done. If for some reason you |
| 307 | want to emulate the previous behavior, you can use the new method |
| 308 | `Cluster#init`: `Cluster.builder().build()` in 1.0 is equivalent to |
| 309 | `Cluster.builder().build().init()` in 2.0. |
| 310 | |
| 311 | 2. Methods from `Metadata`, `KeyspaceMetadata` and `TableMetadata` now use by default |
| 312 | case insensitive identifiers (for keyspace, table and column names in |
| 313 | parameter). You can double-quote an identifier if you want it to be a |
| 314 | case sensitive one (as you would do in CQL) and there is a `Metadata.quote` |
| 315 | helper method for that. |
| 316 | |
| 317 | 3. The `TableMetadata#getClusteringKey` method has been renamed |
| 318 | `TableMetadata#getClusteringColumns` to match the "official" vocabulary. |
| 319 | |
| 320 | 4. The `UnavailableException#getConsistency` method has been renamed to |
| 321 | `UnavailableException#getConsistencyLevel` for consistency with the method of |
| 322 | `QueryTimeoutException`. |
| 323 | |
| 324 | 5. The `RegularStatement` class (ex-`Statement` class, see above) must now |
| 325 | implement two additional methods: `RegularStatement#getKeyspace` and |
| 326 | `RegularStatement#getValues`. If you had extended this class, you will have to |
| 327 | implement those new methods, but both can return null if they are not useful |
| 328 | in your case. |
| 329 | |
| 330 | 6. The `Cluster.Initializer` interface should now implement 2 new methods: |
| 331 | `Cluster.Initializer#getInitialListeners` (which can return an empty |
| 332 | collection) and `Cluster.Initializer#getClusterName` (which can return null). |
| 333 | |
| 334 | 7. The `Metadata#getReplicas` method now takes 2 arguments. On top of the |
| 335 | partition key, you must now provide the keyspace too. The previous behavior |
| 336 | was buggy: it's impossible to properly return the full list of replica for a |
| 337 | partition key without knowing the keyspace since replication may depend on |
| 338 | the keyspace). |
| 339 | |
| 340 | 8. The method `LoadBalancingPolicy#newQueryPlan()` method now takes the currently |
| 341 | logged keyspace as 2nd argument. This information is necessary to do proper |
| 342 | token aware balancing (see preceding point). |
| 343 | |
| 344 | 9. The `ResultSetFuture#set` and `ResultSetFuture#setException` methods have been |
| 345 | removed (from the public API at least). They were never meant to be exposed |
| 346 | publicly: a `resultSetFuture` is always set by the driver itself and should |
| 347 | not be set manually. |
| 348 | |
| 349 | 10. The deprecated since 1.0.2 `Host.HealthMonitor` class has been removed. You |
| 350 | will now need to use `Host#isUp` and `Cluster#register` if you were using that |
| 351 | class. |
| 352 | |
| 353 | #### Features available only with Cassandra 2.0 |
| 354 | |
| 355 | This section details the biggest additions to 2.0 API wise. It is not an |
| 356 | exhaustive list of new features in 2.0. |
| 357 | |
| 358 | 1. The new `BatchStatement` class allows to group any type of insert Statements |
| 359 | (`BoundStatement` or `RegularStatement`) for execution as a batch. For instance, |
| 360 | you can do something like: |
| 361 | |
| 362 | ```java |
| 363 | List<String> values = ...; |
| 364 | PreparedStatement ps = session.prepare("INSERT INTO myTable(value) VALUES (?)"); |
| 365 | BatchStatement bs = new BatchStatement(); |
| 366 | for (String value : values) |
| 367 | bs.add(ps.bind(value)); |
| 368 | session.execute(bs); |
| 369 | ``` |
| 370 | |
| 371 | 2. `SimpleStatement` can now take a list of values in addition to the query. This |
| 372 | allows to do the equivalent of a prepare+execute but with only one round-trip |
| 373 | to the server and without keeping the prepared statement after the |
| 374 | execution. |
| 375 | |
| 376 | This is typically useful if a given query should be executed only |
| 377 | once (i.e. you don't want to prepare it) but you also don't want to |
| 378 | serialize all values into strings. Shortcut `Session#execute()` and |
| 379 | `Session#executeAsync()` methods are also provided so you that you can do: |
| 380 | |
| 381 | ```java |
| 382 | String imgName = ...; |
| 383 | ByteBuffer imgBytes = ...; |
| 384 | session.execute("INSERT INTO images(name, bytes) VALUES (?, ?)", imgName, imgBytes); |
| 385 | ``` |
| 386 | |
| 387 | 3. SELECT queries are now "paged" under the hood. In other words, if a query |
| 388 | yields a very large result, only the beginning of the `ResultSet` will be fetched |
| 389 | initially, the rest being fetched "on-demand". In practice, this means that: |
| 390 | |
| 391 | ```java |
| 392 | for (Row r : session.execute("SELECT * FROM mytable")) |
| 393 | ... process r ... |
| 394 | ``` |
| 395 | |
| 396 | should not timeout or OOM the server anymore even if "mytable" contains a lot |
| 397 | of data. In general paging should be transparent for the application (as in |
| 398 | the example above), but the implementation provides a number of knobs to |
| 399 | fine tune the behavior of that paging: |
| 400 | * the size of each "page" can be set per-query (`Statement#setFetchSize()`) |
| 401 | * the `ResultSet` object provides 2 methods to check the state of paging |
| 402 | (`ResultSet#getAvailableWithoutFetching` and `ResultSet#isFullyFetched`) |
| 403 | as well as a mean to force the pre-fetching of the next page (`ResultSet#fetchMoreResults`). |