@@ -5,16 +5,6 @@ is used to order operations relative to each other.
55
66There are various ways to assign it:
77
8- ### Server-side generation
9-
10- If the client does not specify any timestamp, the server will assign one
11- based on the time it receives the query.
12-
13- This can be a problem when the order of the writes matter: with unlucky
14- timing (different coordinators, network latency, etc.), two successive
15- requests from the same client might be processed in a different order
16- server-side, and end up with out-of-order timestamps.
17-
188### CQL ` USING TIMESTAMP `
199
2010You can explicitly provide the timestamp in your CQL query:
@@ -24,29 +14,24 @@ session.execute("INSERT INTO my_table(c1, c2) values (1, 1) " +
2414 " USING TIMESTAMP 1432815430948040" );
2515```
2616
27- This solves the problems of server-side generation: the client has
28- control over the ordering of the statements it generates. On the other
29- hand, it puts the burden of generating timestamps on client code.
30-
3117### Client-side generation
3218
33- Starting with version 2.1.2 of the driver, and if [ native
34- protocol] ( ../native_protocol/ ) v3 or above is in use, a * default
35- timestamp * can be sent with each query .
19+ This is enabled by default if you're using the driver 2.2 and a version
20+ of Cassandra that supports [ native protocol] ( ../native_protocol ) v3 or
21+ above .
3622
37- To enable this feature, provide an instance of [ TimestampGenerator] [ tsg ]
38- at initialization:
23+ A client timestamp will be sent by each query. It is generated by a
24+ [ TimestampGenerator] [ tsg ] . The default implementation is
25+ [ AtomicMonotonicTimestampGenerator] [ amtsg ] .
26+
27+ You can specify another generator at initialization:
3928
4029``` java
4130Cluster . builder(). addContactPoint(" 127.0.0.1" )
42- .withTimestampGenerator(new AtomicMonotonicTimestampGenerator ())
31+ .withTimestampGenerator(new MyCustomTimestampGenerator ())
4332 .build();
4433```
4534
46- The default is still server-side generation. So unless you explicitly
47- provide a generator, you get the same behavior as previous driver
48- versions.
49-
5035In addition, you can also override the default timestamp on a
5136per-statement basis:
5237
@@ -58,6 +43,22 @@ session.execute(statement);
5843```
5944
6045[ tsg ] : http://docs.datastax.com/en/drivers/java/2.2/com/datastax/driver/core/TimestampGenerator.html
46+ [ amtsg ] : http://docs.datastax.com/en/drivers/java/2.2/com/datastax/driver/core/AtomicMonotonicTimestampGenerator.html
47+
48+
49+ ### Server-side generation
50+
51+ This is the "legacy" behavior if you're connected to a Cassandra version
52+ that only supports protocol v2 or below. The server will assign a
53+ timestamp based on the time it receives the query.
54+
55+ This can be a problem when the order of the writes matter: with unlucky
56+ timing (different coordinators, network latency, etc.), two successive
57+ requests from the same client might be processed in a different order
58+ server-side, and end up with out-of-order timestamps. If protocol v3 is
59+ not an option, the only workaround is to add ` USING TIMESTAMP ` in your
60+ queries.
61+
6162
6263### Summary
6364
0 commit comments