Skip to content

Commit 2edebf9

Browse files
committed
Update query timestamps doc now that client-side is the default.
1 parent 20b2828 commit 2edebf9

2 files changed

Lines changed: 29 additions & 32 deletions

File tree

features/query_timestamps/README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ is used to order operations relative to each other.
55

66
There 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

2010
You 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
4130
Cluster.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-
5035
In addition, you can also override the default timestamp on a
5136
per-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

features/speculative_execution/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,7 @@ But now the second execution of the first query finally reaches its
332332
target node, which applies the mutation. The row that you've just
333333
deleted is back!
334334

335-
The workaround is to use a timestamp with your queries:
336-
337-
insert into my_table (k, v) values (1, 1) USING TIMESTAMP 1432764000;
338-
339-
If you're using native protocol v3, you can also enable client-side
340-
timestamps to have this done automatically; see
341-
[this blog post](http://www.datastax.com/dev/blog/java-driver-2-1-2-native-protocol-v3)
342-
for more information.
335+
The workaround is to use
336+
[client-sidetimestamps](../query_timestamps/#client-side-generation) (if
337+
you're using native protocol v3 or more, the driver already does this
338+
automatically.

0 commit comments

Comments
 (0)