Elffuss BraidHub

kikocis/java-driver public

Document native protocol.
Changesetb728b57e853cee01c8e7437e46465dafa0d331bd47a4939de41d17d2b98a03aa
Authorolim7t <omichallat+github@gmail.com> · 2015-05-06 17:05 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-05-06 20:00 +02:00
Parents122608dec4ea

Browse the files at this changeset

2 files changed

added features/native_protocol/README.md +101 −0
@@ -0,0 +1,101 @@
1+## Native protocol
2+
3+The native protocol defines the format of the binary messages exchanged
4+between the driver and Cassandra over TCP. As a driver user, you don't
5+need to know the fine details (although the protocol spec is [in the
6+Cassandra codebase][native_spec] if you're curious); the most visible
7+aspect is that some features are only available with specific protocol
8+versions.
9+
10+[native_spec]: https://git-wip-us.apache.org/repos/asf?p=cassandra.git;a=tree;f=doc;hb=HEAD
11+
12+### Compatibility matrix
13+
14+By default, the protocol version is negotiated between the driver and
15+Cassandra when the first connection is established. Both sides are
16+backward-compatible with older versions:
17+
18+<table border="1" style="text-align:center; width:100%;margin-bottom:1em;">
19+<tr><td>&nbsp;</td><td>Cassandra: 1.2.x<br/>(DSE 3.2)</td><td>2.0.x<br/>(DSE 4.0 to 4.6)</td><td>2.1.x<br/>(DSE 4.7)</td></tr>
20+<tr><td>Driver: 1.0.x</td> <td>v1</td> <td>v1</td> <td>v1</td> </tr>
21+<tr><td>2.0.x to 2.1.1</td> <td>v1</td> <td>v2</td> <td>v2</td> </tr>
22+<tr><td>2.1.2 or more</td> <td>v1</td> <td>v2</td> <td>v3</td> </tr>
23+</table>
24+
25+For example, if you use version 2.1.5 of the driver to connect to
26+Cassandra 2.0.9, the maximum version you can use (and the one you'll get
27+by default) is protocol v2 (last line, middle column). If you use the
28+same version to connect to Cassandra 2.1.4, you can use protocol v3.
29+
30+### Controlling the protocol version
31+
32+To find out which version you're currently using, use
33+[ProtocolOptions#getProtocolVersionEnum()][gpve]:
34+
35+```java
36+ProtocolVersion myCurrentVersion = cluster.getConfiguration()
37+ .getProtocolOptions()
38+ .getProtocolVersionEnum();
39+```
40+
41+The protocol version can not be changed at runtime. However, you can
42+force a given version at initialization:
43+
44+```java
45+Cluster cluster = Cluster.builder()
46+ .addContactPoint("127.0.0.1")
47+ .withProtocolVersion(ProtocolVersion.V2)
48+ .build();
49+```
50+
51+If you specify a version that is not compatible with your current
52+driver/Cassandra combination, you'll get an error:
53+
54+```
55+Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException:
56+All host(s) tried for query failed
57+(tried: /127.0.0.1:9042 (com.datastax.driver.core.UnsupportedProtocolVersionException:
58+ [/127.0.0.1:9042] Host /127.0.0.1:9042 does not support protocol version V3 but V2))
59+```
60+
61+[gpve]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/ProtocolOptions.html#getProtocolVersionEnum()
62+
63+#### Protocol version with mixed clusters
64+
65+If you have a cluster with mixed versions (for example, while doing a
66+rolling upgrade of Cassandra), note that **the protocol version will be
67+negotiated with the first host the driver connects to**.
68+
69+This could lead to the following situation (assuming you use driver
70+2.1.2+):
71+
72+* the first contact point is a 2.1 host, so the driver negotiates
73+ protocol v3;
74+* while connecting to the rest of the cluster, the driver contacts a 2.0
75+ host using protocol v3, which fails; an error is logged and this host
76+ will be permanently ignored.
77+
78+To avoid this issue, you can use one the following workarounds:
79+
80+* always force a protocol version at startup. You keep it at v2 while
81+ the rolling upgrade is happening, and only switch to v3 when the whole
82+ cluster has switched to Cassandra 2.1;
83+* ensure that the list of initial contact points only contains hosts
84+ with the oldest version (2.0 in this example).
85+
86+
87+### New features by protocol version
88+
89+#### v1 to v2
90+
91+* bound variables in simple statements
92+ ([Session#execute(String, Object...)](http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/Session.html#execute(java.lang.String,%20java.lang.Object...)))
93+* [batch statements](http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/BatchStatement.html)
94+* [query paging](../paging/)
95+
96+#### v2 to v3
97+
98+* the number of stream ids per connection goes from 128 to 32768 (see
99+ [Connection pooling](../pooling/))
100+* [serial consistency on batch statements](http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/BatchStatement.html#setSerialConsistencyLevel(com.datastax.driver.core.ConsistencyLevel))
101+* [client-side timestamps](../query_timestamps/)
added features/query_timestamps/README.md +4 −0
@@ -0,0 +1,4 @@
1+## Query timestamps
2+
3+*Work in progress*: this will be adapted from
4+http://www.datastax.com/dev/blog/java-driver-2-1-2-native-protocol-v3