|
1 | 1 | use crate::errors::ConnectionPoolError;
|
2 | 2 | use crate::network::{Connection, PoolConfig, VerifiedKeyspaceName};
|
3 | 3 | use crate::policies::host_filter::HostFilter;
|
4 |
| -use crate::prepared_statement::TokenCalculationError; |
| 4 | +use crate::prepared_statement::PartitionKeyError; |
5 | 5 | use crate::routing::locator::tablets::{RawTablet, Tablet, TabletsInfo};
|
6 | 6 | use crate::routing::locator::ReplicaLocator;
|
7 | 7 | use crate::routing::partitioner::{calculate_token_for_partition_key, PartitionerName};
|
8 | 8 | use crate::routing::{Shard, Token};
|
9 | 9 |
|
10 | 10 | use itertools::Itertools;
|
11 | 11 | use scylla_cql::frame::response::result::TableSpec;
|
12 |
| -use scylla_cql::serialize::row::SerializedValues; |
| 12 | +use scylla_cql::serialize::row::{RowSerializationContext, SerializeRow, SerializedValues}; |
13 | 13 | use std::collections::{HashMap, HashSet};
|
14 | 14 | use std::sync::Arc;
|
15 | 15 | use tracing::{debug, warn};
|
@@ -203,17 +203,22 @@ impl ClusterState {
|
203 | 203 | &self,
|
204 | 204 | keyspace: &str,
|
205 | 205 | table: &str,
|
206 |
| - partition_key: &SerializedValues, |
207 |
| - ) -> Result<Token, TokenCalculationError> { |
208 |
| - let partitioner = self |
| 206 | + partition_key: &dyn SerializeRow, |
| 207 | + ) -> Result<Token, PartitionKeyError> { |
| 208 | + let table = self |
209 | 209 | .keyspaces
|
210 | 210 | .get(keyspace)
|
211 |
| - .and_then(|k| k.tables.get(table)) |
| 211 | + .and_then(|k| k.tables.get(table)); |
| 212 | + let values = SerializedValues::from_serializable( |
| 213 | + &RowSerializationContext::from_specs(table.unwrap().pk_column_specs.as_slice()), |
| 214 | + partition_key, |
| 215 | + )?; |
| 216 | + let partitioner = table |
212 | 217 | .and_then(|t| t.partitioner.as_deref())
|
213 | 218 | .and_then(PartitionerName::from_str)
|
214 | 219 | .unwrap_or_default();
|
215 | 220 |
|
216 |
| - calculate_token_for_partition_key(partition_key, &partitioner) |
| 221 | + calculate_token_for_partition_key(&values, &partitioner).map_err(PartitionKeyError::from) |
217 | 222 | }
|
218 | 223 |
|
219 | 224 | /// Access to replicas owning a given token
|
@@ -250,8 +255,8 @@ impl ClusterState {
|
250 | 255 | &self,
|
251 | 256 | keyspace: &str,
|
252 | 257 | table: &str,
|
253 |
| - partition_key: &SerializedValues, |
254 |
| - ) -> Result<Vec<(Arc<Node>, Shard)>, TokenCalculationError> { |
| 258 | + partition_key: &dyn SerializeRow, |
| 259 | + ) -> Result<Vec<(Arc<Node>, Shard)>, PartitionKeyError> { |
255 | 260 | let token = self.compute_token(keyspace, table, partition_key)?;
|
256 | 261 | Ok(self.get_token_endpoints(keyspace, table, token))
|
257 | 262 | }
|
|
0 commit comments