From 69b778959bf5b812f0d861abe6d1a272192d38ba Mon Sep 17 00:00:00 2001 From: smoczy123 Date: Wed, 11 Dec 2024 22:50:14 +0100 Subject: [PATCH] docs: Added timestamp generator docs --- docs/source/SUMMARY.md | 97 +++++++++++---------- docs/source/queries/queries.md | 10 ++- docs/source/queries/timestamp-generators.md | 41 +++++++++ 3 files changed, 96 insertions(+), 52 deletions(-) create mode 100644 docs/source/queries/timestamp-generators.md diff --git a/docs/source/SUMMARY.md b/docs/source/SUMMARY.md index c5f65dc92c..8fbe56bc77 100644 --- a/docs/source/SUMMARY.md +++ b/docs/source/SUMMARY.md @@ -3,75 +3,76 @@ [Scylla Rust Driver](index.md) - [Quick start](quickstart/quickstart.md) - - [Creating a project](quickstart/create-project.md) - - [Running Scylla using Docker](quickstart/scylla-docker.md) - - [Connecting and running a simple query](quickstart/example.md) + - [Creating a project](quickstart/create-project.md) + - [Running Scylla using Docker](quickstart/scylla-docker.md) + - [Connecting and running a simple query](quickstart/example.md) - [Migration guides](migration-guides/migration-guides.md) - - [Adjusting code to changes in serialization API introduced in 0.11](migration-guides/0.11-serialization.md) - - [Adjusting code to changes in deserialization API introduced in 0.15](migration-guides/0.15-deserialization.md) + - [Adjusting code to changes in serialization API introduced in 0.11](migration-guides/0.11-serialization.md) + - [Adjusting code to changes in deserialization API introduced in 0.15](migration-guides/0.15-deserialization.md) - [Connecting to the cluster](connecting/connecting.md) - - [Compression](connecting/compression.md) - - [Authentication](connecting/authentication.md) - - [TLS](connecting/tls.md) + - [Compression](connecting/compression.md) + - [Authentication](connecting/authentication.md) + - [TLS](connecting/tls.md) - [Making queries](queries/queries.md) - - [Simple query](queries/simple.md) - - [Query values](queries/values.md) - - [Query result](queries/result.md) - - [Prepared query](queries/prepared.md) - - [Batch statement](queries/batch.md) - - [Paged query](queries/paged.md) - - [Lightweight transaction query (LWT)](queries/lwt.md) - - [USE keyspace](queries/usekeyspace.md) - - [Schema agreement](queries/schema-agreement.md) - - [Query timeouts](queries/timeouts.md) + - [Simple query](queries/simple.md) + - [Query values](queries/values.md) + - [Query result](queries/result.md) + - [Prepared query](queries/prepared.md) + - [Batch statement](queries/batch.md) + - [Paged query](queries/paged.md) + - [Lightweight transaction query (LWT)](queries/lwt.md) + - [USE keyspace](queries/usekeyspace.md) + - [Schema agreement](queries/schema-agreement.md) + - [Query timeouts](queries/timeouts.md) + - [Timestamp generators](queries/timestamp-generators.md) - [Execution profiles](execution-profiles/execution-profiles.md) - - [Creating a profile and setting it](execution-profiles/create-and-use.md) - - [All options supported by a profile](execution-profiles/maximal-example.md) - - [Options priority](execution-profiles/priority.md) - - [Remapping a profile handle](execution-profiles/remap.md) + - [Creating a profile and setting it](execution-profiles/create-and-use.md) + - [All options supported by a profile](execution-profiles/maximal-example.md) + - [Options priority](execution-profiles/priority.md) + - [Remapping a profile handle](execution-profiles/remap.md) - [Data Types](data-types/data-types.md) - - [Bool, Tinyint, Smallint, Int, Bigint, Float, Double](data-types/primitive.md) - - [Ascii, Text, Varchar](data-types/text.md) - - [Counter](data-types/counter.md) - - [Blob](data-types/blob.md) - - [Inet](data-types/inet.md) - - [Uuid](data-types/uuid.md) - - [Timeuuid](data-types/timeuuid.md) - - [Date](data-types/date.md) - - [Time](data-types/time.md) - - [Timestamp](data-types/timestamp.md) - - [Duration](data-types/duration.md) - - [Decimal](data-types/decimal.md) - - [Varint](data-types/varint.md) - - [List, Set, Map](data-types/collections.md) - - [Tuple](data-types/tuple.md) - - [UDT (User defined type)](data-types/udt.md) + - [Bool, Tinyint, Smallint, Int, Bigint, Float, Double](data-types/primitive.md) + - [Ascii, Text, Varchar](data-types/text.md) + - [Counter](data-types/counter.md) + - [Blob](data-types/blob.md) + - [Inet](data-types/inet.md) + - [Uuid](data-types/uuid.md) + - [Timeuuid](data-types/timeuuid.md) + - [Date](data-types/date.md) + - [Time](data-types/time.md) + - [Timestamp](data-types/timestamp.md) + - [Duration](data-types/duration.md) + - [Decimal](data-types/decimal.md) + - [Varint](data-types/varint.md) + - [List, Set, Map](data-types/collections.md) + - [Tuple](data-types/tuple.md) + - [UDT (User defined type)](data-types/udt.md) - [Load balancing](load-balancing/load-balancing.md) - - [Default policy](load-balancing/default-policy.md) + - [Default policy](load-balancing/default-policy.md) - [Retry policy configuration](retry-policy/retry-policy.md) - - [Fallthrough retry policy](retry-policy/fallthrough.md) - - [Default retry policy](retry-policy/default.md) - - [Downgrading consistency policy](retry-policy/downgrading-consistency.md) + - [Fallthrough retry policy](retry-policy/fallthrough.md) + - [Default retry policy](retry-policy/default.md) + - [Downgrading consistency policy](retry-policy/downgrading-consistency.md) - [Speculative execution](speculative-execution/speculative.md) - - [Simple](speculative-execution/simple.md) - - [Latency Percentile](speculative-execution/percentile.md) + - [Simple](speculative-execution/simple.md) + - [Latency Percentile](speculative-execution/percentile.md) - [Driver metrics](metrics/metrics.md) - [Logging](logging/logging.md) - [Query tracing](tracing/tracing.md) - - [Tracing a simple/prepared query](tracing/basic.md) - - [Tracing a paged query](tracing/paged.md) - - [Tracing `Session::prepare`](tracing/prepare.md) - - [Query Execution History](tracing/query-history.md) + - [Tracing a simple/prepared query](tracing/basic.md) + - [Tracing a paged query](tracing/paged.md) + - [Tracing `Session::prepare`](tracing/prepare.md) + - [Query Execution History](tracing/query-history.md) - [Database schema](schema/schema.md) diff --git a/docs/source/queries/queries.md b/docs/source/queries/queries.md index 128be32aa1..4683b6f2b9 100644 --- a/docs/source/queries/queries.md +++ b/docs/source/queries/queries.md @@ -3,7 +3,7 @@ Driver supports all kinds of statements supported by ScyllaDB. The following tables aim to bridge between DB concepts and driver's API. They include recommendations on which API to use in what cases. -## Kinds of CQL statements (from the CQL protocol point of view): +## Kinds of CQL statements (from the CQL protocol point of view) | Kind of CQL statement | Single | Batch | |-----------------------|---------------------|------------------------------------------| @@ -59,7 +59,7 @@ This is **NOT** strictly related to content of the CQL query string. | Load balancing | advanced if prepared, else primitive | advanced if prepared **and ALL** statements in the batch target the same partition, else primitive | | Suitable operations | most of operations | - a list of operations that needs to be executed atomically (batch LightWeight Transaction)
- a batch of operations targetting the same partition (as an advanced optimisation) | -## CQL statements - operations (based on what the CQL string contains): +## CQL statements - operations (based on what the CQL string contains) | CQL data manipulation statement | Recommended statement kind | Recommended Session operation | |------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------| @@ -86,9 +86,10 @@ This is **NOT** strictly related to content of the CQL query string. For more detailed comparison and more best practices, see [doc page about paging](paged.md). -### Queries are fully asynchronous - you can run as many of them in parallel as you wish. +### Queries are fully asynchronous - you can run as many of them in parallel as you wish + +## `USE KEYSPACE` -## `USE KEYSPACE`: There is a special functionality to enable [USE keyspace](usekeyspace.md). ```{eval-rst} @@ -106,4 +107,5 @@ There is a special functionality to enable [USE keyspace](usekeyspace.md). schema-agreement lwt timeouts + timestamp-generators ``` diff --git a/docs/source/queries/timestamp-generators.md b/docs/source/queries/timestamp-generators.md new file mode 100644 index 0000000000..a6e466305a --- /dev/null +++ b/docs/source/queries/timestamp-generators.md @@ -0,0 +1,41 @@ +# 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, as longas the statement did not +already have a timestamp provided (e.g. by using the `TIMESTAMP` clause). + +## Monotonic Timestamp Generator + +Most basic 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> { +use scylla::{Session, SessionBuilder}; +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(()) +# } + +