diff --git a/linera-views/src/backends/scylla_db.rs b/linera-views/src/backends/scylla_db.rs index 27ed7252876..d45c9bdda3d 100644 --- a/linera-views/src/backends/scylla_db.rs +++ b/linera-views/src/backends/scylla_db.rs @@ -165,7 +165,10 @@ impl ScyllaDbClient { root_key: &[u8], key: Vec, ) -> Result>, ScyllaDbStoreInternalError> { - ensure!(key.len() <= MAX_KEY_SIZE, ScyllaDbStoreInternalError::KeyTooLong); + ensure!( + key.len() <= MAX_KEY_SIZE, + ScyllaDbStoreInternalError::KeyTooLong + ); let session = &self.session; // Read the value of a key let values = (root_key.to_vec(), key); @@ -191,7 +194,10 @@ impl ScyllaDbClient { let mut inputs = Vec::new(); inputs.push(root_key.to_vec()); for (i_key, key) in keys.into_iter().enumerate() { - ensure!(key.len() <= MAX_KEY_SIZE, ScyllaDbStoreInternalError::KeyTooLong); + ensure!( + key.len() <= MAX_KEY_SIZE, + ScyllaDbStoreInternalError::KeyTooLong + ); match map.entry(key.clone()) { Entry::Occupied(entry) => { let entry = entry.into_mut(); @@ -237,7 +243,10 @@ impl ScyllaDbClient { let mut inputs = Vec::new(); inputs.push(root_key.to_vec()); for (i_key, key) in keys.into_iter().enumerate() { - ensure!(key.len() <= MAX_KEY_SIZE, ScyllaDbStoreInternalError::KeyTooLong); + ensure!( + key.len() <= MAX_KEY_SIZE, + ScyllaDbStoreInternalError::KeyTooLong + ); match map.entry(key.clone()) { Entry::Occupied(entry) => { let entry = entry.into_mut(); @@ -273,7 +282,10 @@ impl ScyllaDbClient { root_key: &[u8], key: Vec, ) -> Result { - ensure!(key.len() <= MAX_KEY_SIZE, ScyllaDbStoreInternalError::KeyTooLong); + ensure!( + key.len() <= MAX_KEY_SIZE, + ScyllaDbStoreInternalError::KeyTooLong + ); let session = &self.session; // Read the value of a key let values = (root_key.to_vec(), key); @@ -293,8 +305,14 @@ impl ScyllaDbClient { let query1 = &self.write_batch_delete_prefix_unbounded; let query2 = &self.write_batch_delete_prefix_bounded; println!("|batch|={}", batch.len()); - ensure!(batch.len() <= MAX_BATCH_SIZE, ScyllaDbStoreInternalError::TooLargeBatch); - println!("|key_prefix_deletions|={}", batch.key_prefix_deletions.len()); + ensure!( + batch.len() <= MAX_BATCH_SIZE, + ScyllaDbStoreInternalError::TooLargeBatch + ); + println!( + "|key_prefix_deletions|={}", + batch.key_prefix_deletions.len() + ); for key_prefix in batch.key_prefix_deletions { ensure!( key_prefix.len() <= MAX_KEY_SIZE, @@ -314,7 +332,10 @@ impl ScyllaDbClient { } } let query3 = &self.write_batch_deletion; - println!("|deletions|={}", batch.simple_unordered_batch.deletions.len()); + println!( + "|deletions|={}", + batch.simple_unordered_batch.deletions.len() + ); for key in batch.simple_unordered_batch.deletions { ensure!( key.len() <= MAX_KEY_SIZE, @@ -325,12 +346,18 @@ impl ScyllaDbClient { batch_query.append_statement(query3.clone()); } let query4 = &self.write_batch_insertion; - println!("|insertions|={}", batch.simple_unordered_batch.insertions.len()); + println!( + "|insertions|={}", + batch.simple_unordered_batch.insertions.len() + ); let mut total_size = 0; for (key, value) in batch.simple_unordered_batch.insertions { println!("|key|={} |value|={}", key.len(), value.len()); total_size += key.len() + value.len(); - ensure!(key.len() <= MAX_KEY_SIZE, ScyllaDbStoreInternalError::KeyTooLong); + ensure!( + key.len() <= MAX_KEY_SIZE, + ScyllaDbStoreInternalError::KeyTooLong + ); ensure!( value.len() <= RAW_MAX_VALUE_SIZE, ScyllaDbStoreInternalError::ValueTooLong @@ -485,7 +512,10 @@ impl ReadableKeyValueStore for ScyllaDbStoreInternal { self.max_stream_queries } - async fn read_value_bytes(&self, key: &[u8]) -> Result>, ScyllaDbStoreInternalError> { + async fn read_value_bytes( + &self, + key: &[u8], + ) -> Result>, ScyllaDbStoreInternalError> { let store = self.store.deref(); let _guard = self.acquire().await; store @@ -501,7 +531,10 @@ impl ReadableKeyValueStore for ScyllaDbStoreInternal { .await } - async fn contains_keys(&self, keys: Vec>) -> Result, ScyllaDbStoreInternalError> { + async fn contains_keys( + &self, + keys: Vec>, + ) -> Result, ScyllaDbStoreInternalError> { if keys.is_empty() { return Ok(Vec::new()); } @@ -702,7 +735,10 @@ impl AdminKeyValueStore for ScyllaDbStoreInternal { Ok(()) } - async fn exists(config: &Self::Config, namespace: &str) -> Result { + async fn exists( + config: &Self::Config, + namespace: &str, + ) -> Result { Self::check_namespace(namespace)?; let session = SessionBuilder::new() .known_node(config.uri.as_str()) @@ -746,7 +782,10 @@ impl AdminKeyValueStore for ScyllaDbStoreInternal { } } - async fn create(config: &Self::Config, namespace: &str) -> Result<(), ScyllaDbStoreInternalError> { + async fn create( + config: &Self::Config, + namespace: &str, + ) -> Result<(), ScyllaDbStoreInternalError> { Self::check_namespace(namespace)?; let session = SessionBuilder::new() .known_node(config.uri.as_str()) @@ -771,7 +810,10 @@ impl AdminKeyValueStore for ScyllaDbStoreInternal { Ok(()) } - async fn delete(config: &Self::Config, namespace: &str) -> Result<(), ScyllaDbStoreInternalError> { + async fn delete( + config: &Self::Config, + namespace: &str, + ) -> Result<(), ScyllaDbStoreInternalError> { Self::check_namespace(namespace)?; let session = SessionBuilder::new() .known_node(config.uri.as_str()) @@ -828,12 +870,18 @@ impl TestKeyValueStore for JournalingKeyValueStore { /// The `ScyllaDbStore` composed type with metrics #[cfg(with_metrics)] -pub type ScyllaDbStore = - MeteredStore>>>>>; +pub type ScyllaDbStore = MeteredStore< + LruCachingStore< + MeteredStore< + ValueSplittingStore>>, + >, + >, +>; /// The `ScyllaDbStore` composed type #[cfg(not(with_metrics))] -pub type ScyllaDbStore = LruCachingStore>>; +pub type ScyllaDbStore = + LruCachingStore>>; /// The `ScyllaDbStoreConfig` input type pub type ScyllaDbStoreConfig = LruSplittingConfig; diff --git a/linera-views/src/batch.rs b/linera-views/src/batch.rs index b8e5cf1b372..a681b09f69e 100644 --- a/linera-views/src/batch.rs +++ b/linera-views/src/batch.rs @@ -153,6 +153,11 @@ impl UnorderedBatch { pub fn len(&self) -> usize { self.key_prefix_deletions.len() + self.simple_unordered_batch.len() } + + /// Tests whether the batch is empty or not + pub fn is_empty(&self) -> bool { + self.key_prefix_deletions.len() == 0 && self.simple_unordered_batch.len() == 0 + } } /// Checks if `key` is matched by any prefix in `key_prefix_set`. diff --git a/linera-views/src/test_utils/mod.rs b/linera-views/src/test_utils/mod.rs index dd22ff3389b..b9dcdd5d730 100644 --- a/linera-views/src/test_utils/mod.rs +++ b/linera-views/src/test_utils/mod.rs @@ -419,12 +419,18 @@ pub async fn run_writes_from_blank(key_value_st } /// Doing a big read of many keys could trigger some error. That need to be tested. -pub async fn big_read_multi_values(config: C::Config, value_size: usize, n_entries: usize) { +pub async fn big_read_multi_values( + config: C::Config, + value_size: usize, + n_entries: usize, +) { let mut rng = make_deterministic_rng(); let namespace = generate_test_namespace(); let root_key = &[]; // - let store = C::recreate_and_connect(&config, &namespace, root_key).await.unwrap(); + let store = C::recreate_and_connect(&config, &namespace, root_key) + .await + .unwrap(); let key_prefix = vec![42, 54]; let mut batch = Batch::new(); let mut keys = Vec::new(); @@ -497,7 +503,10 @@ pub async fn run_big_write_read( let mut rng = make_deterministic_rng(); for (pos, value_size) in value_sizes.into_iter().enumerate() { let n_entry: usize = target_size / value_size; - println!("n_entry={} target_size={} value_size={}", n_entry, target_size, value_size); + println!( + "n_entry={} target_size={} value_size={}", + n_entry, target_size, value_size + ); let mut batch = Batch::new(); let key_prefix = vec![0, pos as u8]; for i in 0..n_entry { diff --git a/linera-views/tests/store_tests.rs b/linera-views/tests/store_tests.rs index bbe4ad136cb..2f1715698ef 100644 --- a/linera-views/tests/store_tests.rs +++ b/linera-views/tests/store_tests.rs @@ -32,9 +32,7 @@ async fn test_read_multi_values_memory() { #[tokio::test] async fn test_read_multi_values_dynamo_db() { use linera_views::dynamo_db::DynamoDbStore; - let config = DynamoDbStore::new_test_config() - .await - .unwrap(); + let config = DynamoDbStore::new_test_config().await.unwrap(); big_read_multi_values::(config, 22000000, 1000).await; } @@ -43,9 +41,7 @@ async fn test_read_multi_values_dynamo_db() { #[tokio::test] async fn test_read_multi_values_scylla_db() { use linera_views::scylla_db::ScyllaDbStore; - let config = ScyllaDbStore::new_test_config() - .await - .unwrap(); + let config = ScyllaDbStore::new_test_config().await.unwrap(); big_read_multi_values::(config, 22200000, 200).await; }