Elffuss BraidHub

kikocis/java-driver public

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