ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Server
  • Cloud
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Download
ScyllaDB Docs Scylla Rust Driver Query tracing Query Execution History

Caution

You're viewing documentation for a deprecated version of Scylla Rust Driver. Switch to the latest stable version.

Query Execution History¶

The driver allows to collect history of query execution.
This history includes all requests sent, decisions to retry and speculative execution fibers started.

Example code¶

use scylla::statement::unprepared::Statement;
use scylla::observability::history::{HistoryCollector, StructuredHistory};
use std::sync::Arc;

// Create a query for which we would like to trace the history of its execution
let mut query: Statement = Statement::new("SELECT * FROM ks.t");

// Create a history collector and pass it to the query
let history_listener = Arc::new(HistoryCollector::new());
query.set_history_listener(history_listener.clone());

// Run the query, doesn't matter if it failed, the history will still be saved
let _ignore_error = session.query_unpaged(query.clone(), ()).await;

// Access the collected history and print it
let structured_history: StructuredHistory = history_listener.clone_structured_history();
println!("Query history: {}", structured_history);

To see more check out the example code

Output¶

Sample output for a query that didn’t encounter any difficulties:

=== Query #0 ===
| start_time: 2022-08-25 11:21:50.445075147 UTC
| Non-speculative attempts:
| - Attempt #0 sent to 127.0.0.1:9042
|   request send time: 2022-08-25 11:21:50.445151628 UTC
|   Success at 2022-08-25 11:21:50.447444362 UTC
|
| Query successful at 2022-08-25 11:21:50.447447970 UTC
=================

Here’s output for a query that had some trouble - nodes didn’t respond and speculative execution decided to query others in parallel. Finally the third node provided a response.

=== Query #0 ===
| start_time: 2022-08-26 15:08:28.525367409 UTC
| Non-speculative attempts:
| - Attempt #0 sent to 127.0.0.219:9042
|   request send time: 2022-08-26 15:08:28.525409294 UTC
|   No result yet
|
|
| > Speculative fiber #0
| fiber start time: 2022-08-26 15:08:28.537074167 UTC
| - Attempt #0 sent to 127.0.0.217:9042
|   request send time: 2022-08-26 15:08:28.537126083 UTC
|   No result yet
|
|
| > Speculative fiber #1
| fiber start time: 2022-08-26 15:08:28.548050242 UTC
| - Attempt #0 sent to 127.0.0.218:9042
|   request send time: 2022-08-26 15:08:28.548089083 UTC
|   Success at 2022-08-26 15:08:28.590052778 UTC
|
| Query successful at 2022-08-26 15:08:28.590078119 UTC
=================

How the driver executes queries¶

To read the output it’s useful to understand more about how the driver executes queries.

No speculative execution¶

Without speculative execution the driver performs many attempts sequentially until one of them succeeds. A single attempt consists of sending a request to some node and waiting for the answer. In case of an error the driver consults the retry policy to decide what to do next. The decision might be to fail the query, retry on the same node, another node, change query parameters, etc. Once the decision is made either the query fails or another attempt is started. This continues until the query ends.

Speculative execution¶

When speculative execution is enabled at first the driver doesn’t care about it - it does the attempts sequentially and tries to get an answer. However once a specified amount of time has passed it will decide to try new attempts in parallel hoping that another node will be able to answer quicker. This is done by spawning a speculative fiber. Each spawned fiber performs sequential attempts just like in non-speculative execution. Many fibers can be spawned if the answer wasn’t acquired in time.

StructuredHistory¶

StructuredHistory is a history representation that represents the history by listing attempts for each speculative fiber.

HistoryListener trait, custom history collecting¶

History can be collected by any struct implementing the HistoryListener trait.

The implementation of HistoryListener provided by this crate is the HistoryCollector. HistoryCollector simply collects all events along with their timestamps.

Information collected by HistoryCollector is just a stream of events, in order to analyze it it’s possible to convert it to a structured representation. StructuredHistory can be created by calling HistoryCollector::clone_structured_history().

Was this page helpful?

PREVIOUS
Tracing Session::prepare
NEXT
Schema
  • Create an issue
  • Edit this page

On this page

  • Query Execution History
    • Example code
    • Output
    • How the driver executes queries
      • No speculative execution
      • Speculative execution
      • StructuredHistory
    • HistoryListener trait, custom history collecting
Scylla Rust Driver
  • v1.0.0
    • main
    • v1.1.0
    • v1.0.0
  • Scylla Rust Driver
  • Quick Start
    • Creating a project
    • Connecting and running a simple query
    • Running Scylla using Docker
  • Connecting to the cluster
    • Compression
    • Authentication
    • TLS
  • Executing CQL statements - best practices
    • Unprepared statement
    • Statement values
    • Query result
    • Prepared statement
    • Batch statement
    • Paged query
    • USE keyspace
    • Schema agreement
    • Lightweight transaction (LWT) statement
    • Request timeouts
    • Timestamp generators
  • Execution profiles
    • Creating a profile and setting it
    • All options supported by a profile
    • Priorities of execution settings
    • Remapping execution profile handles
  • Data Types
    • Bool, Tinyint, Smallint, Int, Bigint, Float, Double
    • Ascii, Text, Varchar
    • Counter
    • Blob
    • Inet
    • Uuid
    • Timeuuid
    • Date
    • Time
    • Timestamp
    • Duration
    • Decimal
    • Varint
    • List, Set, Map
    • Tuple
    • User defined types
  • Load balancing
    • DefaultPolicy
  • Retry policy configuration
    • Fallthrough retry policy
    • Default retry policy
    • Downgrading consistency retry policy
  • Speculative execution
    • Simple speculative execution
    • Percentile speculative execution
  • Driver metrics
  • Migration guides
    • Adjusting code to changes in serialization API introduced in 0.11
    • Adjusting code to changes in deserialization API introduced in 0.15
  • Logging
  • Query tracing
    • Tracing a simple/prepared/batch query
    • Tracing a paged query
    • Tracing Session::prepare
    • Query Execution History
  • Schema
Docs Tutorials University Contact Us About Us
© 2025, ScyllaDB. All rights reserved. | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 08 May 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.6