Skip to content

Commit 54a0e82

Browse files
Cleanups of the storage definitions. (#2979)
* Simplify out the `LocalStackTestContext` that is no longer used. * Remove unused enum in the error types: `MissingDatabase` and `AlreadyExistingDatabase`. * Introduce constructors for the `RocksDbStoreConfig` and similar. * Remove the `pub` attribute when not needed. * Correct the mis-attribution "lru splitting" into "lru caching". * Add a `PathWithStorage` function `new_testing` and remove standalone functions. * Put the constructor definition of `VISIBLE_MAX_VALUE_SIZE` for DynamoDb. * Remove tests that simply reproduce the formula. * The `InvalidTableName` was renamed as `InvalidNamespace`.
1 parent 31ea0c3 commit 54a0e82

File tree

11 files changed

+149
-241
lines changed

11 files changed

+149
-241
lines changed

linera-client/src/storage.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use linera_storage_service::{
1212
common::{ServiceStoreConfig, ServiceStoreInternalConfig},
1313
};
1414
#[cfg(feature = "dynamodb")]
15-
use linera_views::dynamo_db::{
16-
get_config, DynamoDbStore, DynamoDbStoreConfig, DynamoDbStoreInternalConfig,
17-
};
15+
use linera_views::dynamo_db::{get_config, DynamoDbStore, DynamoDbStoreConfig};
1816
#[cfg(with_storage)]
1917
use linera_views::store::LocalAdminKeyValueStore as _;
2018
use linera_views::{
@@ -25,15 +23,12 @@ use linera_views::{
2523
use tracing::error;
2624
#[cfg(feature = "rocksdb")]
2725
use {
28-
linera_views::rocks_db::{
29-
PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig,
30-
RocksDbStoreInternalConfig,
31-
},
26+
linera_views::rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
3227
std::path::PathBuf,
3328
};
3429
#[cfg(feature = "scylladb")]
3530
use {
36-
linera_views::scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig, ScyllaDbStoreInternalConfig},
31+
linera_views::scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig},
3732
std::num::NonZeroU16,
3833
tracing::debug,
3934
};
@@ -363,40 +358,18 @@ impl StorageConfigNamespace {
363358
StorageConfig::RocksDb { path, spawn_mode } => {
364359
let path_buf = path.to_path_buf();
365360
let path_with_guard = PathWithGuard::new(path_buf);
366-
let inner_config = RocksDbStoreInternalConfig {
367-
path_with_guard,
368-
spawn_mode: *spawn_mode,
369-
common_config: common_config.reduced(),
370-
};
371-
let config = RocksDbStoreConfig {
372-
inner_config,
373-
cache_size: common_config.cache_size,
374-
};
361+
let config = RocksDbStoreConfig::new(*spawn_mode, path_with_guard, common_config);
375362
Ok(StoreConfig::RocksDb(config, namespace))
376363
}
377364
#[cfg(feature = "dynamodb")]
378365
StorageConfig::DynamoDb { use_localstack } => {
379366
let aws_config = get_config(*use_localstack).await?;
380-
let inner_config = DynamoDbStoreInternalConfig {
381-
config: aws_config,
382-
common_config: common_config.reduced(),
383-
};
384-
let config = DynamoDbStoreConfig {
385-
inner_config,
386-
cache_size: common_config.cache_size,
387-
};
367+
let config = DynamoDbStoreConfig::new(aws_config, common_config);
388368
Ok(StoreConfig::DynamoDb(config, namespace))
389369
}
390370
#[cfg(feature = "scylladb")]
391371
StorageConfig::ScyllaDb { uri } => {
392-
let inner_config = ScyllaDbStoreInternalConfig {
393-
uri: uri.to_string(),
394-
common_config: common_config.reduced(),
395-
};
396-
let config = ScyllaDbStoreConfig {
397-
inner_config,
398-
cache_size: common_config.cache_size,
399-
};
372+
let config = ScyllaDbStoreConfig::new(uri.to_string(), common_config);
400373
Ok(StoreConfig::ScyllaDb(config, namespace))
401374
}
402375
}

linera-indexer/lib/src/rocks_db.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ use std::path::PathBuf;
55

66
use clap::Parser as _;
77
use linera_views::{
8-
rocks_db::{
9-
PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig,
10-
RocksDbStoreInternalConfig,
11-
},
12-
store::{AdminKeyValueStore, CommonStoreInternalConfig},
8+
rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
9+
store::{AdminKeyValueStore, CommonStoreConfig},
1310
};
1411

1512
use crate::{
@@ -41,24 +38,17 @@ pub type RocksDbRunner = Runner<RocksDbStore, RocksDbConfig>;
4138
impl RocksDbRunner {
4239
pub async fn load() -> Result<Self, IndexerError> {
4340
let config = IndexerConfig::<RocksDbConfig>::parse();
44-
let common_config = CommonStoreInternalConfig {
41+
let common_config = CommonStoreConfig {
4542
max_concurrent_queries: config.client.max_concurrent_queries,
4643
max_stream_queries: config.client.max_stream_queries,
44+
cache_size: config.client.cache_size,
4745
};
4846
let path_buf = config.client.storage.as_path().to_path_buf();
4947
let path_with_guard = PathWithGuard::new(path_buf);
5048
// The tests are run in single threaded mode, therefore we need
5149
// to use the safe default value of SpawnBlocking.
5250
let spawn_mode = RocksDbSpawnMode::SpawnBlocking;
53-
let inner_config = RocksDbStoreInternalConfig {
54-
path_with_guard,
55-
spawn_mode,
56-
common_config,
57-
};
58-
let store_config = RocksDbStoreConfig {
59-
inner_config,
60-
cache_size: config.client.cache_size,
61-
};
51+
let store_config = RocksDbStoreConfig::new(spawn_mode, path_with_guard, common_config);
6252
let namespace = config.client.namespace.clone();
6353
let root_key = &[];
6454
let store =

linera-indexer/lib/src/scylla_db.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use linera_views::{
5-
scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig, ScyllaDbStoreInternalConfig},
6-
store::{AdminKeyValueStore, CommonStoreInternalConfig},
5+
scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig},
6+
store::{AdminKeyValueStore, CommonStoreConfig},
77
};
88

99
use crate::{
@@ -35,20 +35,14 @@ pub type ScyllaDbRunner = Runner<ScyllaDbStore, ScyllaDbConfig>;
3535
impl ScyllaDbRunner {
3636
pub async fn load() -> Result<Self, IndexerError> {
3737
let config = <IndexerConfig<ScyllaDbConfig> as clap::Parser>::parse();
38-
let common_config = CommonStoreInternalConfig {
38+
let common_config = CommonStoreConfig {
3939
max_concurrent_queries: config.client.max_concurrent_queries,
4040
max_stream_queries: config.client.max_stream_queries,
41+
cache_size: config.client.cache_size,
4142
};
4243
let namespace = config.client.table.clone();
4344
let root_key = &[];
44-
let inner_config = ScyllaDbStoreInternalConfig {
45-
uri: config.client.uri.clone(),
46-
common_config,
47-
};
48-
let store_config = ScyllaDbStoreConfig {
49-
inner_config,
50-
cache_size: config.client.cache_size,
51-
};
45+
let store_config = ScyllaDbStoreConfig::new(config.client.uri.clone(), common_config);
5246
let store = ScyllaDbStore::connect(&store_config, &namespace, root_key).await?;
5347
Self::new(config, store).await
5448
}

linera-storage-service/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::PathBuf;
55

66
use linera_base::command::resolve_binary;
77
use linera_views::{
8-
lru_caching::LruSplittingConfig,
8+
lru_caching::LruCachingConfig,
99
store::{CommonStoreInternalConfig, KeyValueStoreError},
1010
views::MIN_VIEW_TAG,
1111
};
@@ -78,7 +78,7 @@ pub struct ServiceStoreInternalConfig {
7878
}
7979

8080
/// The config type
81-
pub type ServiceStoreConfig = LruSplittingConfig<ServiceStoreInternalConfig>;
81+
pub type ServiceStoreConfig = LruCachingConfig<ServiceStoreInternalConfig>;
8282

8383
impl ServiceStoreInternalConfig {
8484
pub fn http_address(&self) -> String {

linera-storage-service/src/server.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use linera_views::{
1414
};
1515
#[cfg(with_rocksdb)]
1616
use linera_views::{
17-
rocks_db::{
18-
PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig,
19-
RocksDbStoreInternalConfig,
20-
},
17+
rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
2118
store::AdminKeyValueStore as _,
2219
};
2320
use serde::Serialize;
@@ -588,15 +585,7 @@ async fn main() {
588585
let path_with_guard = PathWithGuard::new(path_buf);
589586
// The server is run in multi-threaded mode so we can use the block_in_place.
590587
let spawn_mode = RocksDbSpawnMode::get_spawn_mode_from_runtime();
591-
let inner_config = RocksDbStoreInternalConfig {
592-
path_with_guard,
593-
spawn_mode,
594-
common_config: common_config.reduced(),
595-
};
596-
let config = RocksDbStoreConfig {
597-
inner_config,
598-
cache_size: common_config.cache_size,
599-
};
588+
let config = RocksDbStoreConfig::new(spawn_mode, path_with_guard, common_config);
600589
let store = RocksDbStore::maybe_create_and_connect(&config, namespace, root_key)
601590
.await
602591
.expect("store");

linera-views/benches/queue_view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use linera_views::rocks_db::RocksDbStore;
1414
#[cfg(with_scylladb)]
1515
use linera_views::scylla_db::ScyllaDbStore;
1616
use linera_views::{
17-
backends::memory::MemoryStore,
1817
bucket_queue_view::BucketQueueView,
1918
context::ViewContext,
19+
memory::MemoryStore,
2020
queue_view::QueueView,
2121
random::{make_deterministic_rng, DeterministicRng},
2222
store::{KeyValueStore, TestKeyValueStore as _},

0 commit comments

Comments
 (0)