Skip to content

Commit 32dd96f

Browse files
psarnacvybhu
authored andcommitted
examples: add an example of printing possible replicas
Compare-tokens example is extended by showing the list of likely replicas for given token.
1 parent 9f228df commit 32dd96f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

examples/compare-tokens.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ async fn main() -> Result<()> {
3131
let serialized_pk = (pk,).serialized()?.into_owned();
3232
let t = Murmur3Partitioner::hash(prepared.compute_partition_key(&serialized_pk)?).value;
3333

34+
let statement_info = scylla::transport::load_balancing::Statement {
35+
token: Some(scylla::routing::Token { value: t }),
36+
keyspace: Some("ks"),
37+
};
38+
println!(
39+
"Estimated replicas for query: {:?}",
40+
session
41+
.estimate_replicas_for_query(&statement_info)
42+
.iter()
43+
.map(|n| n.address)
44+
.collect::<Vec<std::net::SocketAddr>>()
45+
);
46+
3447
let qt = session
3548
.query(format!("SELECT token(pk) FROM ks.t where pk = {}", pk), &[])
3649
.await?

0 commit comments

Comments
 (0)