Skip to content

Commit

Permalink
Cleanups of the storage definitions. (#2979)
Browse files Browse the repository at this point in the history
* 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`.
  • Loading branch information
MathieuDutSik authored Nov 30, 2024
1 parent 31ea0c3 commit 54a0e82
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 241 deletions.
39 changes: 6 additions & 33 deletions linera-client/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use linera_storage_service::{
common::{ServiceStoreConfig, ServiceStoreInternalConfig},
};
#[cfg(feature = "dynamodb")]
use linera_views::dynamo_db::{
get_config, DynamoDbStore, DynamoDbStoreConfig, DynamoDbStoreInternalConfig,
};
use linera_views::dynamo_db::{get_config, DynamoDbStore, DynamoDbStoreConfig};
#[cfg(with_storage)]
use linera_views::store::LocalAdminKeyValueStore as _;
use linera_views::{
Expand All @@ -25,15 +23,12 @@ use linera_views::{
use tracing::error;
#[cfg(feature = "rocksdb")]
use {
linera_views::rocks_db::{
PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig,
RocksDbStoreInternalConfig,
},
linera_views::rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
std::path::PathBuf,
};
#[cfg(feature = "scylladb")]
use {
linera_views::scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig, ScyllaDbStoreInternalConfig},
linera_views::scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig},
std::num::NonZeroU16,
tracing::debug,
};
Expand Down Expand Up @@ -363,40 +358,18 @@ impl StorageConfigNamespace {
StorageConfig::RocksDb { path, spawn_mode } => {
let path_buf = path.to_path_buf();
let path_with_guard = PathWithGuard::new(path_buf);
let inner_config = RocksDbStoreInternalConfig {
path_with_guard,
spawn_mode: *spawn_mode,
common_config: common_config.reduced(),
};
let config = RocksDbStoreConfig {
inner_config,
cache_size: common_config.cache_size,
};
let config = RocksDbStoreConfig::new(*spawn_mode, path_with_guard, common_config);
Ok(StoreConfig::RocksDb(config, namespace))
}
#[cfg(feature = "dynamodb")]
StorageConfig::DynamoDb { use_localstack } => {
let aws_config = get_config(*use_localstack).await?;
let inner_config = DynamoDbStoreInternalConfig {
config: aws_config,
common_config: common_config.reduced(),
};
let config = DynamoDbStoreConfig {
inner_config,
cache_size: common_config.cache_size,
};
let config = DynamoDbStoreConfig::new(aws_config, common_config);
Ok(StoreConfig::DynamoDb(config, namespace))
}
#[cfg(feature = "scylladb")]
StorageConfig::ScyllaDb { uri } => {
let inner_config = ScyllaDbStoreInternalConfig {
uri: uri.to_string(),
common_config: common_config.reduced(),
};
let config = ScyllaDbStoreConfig {
inner_config,
cache_size: common_config.cache_size,
};
let config = ScyllaDbStoreConfig::new(uri.to_string(), common_config);
Ok(StoreConfig::ScyllaDb(config, namespace))
}
}
Expand Down
20 changes: 5 additions & 15 deletions linera-indexer/lib/src/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use std::path::PathBuf;

use clap::Parser as _;
use linera_views::{
rocks_db::{
PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig,
RocksDbStoreInternalConfig,
},
store::{AdminKeyValueStore, CommonStoreInternalConfig},
rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
store::{AdminKeyValueStore, CommonStoreConfig},
};

use crate::{
Expand Down Expand Up @@ -41,24 +38,17 @@ pub type RocksDbRunner = Runner<RocksDbStore, RocksDbConfig>;
impl RocksDbRunner {
pub async fn load() -> Result<Self, IndexerError> {
let config = IndexerConfig::<RocksDbConfig>::parse();
let common_config = CommonStoreInternalConfig {
let common_config = CommonStoreConfig {
max_concurrent_queries: config.client.max_concurrent_queries,
max_stream_queries: config.client.max_stream_queries,
cache_size: config.client.cache_size,
};
let path_buf = config.client.storage.as_path().to_path_buf();
let path_with_guard = PathWithGuard::new(path_buf);
// The tests are run in single threaded mode, therefore we need
// to use the safe default value of SpawnBlocking.
let spawn_mode = RocksDbSpawnMode::SpawnBlocking;
let inner_config = RocksDbStoreInternalConfig {
path_with_guard,
spawn_mode,
common_config,
};
let store_config = RocksDbStoreConfig {
inner_config,
cache_size: config.client.cache_size,
};
let store_config = RocksDbStoreConfig::new(spawn_mode, path_with_guard, common_config);
let namespace = config.client.namespace.clone();
let root_key = &[];
let store =
Expand Down
16 changes: 5 additions & 11 deletions linera-indexer/lib/src/scylla_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use linera_views::{
scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig, ScyllaDbStoreInternalConfig},
store::{AdminKeyValueStore, CommonStoreInternalConfig},
scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig},
store::{AdminKeyValueStore, CommonStoreConfig},
};

use crate::{
Expand Down Expand Up @@ -35,20 +35,14 @@ pub type ScyllaDbRunner = Runner<ScyllaDbStore, ScyllaDbConfig>;
impl ScyllaDbRunner {
pub async fn load() -> Result<Self, IndexerError> {
let config = <IndexerConfig<ScyllaDbConfig> as clap::Parser>::parse();
let common_config = CommonStoreInternalConfig {
let common_config = CommonStoreConfig {
max_concurrent_queries: config.client.max_concurrent_queries,
max_stream_queries: config.client.max_stream_queries,
cache_size: config.client.cache_size,
};
let namespace = config.client.table.clone();
let root_key = &[];
let inner_config = ScyllaDbStoreInternalConfig {
uri: config.client.uri.clone(),
common_config,
};
let store_config = ScyllaDbStoreConfig {
inner_config,
cache_size: config.client.cache_size,
};
let store_config = ScyllaDbStoreConfig::new(config.client.uri.clone(), common_config);
let store = ScyllaDbStore::connect(&store_config, &namespace, root_key).await?;
Self::new(config, store).await
}
Expand Down
4 changes: 2 additions & 2 deletions linera-storage-service/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::PathBuf;

use linera_base::command::resolve_binary;
use linera_views::{
lru_caching::LruSplittingConfig,
lru_caching::LruCachingConfig,
store::{CommonStoreInternalConfig, KeyValueStoreError},
views::MIN_VIEW_TAG,
};
Expand Down Expand Up @@ -78,7 +78,7 @@ pub struct ServiceStoreInternalConfig {
}

/// The config type
pub type ServiceStoreConfig = LruSplittingConfig<ServiceStoreInternalConfig>;
pub type ServiceStoreConfig = LruCachingConfig<ServiceStoreInternalConfig>;

impl ServiceStoreInternalConfig {
pub fn http_address(&self) -> String {
Expand Down
15 changes: 2 additions & 13 deletions linera-storage-service/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use linera_views::{
};
#[cfg(with_rocksdb)]
use linera_views::{
rocks_db::{
PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig,
RocksDbStoreInternalConfig,
},
rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
store::AdminKeyValueStore as _,
};
use serde::Serialize;
Expand Down Expand Up @@ -588,15 +585,7 @@ async fn main() {
let path_with_guard = PathWithGuard::new(path_buf);
// The server is run in multi-threaded mode so we can use the block_in_place.
let spawn_mode = RocksDbSpawnMode::get_spawn_mode_from_runtime();
let inner_config = RocksDbStoreInternalConfig {
path_with_guard,
spawn_mode,
common_config: common_config.reduced(),
};
let config = RocksDbStoreConfig {
inner_config,
cache_size: common_config.cache_size,
};
let config = RocksDbStoreConfig::new(spawn_mode, path_with_guard, common_config);
let store = RocksDbStore::maybe_create_and_connect(&config, namespace, root_key)
.await
.expect("store");
Expand Down
2 changes: 1 addition & 1 deletion linera-views/benches/queue_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use linera_views::rocks_db::RocksDbStore;
#[cfg(with_scylladb)]
use linera_views::scylla_db::ScyllaDbStore;
use linera_views::{
backends::memory::MemoryStore,
bucket_queue_view::BucketQueueView,
context::ViewContext,
memory::MemoryStore,
queue_view::QueueView,
random::{make_deterministic_rng, DeterministicRng},
store::{KeyValueStore, TestKeyValueStore as _},
Expand Down
Loading

0 comments on commit 54a0e82

Please sign in to comment.