On behalf of the SDK Team, it is my great pleasure to announce that the Java SDK version
2.2 is now GA!
This version is packed with enhancements and bugfixes. First and foremost it offers compatibility with all the new shiny things our new
Couchbase Server 4.0 brings to the table.
Thanks to feedback and after quite a few iterations (there were not one but two Developer Previews for this release!), we now have a rich set of improvements to take advantage of when migrating from
See the release notes for a complete list of changes, but here is a recap:
- Switched from hot observables to cold ones
- Extended support for N1QL and Multi-Dimensional Scaling (MDS)
- Enhanced durability support
- Supportability enhancements with metrics
- Simple ODM
- Sync and Async API enhancements
- Misc (naming changes, dependency upgrades)
To get your hands on this release, simply update your
pom.xml (or download the archive):
The SDK has been tuned to seamlessly work with
Couchbase Server 4.0:
Explore a full DSL to work with N1QL and perform SELECT as well as work with indexes.
Let the SDK and the query service optimize queries you run often by using the
Rely on the SDK to be aware of your
Multi Dimensional Scaling, the possibility for nodes to have different services enabled, allowing you to scale nodes up according to their need, eg. more RAM for data nodes, more CPU for query nodes).
About query optimization: this is a replacement of the initial
prepare API in developer previews. No need to hold on to a
QueryPlan. Marking a query for optimization using
adhoc(false) method will internally use prepared statement feature of the query engine, caching up to 5000 execution plans for faster execution.
Another possibility introduced in
Couchbase Server 4.0 is enhanced durability. The idea is that rather than using CAS to check correct persistence and replication of your data, a finer grained
MutationToken can be emitted by the server with each mutation and used for durability observation.
It allows to ensure a specific mutation has been seen on a replica even if a newer mutation is made in the meantime (changing yet again the CAS on the master and replica). It also allows for more correct state detection if a hard failover has been triggered in the cluster.
To activate this feature on the
CouchbaseEnvironment use the
Note This implies that additional bytes are sent by the server on each mutation response, so it comes with a slight overhead and therefore is turned off by default.
What is going on inside the SDK? What is the health of my JVM? Are those latencies due to network round trips or are they occuring in the SDK?
All these questions and more find answers through the new Metrics feature!
Latency metrics are collected all the time, and are regularly dumped to the
Observable itself), by default every hour. Additionaly to changing the interval for the dump, one can easily configure a consumer for these metric events that logs them.
Have a look at the documentation to discover all the nitty gritty details of it 🙂
We are exploring ODM (
Object-Document Mapping) in the form of a
Repository interface that allows to store Entity classes directly, provided they are simple enough (eg. for now it needs an empty constructor) and annotated with
This is a major change to the behavior of the
async API. In
RxJava, a hot
Observable will emit data wether or not someone is listening/subscribing, and will always serve the same data to new subscribers.
This was the behavior of Couchbase SDK Observables previously. This meant that if you needed new subscriptions to trigger a new operation on the database (for example in the context of
retry), you had to wrap your call in a
Otherwise all retries would see the same first result, for example a
2.2 onwards, the default behavior is to have cold
Observables, meaning that the wrapping in
defer is now redundant. All SDK calls will seamlessly work with
Unless you explicitely
subscribe() to an
Observable returned by the SDK, no db interaction is triggered. This is a lazier “do nothing until needed” approach that is also beneficial while declaring fallback streams (like with
In the sync API, there is now an overload of
getFromReplica that returns an
Iterator, allowing for easy consumption of only part of the responses (eg. when only interested in the fastest response).
Still in the sync API, if you want your
ViewQuery to efficiently retrieve the whole content of the documents in the background, you can now use the
counter method would initialize the counter document with the default value of 0 if no
initialValue was provided in the overload.
This has been changed so that instead, a
DocumentDoesNotExistException is thrown with these kind of overloads (like in the 1.4 SDK generation). To initialize with 0 instead of erroring, simply use one of the overloads that accept an
Durability Requirement Support for
Previously no overload would allow to set a
ReplicateTo durability requirement. This has now been implemented.
CASMismatchException instead of
As the title implies, where both methods would just return a generic
Design Document Options
You can now specify different options on a per design document basis when creating or replacing one.
CouchbaseEnvironment: Avoiding Confusion
CouchbaseEnvironment.Builder doesn't implement the interface anymore, forcing you to call
build() to obtain the actual environment (and thus avoiding confusing
NullPointerException during usage).
Some classes related to
N1QL have been renamed to avoid confusion and better align with other similar classes and/or other SDKs:
Queryrelated classes have been prefixed with
AsyncN1qlQueryResult). This is more consistent with the naming eg. for views (
The various instances of the word
parametrizedhave been replaced with
parameterizedacross documentation and the SDKs. For example in
N1qlQuery.parameterized(Statement st, JsonObject paramValues)factory method…
The following external dependency had been updated:
Additionaly, internal dependencies have also been updated:
LatencyUtilsnew in version