forked from scylladb/scylla-rust-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speculative-execution.rs
49 lines (38 loc) · 1.48 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
43
44
45
46
47
48
49
use scylla::{
speculative_execution::PercentileSpeculativeExecutionPolicy,
transport::execution_profile::ExecutionProfile, 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 speculative_profile = ExecutionProfile::builder()
.speculative_execution_policy(Some(Arc::new(speculative)))
.build();
let session: Session = SessionBuilder::new()
.known_node(uri)
.default_execution_profile_handle(speculative_profile.into_handle())
.build()
.await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session
.query(
"CREATE TABLE IF NOT EXISTS examples_ks.speculative_execution (a int, b int, c text, primary key (a, b))",
&[],
)
.await?;
let mut select_stmt = session
.prepare("SELECT a, b, c FROM examples_ks.speculative_execution")
.await?;
// This will allow for speculative execution
select_stmt.set_is_idempotent(true);
// This will trigger speculative execution
session.execute(&select_stmt, &[]).await?;
Ok(())
}