-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Added timestamp generator docs
- Loading branch information
Showing
3 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Timestamp generators | ||
|
||
If you want to generate timestamps on the client side you can provide | ||
a TimestampGenerator to a SessionBuilder when creating a Session. Then | ||
every executed statement will have attached a new timestamp generated | ||
by the provided TimestampGenerator. | ||
Timestamps are set according to precendence: | ||
|
||
1. ```USING TIMESTAMP``` in the query itself | ||
2. Manually using ```set_timestamp``` on the query | ||
3. Timestamp generated by the generator | ||
|
||
## Simple Timestamp Generator | ||
|
||
Most basic client-side timestamp generator. Generates timestamp | ||
based on system clock. Provides no guarantees and panic when the system clock | ||
provides timestamp before the unix epoch. | ||
|
||
## Monotonic Timestamp Generator | ||
|
||
Client-side timestamp generator. Guarantees monotonic timestamps | ||
based on the system clock, with automatic timestamp incrementation | ||
if the system clock timestamp would not be monotonic. If the clock skew | ||
exceeds warning_threshold of the generator (provided in the constructor, 1s by default) | ||
user will be warned with timestamp generation with warning_interval cooldown period | ||
(provided in the constructor, 1s by default) to not spam the user. | ||
|
||
``` rust | ||
# extern crate scylla; | ||
# use std::error::Error; | ||
# async fn check_only_compiles() -> Result<(), Box<dyn std::error::Error>> { | ||
use scylla::{Session, SessionBuilder, query::Query}; | ||
use scylla::transport::timestamp_generator::MonotonicTimestampGenerator; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
let session: Session = SessionBuilder::new() | ||
.known_node("127.0.0.1:9042") | ||
.timestamp_generator(Arc::new(MonotonicTimestampGenerator::new())) | ||
.build() | ||
.await?; | ||
|
||
// This query will have a timestamp generated | ||
// by the monotonic timestamp generator | ||
let my_query: Query = Query::new("INSERT INTO ks.tab (a) VALUES(?)"); | ||
let to_insert: i32 = 12345; | ||
session.query_unpaged(my_query, (to_insert,)).await?; | ||
# Ok(()) | ||
# } | ||
|
||
|