@@ -4,8 +4,10 @@ use std::sync::Arc;
44use crate :: history:: HistoryListener ;
55use crate :: load_balancing;
66use crate :: retry_policy:: RetryPolicy ;
7+ use crate :: routing:: Shard ;
78use crate :: statement:: { prepared_statement:: PreparedStatement , query:: Query } ;
8- use crate :: transport:: { execution_profile:: ExecutionProfileHandle , Node } ;
9+ use crate :: transport:: execution_profile:: ExecutionProfileHandle ;
10+ use crate :: transport:: NodeRef ;
911use crate :: Session ;
1012
1113use super :: StatementConfig ;
@@ -145,31 +147,31 @@ impl Batch {
145147 self . config . execution_profile_handle . as_ref ( )
146148 }
147149
148- /// Associates the batch with a new execution profile that will have a load balancing policy
149- /// that will enforce the use of the provided [`Node`] to the extent possible.
150+ /// Associates the batch with a new execution profile that will have a load
151+ /// balancing policy that will enforce the use of the provided [`Node`]
152+ /// to the extent possible.
150153 ///
151- /// This should typically be used in conjunction with [`Session::shard_for_statement`], where
152- /// you would constitute a batch by assigning to the same batch all the statements that would be executed in
153- /// the same shard.
154+ /// This should typically be used in conjunction with
155+ /// [`Session::shard_for_statement`], where you would constitute a batch
156+ /// by assigning to the same batch all the statements that would be executed
157+ /// in the same shard.
154158 ///
155- /// Since it is not guaranteed that subsequent calls to the load balancer would re-assign the statement
156- /// to the same node, you should use this method to enforce the use of the original node that was envisioned by
159+ /// Since it is not guaranteed that subsequent calls to the load balancer
160+ /// would re-assign the statement to the same node, you should use this
161+ /// method to enforce the use of the original node that was envisioned by
157162 /// `shard_for_statement` for the batch:
158163 ///
159164 /// ```rust
160165 /// # use scylla::Session;
161166 /// # use std::error::Error;
162167 /// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
163- /// use scylla::{
164- /// batch::Batch,
165- /// frame::value::{SerializedValues, ValueList},
166- /// };
168+ /// use scylla::{batch::Batch, serialize::row::SerializedValues};
167169 ///
168170 /// let prepared_statement = session
169171 /// .prepare("INSERT INTO ks.tab(a, b) VALUES(?, ?)")
170172 /// .await?;
171173 ///
172- /// let serialized_values: SerializedValues = ( 1, 2).serialized()?.into_owned() ;
174+ /// let serialized_values: SerializedValues = prepared_statement.serialize_values(&( 1, 2))? ;
173175 /// let shard = session.shard_for_statement(&prepared_statement, &serialized_values)?;
174176 ///
175177 /// // Send that to a task that will handle statements targeted to the same shard
@@ -178,8 +180,8 @@ impl Batch {
178180 /// // Constitute a batch with all the statements that would be executed in the same shard
179181 ///
180182 /// let mut batch: Batch = Default::default();
181- /// if let Some((node, _shard_idx )) = shard {
182- /// batch.enforce_target_node(&node, &session);
183+ /// if let Some((node, shard_idx )) = shard {
184+ /// batch.enforce_target_node(&node, shard_idx, &session);
183185 /// }
184186 /// let mut batch_values = Vec::new();
185187 ///
@@ -195,13 +197,14 @@ impl Batch {
195197 /// ```
196198 ///
197199 ///
198- /// If the target node is not available anymore at the time of executing the statement, it will fallback to the
199- /// original load balancing policy:
200+ /// If the target node is not available anymore at the time of executing the
201+ /// statement, it will fallback to the original load balancing policy:
200202 /// - Either that currently set on the [`Batch`], if any
201203 /// - Or that of the [`Session`] if there isn't one on the `Batch`
202204 pub fn enforce_target_node (
203205 & mut self ,
204- node : & Arc < Node > ,
206+ node : NodeRef < ' _ > ,
207+ shard : Shard ,
205208 base_execution_profile_from_session : & Session ,
206209 ) {
207210 let execution_profile_handle = self . get_execution_profile_handle ( ) . unwrap_or_else ( || {
@@ -210,8 +213,9 @@ impl Batch {
210213 self . set_execution_profile_handle ( Some (
211214 execution_profile_handle
212215 . pointee_to_builder ( )
213- . load_balancing_policy ( Arc :: new ( load_balancing:: EnforceTargetNodePolicy :: new (
216+ . load_balancing_policy ( Arc :: new ( load_balancing:: EnforceTargetShardPolicy :: new (
214217 node,
218+ shard,
215219 execution_profile_handle. load_balancing_policy ( ) ,
216220 ) ) )
217221 . build ( )
0 commit comments