Skip to content

Commit a86d390

Browse files
authored
Merge pull request #1223 from wprzytula/partitioner-visibility
Partitioner visibility
2 parents f6d37a6 + 6d521b2 commit a86d390

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

scylla/benches/benchmark.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
22

33
use bytes::BytesMut;
4-
use scylla::routing::partitioner::{calculate_token_for_partition_key, Murmur3Partitioner};
4+
use scylla::routing::partitioner::{calculate_token_for_partition_key, PartitionerName};
55
use scylla_cql::frame::response::result::{ColumnType, NativeType};
66
use scylla_cql::frame::types;
77
use scylla_cql::serialize::row::SerializedValues;
@@ -84,7 +84,9 @@ fn calculate_token_bench(c: &mut Criterion) {
8484
.unwrap();
8585

8686
c.bench_function("calculate_token_from_partition_key simple pk", |b| {
87-
b.iter(|| calculate_token_for_partition_key(&serialized_simple_pk, &Murmur3Partitioner))
87+
b.iter(|| {
88+
calculate_token_for_partition_key(&serialized_simple_pk, &PartitionerName::Murmur3)
89+
})
8890
});
8991

9092
c.bench_function(
@@ -93,14 +95,16 @@ fn calculate_token_bench(c: &mut Criterion) {
9395
b.iter(|| {
9496
calculate_token_for_partition_key(
9597
&serialized_simple_pk_long_column,
96-
&Murmur3Partitioner,
98+
&PartitionerName::Murmur3,
9799
)
98100
})
99101
},
100102
);
101103

102104
c.bench_function("calculate_token_from_partition_key complex pk", |b| {
103-
b.iter(|| calculate_token_for_partition_key(&serialized_complex_pk, &Murmur3Partitioner))
105+
b.iter(|| {
106+
calculate_token_for_partition_key(&serialized_complex_pk, &PartitionerName::Murmur3)
107+
})
104108
});
105109

106110
c.bench_function(
@@ -109,7 +113,7 @@ fn calculate_token_bench(c: &mut Criterion) {
109113
b.iter(|| {
110114
calculate_token_for_partition_key(
111115
&serialized_values_long_column,
112-
&Murmur3Partitioner,
116+
&PartitionerName::Murmur3,
113117
)
114118
})
115119
},

scylla/src/client/pager.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ where
555555
/// needs to be cast into a typed stream. This is done by use of `rows_stream()` method.
556556
/// As the method is generic over the target type, the turbofish syntax
557557
/// can come in handy there, e.g. `query_pager.rows_stream::<(i32, String, Uuid)>()`.
558+
#[derive(Debug)]
558559
pub struct QueryPager {
559560
current_page: RawRowLendingIterator,
560561
page_receiver: mpsc::Receiver<Result<ReceivedPage, NextPageError>>,
@@ -640,7 +641,7 @@ impl QueryPager {
640641
/// Type-checks the iterator against given type.
641642
///
642643
/// This is automatically called upon transforming [QueryPager] into [TypedRowStream].
643-
/// Can be used with `next()` for manual deserialization. See `next()` for an example.
644+
// Can be used with `next()` for manual deserialization.
644645
#[inline]
645646
pub fn type_check<'frame, 'metadata, RowT: DeserializeRow<'frame, 'metadata>>(
646647
&self,
@@ -972,6 +973,17 @@ pub struct TypedRowStream<RowT: 'static> {
972973
_phantom: std::marker::PhantomData<RowT>,
973974
}
974975

976+
// Manual implementation not to depend on RowT implementing Debug.
977+
// Explanation: automatic derive of Debug would impose the RowT: Debug
978+
// constaint for the Debug impl.
979+
impl<T> std::fmt::Debug for TypedRowStream<T> {
980+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
981+
f.debug_struct("TypedRowStream")
982+
.field("raw_row_lending_stream", &self.raw_row_lending_stream)
983+
.finish()
984+
}
985+
}
986+
975987
impl<RowT> Unpin for TypedRowStream<RowT> {}
976988

977989
impl<RowT> TypedRowStream<RowT>

scylla/src/client/session_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3044,7 +3044,7 @@ async fn test_manual_primary_key_computation() {
30443044

30453045
let token_by_hand = calculate_token_for_partition_key(
30463046
serialized_pk_values_in_pk_order,
3047-
&Murmur3Partitioner,
3047+
&PartitionerName::Murmur3,
30483048
)
30493049
.unwrap();
30503050
println!(

scylla/src/routing/partitioner.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ use std::num::Wrapping;
1616
use crate::{prepared_statement::TokenCalculationError, routing::Token};
1717

1818
#[allow(clippy::upper_case_acronyms)]
19-
#[derive(Clone, PartialEq, Debug, Default)]
20-
pub(crate) enum PartitionerName {
19+
#[derive(Clone, PartialEq, Eq, Debug, Default)]
20+
#[non_exhaustive]
21+
pub enum PartitionerName {
2122
#[default]
2223
Murmur3,
2324
CDC,
@@ -75,11 +76,12 @@ impl PartitionerHasher for PartitionerHasherAny {
7576
/// The Partitioners' design is based on std::hash design: `Partitioner`
7677
/// corresponds to `HasherBuilder`, and `PartitionerHasher` to `Hasher`.
7778
/// See their documentation for more details.
78-
pub trait Partitioner {
79+
pub(crate) trait Partitioner {
7980
type Hasher: PartitionerHasher;
8081

8182
fn build_hasher(&self) -> Self::Hasher;
8283

84+
#[allow(unused)] // Currently, no public API uses this.
8385
fn hash_one(&self, data: &[u8]) -> Token {
8486
let mut hasher = self.build_hasher();
8587
hasher.write(data);
@@ -92,12 +94,12 @@ pub trait Partitioner {
9294
/// Instances of this trait are created by a `Partitioner` and are stateful.
9395
/// At any point, one can call `finish()` and a `Token` will be computed
9496
/// based on values that has been fed so far.
95-
pub trait PartitionerHasher {
97+
pub(crate) trait PartitionerHasher {
9698
fn write(&mut self, pk_part: &[u8]);
9799
fn finish(&self) -> Token;
98100
}
99101

100-
pub struct Murmur3Partitioner;
102+
pub(crate) struct Murmur3Partitioner;
101103

102104
impl Partitioner for Murmur3Partitioner {
103105
type Hasher = Murmur3PartitionerHasher;
@@ -112,7 +114,7 @@ impl Partitioner for Murmur3Partitioner {
112114
}
113115
}
114116

115-
pub struct Murmur3PartitionerHasher {
117+
pub(crate) struct Murmur3PartitionerHasher {
116118
total_len: usize,
117119
buf: [u8; Self::BUF_CAPACITY],
118120
h1: Wrapping<i64>,
@@ -278,9 +280,9 @@ enum CDCPartitionerHasherState {
278280
Computed(Token),
279281
}
280282

281-
pub struct CDCPartitioner;
283+
pub(crate) struct CDCPartitioner;
282284

283-
pub struct CDCPartitionerHasher {
285+
pub(crate) struct CDCPartitionerHasher {
284286
state: CDCPartitionerHasherState,
285287
}
286288

@@ -346,9 +348,9 @@ impl PartitionerHasher for CDCPartitionerHasher {
346348
///
347349
/// NOTE: the provided values must completely constitute partition key
348350
/// and be in the order defined in CREATE TABLE statement.
349-
pub fn calculate_token_for_partition_key<P: Partitioner>(
351+
pub fn calculate_token_for_partition_key(
350352
serialized_partition_key_values: &SerializedValues,
351-
partitioner: &P,
353+
partitioner: &PartitionerName,
352354
) -> Result<Token, TokenCalculationError> {
353355
let mut partitioner_hasher = partitioner.build_hasher();
354356

scylla/src/statement/prepared_statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl PreparedStatement {
418418
}
419419

420420
/// Get the name of the partitioner used for this statement.
421-
pub(crate) fn get_partitioner_name(&self) -> &PartitionerName {
421+
pub fn get_partitioner_name(&self) -> &PartitionerName {
422422
&self.partitioner_name
423423
}
424424

0 commit comments

Comments
 (0)