Was this page helpful?
Caution
You're viewing documentation for an unstable version of Scylla Rust Driver. Switch to the latest stable version.
Query timeoutsΒΆ
Query execution time can be limited by setting a request timeout. If a query does not complete
in the given time, then ExecutionError::RequestTimeout
is returned by the driver immediately,
so that application logic can continue operating, but the query may still be in progress on the server.
As a side note, if one wishes custom server-side timeouts (i.e. actual interruption of query processing),
one can use aUSING TIMEOUT <duration>
directive supported in ScyllaDB
(but not in Cassandra).
Timeout can be set globally (per session) or locally (for given statement).
The default per-session timeout is currently 30s.
It is possible to turn off timeouts completely by providing None
as timeout when building Session
.
However, setting per-statement timeout to None
results in falling back to per-session timeout.
use scylla::client::execution_profile::ExecutionProfile;
use scylla::client::session::Session;
use scylla::client::session_builder::SessionBuilder;
use scylla::query::Query;
use std::time::Duration;
let uri = std::env::var("SCYLLA_URI")
.unwrap_or_else(|_| "127.0.0.1:9042".to_string());
let no_timeout_profile_handle = ExecutionProfile::builder()
.request_timeout(None) // no timeout
.build()
.into_handle();
let session: Session = SessionBuilder::new()
.known_node(uri)
.default_execution_profile_handle(no_timeout_profile_handle) // no per-session timeout
.build()
.await?;
// This query, having no timeout, could block indefinitely if a queried node hangs.
session
.query_unpaged("TRUNCATE keyspace.table", ())
.await?;
let three_sec_timeout_profile_handle = ExecutionProfile::builder()
.request_timeout(Some(Duration::from_secs(3))) // no timeout
.build()
.into_handle();
// The below query will last for no more than 3 seconds, yielding a RequestTimeout error
// if no response arrives until then.
let mut query: Query = "TRUNCATE keyspace.table".into();
query.set_execution_profile_handle(Some(three_sec_timeout_profile_handle));
session
.query_unpaged(query, ())
.await?;