@@ -35,7 +35,7 @@ use crate::transport::connection::{Connection, NonErrorQueryResponse, QueryRespo
35
35
use crate :: transport:: load_balancing:: { self , RoutingInfo } ;
36
36
use crate :: transport:: metrics:: Metrics ;
37
37
use crate :: transport:: retry_policy:: { QueryInfo , RetryDecision , RetrySession } ;
38
- use crate :: transport:: { Node , NodeRef } ;
38
+ use crate :: transport:: NodeRef ;
39
39
use tracing:: { trace, trace_span, warn, Instrument } ;
40
40
use uuid:: Uuid ;
41
41
@@ -160,8 +160,6 @@ impl RowIterator {
160
160
let worker_task = async move {
161
161
let query_ref = & query;
162
162
163
- let choose_connection = |node : Arc < Node > | async move { node. random_connection ( ) . await } ;
164
-
165
163
let page_query = |connection : Arc < Connection > ,
166
164
consistency : Consistency ,
167
165
paging_state : Option < Bytes > | {
@@ -187,7 +185,6 @@ impl RowIterator {
187
185
188
186
let worker = RowIteratorWorker {
189
187
sender : sender. into ( ) ,
190
- choose_connection,
191
188
page_query,
192
189
statement_info : routing_info,
193
190
query_is_idempotent : query. config . is_idempotent ,
@@ -259,13 +256,6 @@ impl RowIterator {
259
256
is_confirmed_lwt : config. prepared . is_confirmed_lwt ( ) ,
260
257
} ;
261
258
262
- let choose_connection = |node : Arc < Node > | async move {
263
- match token {
264
- Some ( token) => node. connection_for_token ( token) . await ,
265
- None => node. random_connection ( ) . await ,
266
- }
267
- } ;
268
-
269
259
let page_query = |connection : Arc < Connection > ,
270
260
consistency : Consistency ,
271
261
paging_state : Option < Bytes > | async move {
@@ -290,7 +280,7 @@ impl RowIterator {
290
280
config
291
281
. cluster_data
292
282
. get_token_endpoints_iter ( keyspace, token)
293
- . cloned ( )
283
+ . map ( | ( node , shard ) | ( node . clone ( ) , shard ) )
294
284
. collect ( ) ,
295
285
)
296
286
} else {
@@ -311,7 +301,6 @@ impl RowIterator {
311
301
312
302
let worker = RowIteratorWorker {
313
303
sender : sender. into ( ) ,
314
- choose_connection,
315
304
page_query,
316
305
statement_info,
317
306
query_is_idempotent : config. prepared . config . is_idempotent ,
@@ -496,13 +485,9 @@ type PageSendAttemptedProof = SendAttemptedProof<Result<ReceivedPage, QueryError
496
485
497
486
// RowIteratorWorker works in the background to fetch pages
498
487
// RowIterator receives them through a channel
499
- struct RowIteratorWorker < ' a , ConnFunc , QueryFunc , SpanCreatorFunc > {
488
+ struct RowIteratorWorker < ' a , QueryFunc , SpanCreatorFunc > {
500
489
sender : ProvingSender < Result < ReceivedPage , QueryError > > ,
501
490
502
- // Closure used to choose a connection from a node
503
- // AsyncFn(Arc<Node>) -> Result<Arc<Connection>, QueryError>
504
- choose_connection : ConnFunc ,
505
-
506
491
// Closure used to perform a single page query
507
492
// AsyncFn(Arc<Connection>, Option<Bytes>) -> Result<QueryResponse, QueryError>
508
493
page_query : QueryFunc ,
@@ -524,11 +509,8 @@ struct RowIteratorWorker<'a, ConnFunc, QueryFunc, SpanCreatorFunc> {
524
509
span_creator : SpanCreatorFunc ,
525
510
}
526
511
527
- impl < ConnFunc , ConnFut , QueryFunc , QueryFut , SpanCreator >
528
- RowIteratorWorker < ' _ , ConnFunc , QueryFunc , SpanCreator >
512
+ impl < QueryFunc , QueryFut , SpanCreator > RowIteratorWorker < ' _ , QueryFunc , SpanCreator >
529
513
where
530
- ConnFunc : Fn ( Arc < Node > ) -> ConnFut ,
531
- ConnFut : Future < Output = Result < Arc < Connection > , QueryError > > ,
532
514
QueryFunc : Fn ( Arc < Connection > , Consistency , Option < Bytes > ) -> QueryFut ,
533
515
QueryFut : Future < Output = Result < QueryResponse , QueryError > > ,
534
516
SpanCreator : Fn ( ) -> RequestSpan ,
@@ -546,12 +528,13 @@ where
546
528
547
529
self . log_query_start ( ) ;
548
530
549
- ' nodes_in_plan: for node in query_plan {
531
+ ' nodes_in_plan: for ( node, shard ) in query_plan {
550
532
let span =
551
533
trace_span ! ( parent: & self . parent_span, "Executing query" , node = %node. address) ;
552
534
// For each node in the plan choose a connection to use
553
535
// This connection will be reused for same node retries to preserve paging cache on the shard
554
- let connection: Arc < Connection > = match ( self . choose_connection ) ( node. clone ( ) )
536
+ let connection: Arc < Connection > = match node
537
+ . connection_for_shard ( shard)
555
538
. instrument ( span. clone ( ) )
556
539
. await
557
540
{
0 commit comments