Skip to content

Commit efab01a

Browse files
Lorak-mmkwprzytula
andcommitted
Cluster: get_endpoints and related methods return shards
Co-authored-by: Wojciech Przytuła <[email protected]>
1 parent 9f5cbae commit efab01a

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

examples/compare-tokens.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async fn main() -> Result<()> {
4141
.get_cluster_data()
4242
.get_token_endpoints("examples_ks", Token { value: t })
4343
.iter()
44-
.map(|n| n.address)
44+
.map(|(node, _shard)| node.address)
4545
.collect::<Vec<NodeAddr>>()
4646
);
4747

scylla/src/transport/cluster.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Cluster manages up to date information and connections to database nodes
22
use crate::frame::response::event::{Event, StatusChangeEvent};
33
use crate::prepared_statement::TokenCalculationError;
4-
use crate::routing::Token;
4+
use crate::routing::{Shard, Token};
55
use crate::transport::host_filter::HostFilter;
66
use crate::transport::{
77
connection::{Connection, VerifiedKeyspaceName},
@@ -27,6 +27,7 @@ use tracing::{debug, warn};
2727
use uuid::Uuid;
2828

2929
use super::node::{KnownNode, NodeAddr};
30+
use super::NodeRef;
3031

3132
use super::locator::ReplicaLocator;
3233
use super::partitioner::calculate_token_for_partition_key;
@@ -408,17 +409,17 @@ impl ClusterData {
408409
}
409410

410411
/// Access to replicas owning a given token
411-
pub fn get_token_endpoints(&self, keyspace: &str, token: Token) -> Vec<Arc<Node>> {
412+
pub fn get_token_endpoints(&self, keyspace: &str, token: Token) -> Vec<(Arc<Node>, Shard)> {
412413
self.get_token_endpoints_iter(keyspace, token)
413-
.cloned()
414+
.map(|(node, shard)| (node.clone(), shard))
414415
.collect()
415416
}
416417

417418
pub(crate) fn get_token_endpoints_iter(
418419
&self,
419420
keyspace: &str,
420421
token: Token,
421-
) -> impl Iterator<Item = &Arc<Node>> {
422+
) -> impl Iterator<Item = (NodeRef<'_>, Shard)> {
422423
let keyspace = self.keyspaces.get(keyspace);
423424
let strategy = keyspace
424425
.map(|k| &k.strategy)
@@ -427,7 +428,7 @@ impl ClusterData {
427428
.replica_locator()
428429
.replicas_for_token(token, strategy, None);
429430

430-
replica_set.into_iter().map(|(node, _shard)| node)
431+
replica_set.into_iter()
431432
}
432433

433434
/// Access to replicas owning a given partition key (similar to `nodetool getendpoints`)
@@ -436,7 +437,7 @@ impl ClusterData {
436437
keyspace: &str,
437438
table: &str,
438439
partition_key: &SerializedValues,
439-
) -> Result<Vec<Arc<Node>>, BadQuery> {
440+
) -> Result<Vec<(Arc<Node>, Shard)>, BadQuery> {
440441
Ok(self.get_token_endpoints(
441442
keyspace,
442443
self.compute_token(keyspace, table, partition_key)?,

scylla/src/transport/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl RowIterator {
290290
config
291291
.cluster_data
292292
.get_token_endpoints_iter(keyspace, token)
293-
.cloned()
293+
.map(|(node, shard)| (node.clone(), shard))
294294
.collect(),
295295
)
296296
} else {

scylla/src/transport/session.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2027,19 +2027,19 @@ impl RequestSpan {
20272027
self.span.record("result_rows", rows.rows.len());
20282028
}
20292029

2030-
pub(crate) fn record_replicas<'a>(&'a self, replicas: &'a [impl Borrow<Arc<Node>>]) {
2031-
struct ReplicaIps<'a, N>(&'a [N]);
2030+
pub(crate) fn record_replicas<'a>(&'a self, replicas: &'a [(impl Borrow<Arc<Node>>, Shard)]) {
2031+
struct ReplicaIps<'a, N>(&'a [(N, Shard)]);
20322032
impl<'a, N> Display for ReplicaIps<'a, N>
20332033
where
20342034
N: Borrow<Arc<Node>>,
20352035
{
20362036
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2037-
let mut nodes = self.0.iter();
2038-
if let Some(node) = nodes.next() {
2039-
write!(f, "{}", node.borrow().address.ip())?;
2037+
let mut nodes_with_shards = self.0.iter();
2038+
if let Some((node, shard)) = nodes_with_shards.next() {
2039+
write!(f, "{}-shard{}", node.borrow().address.ip(), shard)?;
20402040

2041-
for node in nodes {
2042-
write!(f, ",{}", node.borrow().address.ip())?;
2041+
for (node, shard) in nodes_with_shards {
2042+
write!(f, ",{}-shard{}", node.borrow().address.ip(), shard)?;
20432043
}
20442044
}
20452045
Ok(())

0 commit comments

Comments
 (0)