Skip to content

Commit

Permalink
Merge pull request #758 from wprzytula/stateful-partitioners
Browse files Browse the repository at this point in the history
Stateful partitioners
  • Loading branch information
piodul authored Aug 22, 2023
2 parents ffd374b + 0e21804 commit 83f4050
Show file tree
Hide file tree
Showing 10 changed files with 660 additions and 426 deletions.
3 changes: 1 addition & 2 deletions examples/compare-tokens.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use scylla::frame::value::ValueList;
use scylla::routing::Token;
use scylla::transport::partitioner::{Murmur3Partitioner, Partitioner};
use scylla::transport::NodeAddr;
use scylla::{Session, SessionBuilder};
use std::env;
Expand Down Expand Up @@ -31,7 +30,7 @@ async fn main() -> Result<()> {
.await?;

let serialized_pk = (pk,).serialized()?.into_owned();
let t = Murmur3Partitioner::hash(&prepared.compute_partition_key(&serialized_pk)?).value;
let t = prepared.calculate_token(&serialized_pk)?.unwrap().value;

println!(
"Token endpoints for query: {:?}",
Expand Down
4 changes: 2 additions & 2 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct SchemaChange {
pub event: SchemaChangeEvent,
}

#[derive(Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TableSpec {
pub ks_name: String,
pub table_name: String,
Expand Down Expand Up @@ -329,7 +329,7 @@ impl CqlValue {
// TODO
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColumnSpec {
pub table_spec: TableSpec,
pub name: String,
Expand Down
60 changes: 58 additions & 2 deletions scylla/benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use criterion::{criterion_group, criterion_main, Criterion};

use bytes::BytesMut;
use scylla::frame::types;
use scylla::{
frame::types,
frame::value::ValueList,
transport::partitioner::{calculate_token_for_partition_key, Murmur3Partitioner},
};

fn types_benchmark(c: &mut Criterion) {
let mut buf = BytesMut::with_capacity(64);
Expand Down Expand Up @@ -35,5 +39,57 @@ fn types_benchmark(c: &mut Criterion) {
});
}

criterion_group!(benches, types_benchmark);
fn calculate_token_bench(c: &mut Criterion) {
let simple_pk = ("I'm prepared!!!",);
let serialized_simple_pk = simple_pk.serialized().unwrap().into_owned();
let simple_pk_long_column = (
17_i32,
16_i32,
String::from_iter(std::iter::repeat('.').take(2000)),
);
let serialized_simple_pk_long_column = simple_pk_long_column.serialized().unwrap().into_owned();

let complex_pk = (17_i32, 16_i32, "I'm prepared!!!");
let serialized_complex_pk = complex_pk.serialized().unwrap().into_owned();
let complex_pk_long_column = (
17_i32,
16_i32,
String::from_iter(std::iter::repeat('.').take(2000)),
);
let serialized_values_long_column = complex_pk_long_column.serialized().unwrap().into_owned();

c.bench_function("calculate_token_from_partition_key simple pk", |b| {
b.iter(|| calculate_token_for_partition_key(&serialized_simple_pk, &Murmur3Partitioner))
});

c.bench_function(
"calculate_token_from_partition_key simple pk long column",
|b| {
b.iter(|| {
calculate_token_for_partition_key(
&serialized_simple_pk_long_column,
&Murmur3Partitioner,
)
})
},
);

c.bench_function("calculate_token_from_partition_key complex pk", |b| {
b.iter(|| calculate_token_for_partition_key(&serialized_complex_pk, &Murmur3Partitioner))
});

c.bench_function(
"calculate_token_from_partition_key complex pk long column",
|b| {
b.iter(|| {
calculate_token_for_partition_key(
&serialized_values_long_column,
&Murmur3Partitioner,
)
})
},
);
}

criterion_group!(benches, types_benchmark, calculate_token_bench);
criterion_main!(benches);
Loading

0 comments on commit 83f4050

Please sign in to comment.