Elffuss BraidHub

kikocis/java-driver public

Document native protocol.
Changeset92782d18ab290d4baae213b087dcdce93624c157adcda616c7da09e6654ef6fd
Authorolim7t <omichallat+github@gmail.com> · 2015-05-06 17:05 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-05-14 16:30 +02:00
Parents4b4f49c77b5f

Browse the files at this changeset

1 file changed

added features/native_protocol/README.md +93 −0
@@ -0,0 +1,93 @@
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></tr>
20+<tr><td>Driver: 1.0.x</td> <td>v1</td> <td>v1</td></tr>
21+<tr><td>2.0.x or more</td> <td>v1</td> <td>v2</td></tr>
22+</table>
23+
24+For example, if you use version 2.0.10 of the driver to connect to
25+Cassandra 1.2.19, the maximum version you can use (and the one you'll get
26+by default) is protocol v1 (bottom line, left column). If you use the
27+same version to connect to Cassandra 2.0.9, you can use protocol v2.
28+
29+### Controlling the protocol version
30+
31+To find out which version you're currently using, use
32+[ProtocolOptions#getProtocolVersion()][gpv]:
33+
34+```java
35+int myCurrentVersion = cluster.getConfiguration()
36+ .getProtocolOptions()
37+ .getProtocolVersion();
38+```
39+
40+The protocol version can not be changed at runtime. However, you can
41+force a given version at initialization:
42+
43+```java
44+Cluster cluster = Cluster.builder()
45+ .addContactPoint("127.0.0.1")
46+ .withProtocolVersion(1)
47+ .build();
48+```
49+
50+If you specify a version that is not compatible with your current
51+driver/Cassandra combination, you'll get an error:
52+
53+```
54+Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException:
55+All host(s) tried for query failed
56+(tried: /127.0.0.1:9042 (com.datastax.driver.core.UnsupportedProtocolVersionException:
57+ [/127.0.0.1:9042] Host /127.0.0.1:9042 does not support protocol version 2))
58+```
59+
60+[gpv]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/ProtocolOptions.html#getProtocolVersion()
61+
62+#### Protocol version with mixed clusters
63+
64+If you have a cluster with mixed versions (for example, while doing a
65+rolling upgrade of Cassandra), note that **the protocol version will be
66+negotiated with the first host the driver connects to**.
67+
68+This could lead to the following situation (assuming you use driver
69+2.x):
70+
71+* the first contact point is a 2.0 host, so the driver negotiates
72+ protocol v2;
73+* while connecting to the rest of the cluster, the driver contacts a 1.2
74+ host using protocol v2, which fails; an error is logged and this host
75+ will be permanently ignored.
76+
77+To avoid this issue, you can use one the following workarounds:
78+
79+* always force a protocol version at startup. You keep it at v1 while
80+ the rolling upgrade is happening, and only switch to v2 when the whole
81+ cluster has switched to Cassandra 2.0;
82+* ensure that the list of initial contact points only contains hosts
83+ with the oldest version (1.2 in this example).
84+
85+
86+### New features by protocol version
87+
88+#### v1 to v2
89+
90+* bound variables in simple statements
91+ ([Session#execute(String, Object...)](http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/Session.html#execute(java.lang.String,%20java.lang.Object...)))
92+* [batch statements](http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/BatchStatement.html)
93+* [query paging](../paging/)