Skip to content

Commit 9f228df

Browse files
psarnacvybhu
authored andcommitted
session: add a method of estimating replicas for a statement
Given that a statement has a well defined token, it's possible to quite reliably estimate which replicas own a particular piece of data. Such a function is now available for users, for analytical purposes.
1 parent 9a48f7c commit 9f228df

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

scylla/src/transport/session.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,17 @@ impl Session {
11401140
Ok(Some(tracing_info))
11411141
}
11421142

1143+
// Returns which replicas are likely to take part in handling the query.
1144+
// If a list of replicas cannot be easily narrowed down, all available replicas
1145+
// will be returned.
1146+
pub fn estimate_replicas_for_query(&self, statement: &Statement) -> Vec<Arc<Node>> {
1147+
let cluster_data = self.cluster.get_data();
1148+
match statement.token {
1149+
Some(token) => TokenAwarePolicy::replicas_for_token(&token, statement, &cluster_data),
1150+
None => cluster_data.all_nodes.clone(),
1151+
}
1152+
}
1153+
11431154
// This method allows to easily run a query using load balancing, retry policy etc.
11441155
// Requires some information about the query and two closures
11451156
// First closure is used to choose a connection

0 commit comments

Comments
 (0)