Scylla Documentation Logo Documentation
  • Server
    • Scylla Open Source
    • Scylla Enterprise
    • Scylla Alternator
  • Cloud
    • Scylla Cloud
    • Scylla Cloud Docs
  • Tools
    • Scylla Manager
    • Scylla Monitoring Stack
    • Scylla Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
Download
Menu
Scylla Rust Driver Making queries Schema agreement

Schema agreement¶

Sometimes after performing queries some nodes have not been updated so we need a mechanism that checks if every node have agreed schema version. There are four methods in Session that assist us. Every method raise QueryError if something goes wrong, but they should never raise any errors, unless there is a DB or connection malfunction.

Checking schema version¶

Session::fetch_schema_version returns an Uuid of local node’s schema version.

# extern crate scylla;
# use scylla::Session;
# use std::error::Error;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
println!("Local schema version is: {}", session.fetch_schema_version().await?);
# Ok(())
# }

Awaiting schema agreement¶

Session::await_schema_agreement returns a Future that can be awaited on as long as schema is not in an agreement.

# extern crate scylla;
# use scylla::Session;
# use std::error::Error;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
session.await_schema_agreement().await?;
# Ok(())
# }

Awaiting with timeout¶

We can also set timeout in milliseconds with Session::await_timed_schema_agreement. It takes one argument, an std::time::Duration value that tells how long our driver should await for schema agreement. If the timeout is met the return value is false otherwise it is true.

# extern crate scylla;
# use scylla::Session;
# use std::error::Error;
# use std::time::Duration;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
if session.await_timed_schema_agreement(Duration::from_secs(5)).await? { // wait for 5 seconds
    println!("SCHEMA AGREED");
} else {
    println!("SCHEMA IS NOT IN AGREEMENT - TIMED OUT");
}
# Ok(())
# }

Checking for schema interval¶

If schema is not agreed driver sleeps for a duration before checking it again. Default value is 200 milliseconds but it can be changed with SessionBuilder::schema_agreement_interval.

# extern crate scylla;
# use scylla::SessionBuilder;
# use std::error::Error;
# use std::time::Duration;
# async fn check_only_compiles() -> Result<(), Box<dyn Error>> {
SessionBuilder::new()
    .known_node("127.0.0.1:9042")
    .schema_agreement_interval(Duration::from_secs(1))
    .build()
    .await?;
# Ok(())
# }

Checking if schema is in agreement now¶

If you want to check if schema is in agreement now without retrying after failure you can use Session::check_schema_agreement function.

# extern crate scylla;
# use scylla::Session;
# use std::error::Error;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
if session.check_schema_agreement().await? { 
    println!("SCHEMA AGREED");
} else {
    println!("SCHEMA IS NOT IN AGREEMENT");
}
# Ok(())
# }
PREVIOUS
USE keyspace
NEXT
Lightweight transaction (LWT) query
  • 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
  • Making queries
    • Simple query
    • Query values
    • Query result
    • Prepared query
    • Batch statement
    • Paged query
    • USE keyspace
    • Schema agreement
    • Lightweight transaction (LWT) query
  • Data Types
    • Bool, Tinyint, Smallint, Int, Bigint, Float, Double
    • Ascii, Text, Varchar
    • Counter
    • Blob
    • Inet
    • Uuid, Timeuuid
    • Date
    • Time
    • Timestamp
    • Decimal
    • Varint
    • List, Set, Map
    • Tuple
    • User defined types
  • Load balancing
    • Round robin
    • DC Aware Round robin
    • Token aware Round robin
    • Token aware DC Aware Round robin
  • Retry policy configuration
    • Fallthrough retry policy
    • Default retry policy
  • Speculative execution
    • Simple speculative execution
    • Percentile speculative execution
  • Driver metrics
  • Logging
  • Query tracing
    • Tracing a simple/prepared query
    • Tracing a batch query
    • Tracing a paged query
    • Tracing Session::prepare
  • Create an issue
  • Edit this page

On this page

  • Schema agreement
    • Checking schema version
    • Awaiting schema agreement
    • Awaiting with timeout
    • Checking for schema interval
    • Checking if schema is in agreement now
Logo
Docs Contact Us About Us
Mail List Icon Slack Icon
© 2022, ScyllaDB. All rights reserved.
Last updated on 17 June 2022.
Powered by Sphinx 4.3.2 & ScyllaDB Theme 1.2.2