-
Notifications
You must be signed in to change notification settings - Fork 136
Implement timestamp generators #1128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wprzytula
merged 6 commits into
scylladb:main
from
smoczy123:implement-timestamp-generator
Jan 27, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0881ae2
policies/timestamp_generator: Added MonotonicTimestampGenerator
smoczy123 ef073e3
client/session: Added timestamp generator to SessionConfig
smoczy123 7fa1821
network/connection: Added timestamp generator to ConnectionConfig
smoczy123 96a03ab
network/connection: Added logic for setting a timestamp
smoczy123 89b5aa2
client/session_test: Added tests for MonotonicTimestampGenerator
smoczy123 34315f2
docs: Added timestamp generator docs
smoczy123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,54 @@ | ||
# 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 panics 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 (can be changed with `with_warning_times`, 1s by default) | ||
user will be warned with timestamp generation with `warning_interval` cooldown period | ||
(can be changed with `with_warning_times`, 1s by default) to not spam the user. If user does not want to | ||
be warned about the clock skew, the warnings can be turned off with `without_warnings` function. | ||
|
||
``` rust | ||
# extern crate scylla; | ||
# use std::error::Error; | ||
# async fn check_only_compiles() -> Result<(), Box<dyn std::error::Error>> { | ||
use scylla::client::session::Session; | ||
use scylla::client::session_builder::SessionBuilder; | ||
use scylla::policies::timestamp_generator::MonotonicTimestampGenerator; | ||
use scylla::query::Query; | ||
use std::sync::Arc; | ||
|
||
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(()) | ||
# } | ||
``` | ||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.