Was this page helpful?
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.
Session::fetch_schema_version
returns an Uuid
of local node’s schema version.
println!("Local schema version is: {}", session.fetch_schema_version().await?);
Session::await_schema_agreement
returns a Future
that can be await
ed on as long as schema is not in an agreement.
session.await_schema_agreement().await?;
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
.
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");
}
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
.
SessionBuilder::new()
.known_node("127.0.0.1:9042")
.schema_agreement_interval(Duration::from_secs(1))
.build()
.await?;
If you want to check if schema is in agreement now without retrying after failure you can use Session::check_schema_agreement
function.
if session.check_schema_agreement().await? {
println!("SCHEMA AGREED");
} else {
println!("SCHEMA IS NOT IN AGREEMENT");
}
Was this page helpful?