Skip to content

Commit 4ad3cd7

Browse files
committed
docs: Added timestamp generator docs
1 parent 55b556d commit 4ad3cd7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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, as longas the statement did not
7+
already have a timestamp provided (e.g. by using the `TIMESTAMP` clause).
8+
9+
## Monotonic Timestamp Generator
10+
11+
Most basic client-side timestamp generator. Guarantees monotonic timestamps
12+
based on the system clock, with automatic timestamp incrementation
13+
if the system clock timestamp would not be monotonic. If the clock skew
14+
exceeds warning_threshold of the generator (provided in the constructor, 1s by default)
15+
user will be warned with timestamp generation with warning_interval cooldown period
16+
(provided in the constructor, 1s by default) to not spam the user.
17+
18+
``` rust
19+
# extern crate scylla;
20+
# use std::error::Error;
21+
# async fn check_only_compiles() -> Result<(), Box<dyn std::error::Error>> {
22+
use scylla::{Session, SessionBuilder};
23+
use scylla::transport::timestamp_generator::MonotonicTimestampGenerator;
24+
use std::sync::Arc;
25+
use std::time::Duration;
26+
27+
let session: Session = SessionBuilder::new()
28+
.known_node("127.0.0.1:9042")
29+
.timestamp_generator(Arc::new(MonotonicTimestampGenerator::new()))
30+
.build()
31+
.await?;
32+
33+
// This query will have a timestamp generated
34+
// by the monotonic timestamp generator
35+
let my_query: Query = Query::new("INSERT INTO ks.tab (a) VALUES(?)");
36+
let to_insert: i32 = 12345;
37+
session.query_unpaged(my_query, (to_insert,)).await?;
38+
# Ok(())
39+
# }
40+
41+

0 commit comments

Comments
 (0)