1
1
/// Cluster manages up to date information and connections to database nodes
2
2
use crate :: frame:: response:: event:: { Event , StatusChangeEvent } ;
3
3
use crate :: prepared_statement:: TokenCalculationError ;
4
- use crate :: routing:: Token ;
4
+ use crate :: routing:: { Shard , Token } ;
5
5
use crate :: transport:: host_filter:: HostFilter ;
6
6
use crate :: transport:: {
7
7
connection:: { Connection , VerifiedKeyspaceName } ,
@@ -27,6 +27,7 @@ use tracing::{debug, warn};
27
27
use uuid:: Uuid ;
28
28
29
29
use super :: node:: { KnownNode , NodeAddr } ;
30
+ use super :: NodeRef ;
30
31
31
32
use super :: locator:: ReplicaLocator ;
32
33
use super :: partitioner:: calculate_token_for_partition_key;
@@ -408,17 +409,17 @@ impl ClusterData {
408
409
}
409
410
410
411
/// 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 ) > {
412
413
self . get_token_endpoints_iter ( keyspace, token)
413
- . cloned ( )
414
+ . map ( | ( node , shard ) | ( node . clone ( ) , shard ) )
414
415
. collect ( )
415
416
}
416
417
417
418
pub ( crate ) fn get_token_endpoints_iter (
418
419
& self ,
419
420
keyspace : & str ,
420
421
token : Token ,
421
- ) -> impl Iterator < Item = & Arc < Node > > {
422
+ ) -> impl Iterator < Item = ( NodeRef < ' _ > , Shard ) > {
422
423
let keyspace = self . keyspaces . get ( keyspace) ;
423
424
let strategy = keyspace
424
425
. map ( |k| & k. strategy )
@@ -427,7 +428,7 @@ impl ClusterData {
427
428
. replica_locator ( )
428
429
. replicas_for_token ( token, strategy, None ) ;
429
430
430
- replica_set. into_iter ( ) . map ( | ( node , _shard ) | node )
431
+ replica_set. into_iter ( )
431
432
}
432
433
433
434
/// Access to replicas owning a given partition key (similar to `nodetool getendpoints`)
@@ -436,7 +437,7 @@ impl ClusterData {
436
437
keyspace : & str ,
437
438
table : & str ,
438
439
partition_key : & SerializedValues ,
439
- ) -> Result < Vec < Arc < Node > > , BadQuery > {
440
+ ) -> Result < Vec < ( Arc < Node > , Shard ) > , BadQuery > {
440
441
Ok ( self . get_token_endpoints (
441
442
keyspace,
442
443
self . compute_token ( keyspace, table, partition_key) ?,
0 commit comments