Skip to content

Commit

Permalink
Split read_multi_values_bytes queries for ScyllaDb in chunks of 100 (
Browse files Browse the repository at this point in the history
…#2214)

* Reintroduce the use of `join` methods for this purpose.
  • Loading branch information
MathieuDutSik committed Jul 4, 2024
1 parent fe52243 commit a320175
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions linera-views/src/scylla_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
//! [trait1]: common::KeyValueStore
//! [trait2]: common::Context

/// Fundamental constant in ScyllaDB: The maximum size of a multi keys query
const MAX_MULTI_KEYS: usize = 100;

use std::{
collections::{hash_map::Entry, HashMap},
ops::Deref,
Expand All @@ -23,7 +26,7 @@ use std::{

use async_lock::{Semaphore, SemaphoreGuard};
use async_trait::async_trait;
use futures::{FutureExt as _, StreamExt};
use futures::{future::join_all, FutureExt as _, StreamExt};
use linera_base::ensure;
use scylla::{
frame::request::batch::BatchType,
Expand Down Expand Up @@ -420,7 +423,14 @@ impl ReadableKeyValueStore<ScyllaDbContextError> for ScyllaDbStoreInternal {
}
let store = self.store.deref();
let _guard = self.acquire().await;
store.read_multi_values_internal(keys).await
let handles = keys
.chunks(MAX_MULTI_KEYS)
.map(|keys| store.read_multi_values_internal(keys.to_vec()));
let results: Vec<_> = join_all(handles)
.await
.into_iter()
.collect::<Result<_, _>>()?;
Ok(results.into_iter().flatten().collect())
}

async fn find_keys_by_prefix(
Expand Down
3 changes: 2 additions & 1 deletion linera-views/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub async fn run_reads<S: LocalKeyValueStore>(store: S, key_values: Vec<(Vec<u8>
}
// Now checking the read_multi_values_bytes
let mut rng = make_deterministic_rng();
for _ in 0..10 {
for _ in 0..3 {
let mut keys = Vec::new();
let mut values = Vec::new();
for (key, value) in &key_values {
Expand Down Expand Up @@ -349,6 +349,7 @@ fn get_random_key_values2(num_entries: usize, len_value: usize) -> Vec<(Vec<u8>,
pub fn get_random_test_scenarios() -> Vec<Vec<(Vec<u8>, Vec<u8>)>> {
vec![
get_random_key_values1(7, 3),
get_random_key_values1(150, 3),
get_random_key_values1(30, 10),
get_random_key_values2(30, 10),
get_random_key_values2(30, 100),
Expand Down

0 comments on commit a320175

Please sign in to comment.