Elffuss BraidHub

kikocis/java-driver public

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