Skip to content

Commit ed7b08d

Browse files
committed
docs: Added timestamp generator docs
1 parent ef93421 commit ed7b08d

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

docs/source/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [USE keyspace](queries/usekeyspace.md)
2828
- [Schema agreement](queries/schema-agreement.md)
2929
- [Query timeouts](queries/timeouts.md)
30+
- [Timestamp generators](queries/timestamp-generators.md)
3031

3132
- [Execution profiles](execution-profiles/execution-profiles.md)
3233
- [Creating a profile and setting it](execution-profiles/create-and-use.md)

docs/source/queries/queries.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Driver supports all kinds of statements supported by ScyllaDB. The following tables aim to bridge between DB concepts and driver's API.
44
They include recommendations on which API to use in what cases.
55

6-
## Kinds of CQL statements (from the CQL protocol point of view):
6+
## Kinds of CQL statements (from the CQL protocol point of view)
77

88
| Kind of CQL statement | Single | Batch |
99
|-----------------------|---------------------|------------------------------------------|
@@ -59,7 +59,7 @@ This is **NOT** strictly related to content of the CQL query string.
5959
| Load balancing | advanced if prepared, else primitive | advanced if prepared **and ALL** statements in the batch target the same partition, else primitive |
6060
| Suitable operations | most of operations | - a list of operations that needs to be executed atomically (batch LightWeight Transaction)</br> - a batch of operations targetting the same partition (as an advanced optimisation) |
6161

62-
## CQL statements - operations (based on what the CQL string contains):
62+
## CQL statements - operations (based on what the CQL string contains)
6363

6464
| CQL data manipulation statement | Recommended statement kind | Recommended Session operation |
6565
|------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
@@ -86,9 +86,10 @@ This is **NOT** strictly related to content of the CQL query string.
8686

8787
For more detailed comparison and more best practices, see [doc page about paging](paged.md).
8888

89-
### Queries are fully asynchronous - you can run as many of them in parallel as you wish.
89+
### Queries are fully asynchronous - you can run as many of them in parallel as you wish
90+
91+
## `USE KEYSPACE`
9092

91-
## `USE KEYSPACE`:
9293
There is a special functionality to enable [USE keyspace](usekeyspace.md).
9394

9495
```{eval-rst}
@@ -106,4 +107,5 @@ There is a special functionality to enable [USE keyspace](usekeyspace.md).
106107
schema-agreement
107108
lwt
108109
timeouts
110+
timestamp-generators
109111
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Timestamp generators
2+
3+
If you want to generate timestamps on the client side you can provide
4+
a TimestampGenerator to a SessionBuilder when creating a Session. Then
5+
every executed statement will have attached a new timestamp generated
6+
by the provided TimestampGenerator.
7+
Timestamps are set according to precendence:
8+
9+
1. ```USING TIMESTAMP``` in the query itself
10+
2. Manually using ```set_timestamp``` on the query
11+
3. Timestamp generated by the generator
12+
13+
## Simple Timestamp Generator
14+
15+
Most basic client-side timestamp generator. Generates timestamp
16+
based on system clock. Provides no guarantees and panics when the system clock
17+
provides timestamp before the unix epoch.
18+
19+
## Monotonic Timestamp Generator
20+
21+
Client-side timestamp generator. Guarantees monotonic timestamps
22+
based on the system clock, with automatic timestamp incrementation
23+
if the system clock timestamp would not be monotonic. If the clock skew
24+
exceeds `warning_threshold` of the generator (can be changed with `with_warning_times`, 1s by default)
25+
user will be warned with timestamp generation with `warning_interval` cooldown period
26+
(can be changed with `with_warning_times`, 1s by default) to not spam the user. If user does not want to
27+
be warned about the clock skew, the warnings can be turned off with `without_warnings` function.
28+
29+
``` rust
30+
# extern crate scylla;
31+
# use std::error::Error;
32+
# async fn check_only_compiles() -> Result<(), Box<dyn std::error::Error>> {
33+
use scylla::client::session::Session;
34+
use scylla::client::session_builder::SessionBuilder;
35+
use scylla::policies::timestamp_generator::MonotonicTimestampGenerator;
36+
use scylla::query::Query;
37+
use std::sync::Arc;
38+
39+
let session: Session = SessionBuilder::new()
40+
.known_node("127.0.0.1:9042")
41+
.timestamp_generator(Arc::new(MonotonicTimestampGenerator::new()))
42+
.build()
43+
.await?;
44+
45+
// This query will have a timestamp generated
46+
// by the monotonic timestamp generator
47+
let my_query: Query = Query::new("INSERT INTO ks.tab (a) VALUES(?)");
48+
let to_insert: i32 = 12345;
49+
session.query_unpaged(my_query, (to_insert,)).await?;
50+
# Ok(())
51+
# }
52+
```
53+
54+

0 commit comments

Comments
 (0)