forked from scylladb/scylla-rust-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speculative-execution.rs
42 lines (32 loc) · 1.17 KB
/
speculative-execution.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use scylla::{
speculative_execution::PercentileSpeculativeExecutionPolicy, Session, SessionBuilder,
};
use anyhow::Result;
use std::{env, sync::Arc};
#[tokio::main]
async fn main() -> Result<()> {
let uri = env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
println!("Connecting to {} ...", uri);
let speculative = PercentileSpeculativeExecutionPolicy {
max_retry_count: 2,
percentile: 99.0,
};
let session: Session = SessionBuilder::new()
.known_node(uri)
.speculative_execution(Arc::new(speculative))
.build()
.await?;
session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}", &[]).await?;
session
.query(
"CREATE TABLE IF NOT EXISTS ks.t (a int, b int, c text, primary key (a, b))",
&[],
)
.await?;
let mut select_stmt = session.prepare("SELECT a, b, c FROM ks.t").await?;
// This will allow for speculative execution
select_stmt.set_is_idempotent(true);
// This will trigger speculative execution
session.execute(&select_stmt, &[]).await?;
Ok(())
}