Skip to content

Commit e73bcf1

Browse files
authored
Remove CommonStoreInternalConfig and CommonStoreConfig (#4115)
## Motivation Storage backends should only receive configuration options that they actually use. ## Proposal * Remove `CommonStoreInternalConfig` and `CommonStoreConfig` step by step * Add missing CLI options to `linera-storage-service` Nothing changes from the user point of view. This temporary creates a little more code duplication between `linera-service` and the binaries in `linera-indexer` and `linera-storage-service` but I think that's fine and should be fixed over time. Future work: * We may re-evaluate whether `max_stream_queries` is best implemented as a method of `ReadableKeyValueStore`. * I'm still conflicted about `max_concurrent_queries` and would very much like to remove it. * It's not clear what happens if we pass the wrong replication factor for ScyllaDb. * We may re-evaluate whether `linera-indexer` and `linera-storage-service` belong to separate crates. Follows #4111 ## Test Plan CI
1 parent cd048db commit e73bcf1

File tree

13 files changed

+241
-321
lines changed

13 files changed

+241
-321
lines changed

linera-indexer/lib/src/rocks_db.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ use std::path::PathBuf;
66
use clap::Parser as _;
77
use linera_views::{
88
lru_caching::StorageCacheConfig,
9-
rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig},
10-
store::{AdminKeyValueStore, CommonStoreConfig},
9+
rocks_db::{
10+
PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig,
11+
RocksDbStoreInternalConfig,
12+
},
13+
store::AdminKeyValueStore as _,
1114
};
1215

1316
use crate::{
@@ -56,18 +59,20 @@ impl RocksDbRunner {
5659
max_entry_size: config.client.max_entry_size,
5760
max_cache_entries: config.client.max_cache_entries,
5861
};
59-
let common_config = CommonStoreConfig {
60-
max_concurrent_queries: config.client.max_concurrent_queries,
61-
max_stream_queries: config.client.max_stream_queries,
62-
storage_cache_config,
63-
replication_factor: 1,
64-
};
6562
let path_buf = config.client.storage.as_path().to_path_buf();
6663
let path_with_guard = PathWithGuard::new(path_buf);
6764
// The tests are run in single threaded mode, therefore we need
6865
// to use the safe default value of SpawnBlocking.
6966
let spawn_mode = RocksDbSpawnMode::SpawnBlocking;
70-
let store_config = RocksDbStoreConfig::new(spawn_mode, path_with_guard, common_config);
67+
let inner_config = RocksDbStoreInternalConfig {
68+
spawn_mode,
69+
path_with_guard,
70+
max_stream_queries: config.client.max_stream_queries,
71+
};
72+
let store_config = RocksDbStoreConfig {
73+
inner_config,
74+
storage_cache_config,
75+
};
7176
let namespace = config.client.namespace.clone();
7277
let store = RocksDbStore::maybe_create_and_connect(&store_config, &namespace).await?;
7378
Self::new(config, store).await

linera-indexer/lib/src/scylla_db.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use linera_views::{
55
lru_caching::StorageCacheConfig,
6-
scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig},
7-
store::{AdminKeyValueStore, CommonStoreConfig},
6+
scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig, ScyllaDbStoreInternalConfig},
7+
store::AdminKeyValueStore,
88
};
99

1010
use crate::{
@@ -57,14 +57,17 @@ impl ScyllaDbRunner {
5757
max_entry_size: config.client.max_entry_size,
5858
max_cache_entries: config.client.max_cache_entries,
5959
};
60-
let common_config = CommonStoreConfig {
61-
max_concurrent_queries: config.client.max_concurrent_queries,
60+
let inner_config = ScyllaDbStoreInternalConfig {
61+
uri: config.client.uri.clone(),
6262
max_stream_queries: config.client.max_stream_queries,
63-
storage_cache_config,
63+
max_concurrent_queries: config.client.max_concurrent_queries,
6464
replication_factor: config.client.replication_factor,
6565
};
66+
let store_config = ScyllaDbStoreConfig {
67+
inner_config,
68+
storage_cache_config,
69+
};
6670
let namespace = config.client.table.clone();
67-
let store_config = ScyllaDbStoreConfig::new(config.client.uri.clone(), common_config);
6871
let store = ScyllaDbStore::connect(&store_config, &namespace).await?;
6972
Self::new(config, store).await
7073
}

linera-service/src/storage.rs

Lines changed: 85 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ use linera_storage_service::{
1414
common::{ServiceStoreConfig, ServiceStoreInternalConfig},
1515
};
1616
#[cfg(feature = "dynamodb")]
17-
use linera_views::dynamo_db::{DynamoDbStore, DynamoDbStoreConfig};
17+
use linera_views::dynamo_db::{DynamoDbStore, DynamoDbStoreConfig, DynamoDbStoreInternalConfig};
1818
#[cfg(feature = "rocksdb")]
19-
use linera_views::rocks_db::{PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig};
19+
use linera_views::rocks_db::{
20+
PathWithGuard, RocksDbSpawnMode, RocksDbStore, RocksDbStoreConfig, RocksDbStoreInternalConfig,
21+
};
2022
use linera_views::{
2123
lru_caching::StorageCacheConfig,
2224
memory::{MemoryStore, MemoryStoreConfig},
23-
store::{CommonStoreConfig, KeyValueStore},
25+
store::KeyValueStore,
2426
};
2527
use serde::{Deserialize, Serialize};
2628
use tracing::error;
@@ -32,7 +34,7 @@ use {
3234
};
3335
#[cfg(feature = "scylladb")]
3436
use {
35-
linera_views::scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig},
37+
linera_views::scylla_db::{ScyllaDbStore, ScyllaDbStoreConfig, ScyllaDbStoreInternalConfig},
3638
std::num::NonZeroU16,
3739
tracing::debug,
3840
};
@@ -65,36 +67,30 @@ pub struct CommonStorageOptions {
6567
}
6668

6769
impl CommonStorageOptions {
68-
pub fn common_store_config(&self) -> CommonStoreConfig {
69-
let storage_cache_config = StorageCacheConfig {
70+
pub fn storage_cache_config(&self) -> StorageCacheConfig {
71+
StorageCacheConfig {
7072
max_cache_size: self.storage_max_cache_size,
7173
max_entry_size: self.storage_max_entry_size,
7274
max_cache_entries: self.storage_max_cache_entries,
73-
};
74-
CommonStoreConfig {
75-
storage_cache_config,
76-
max_concurrent_queries: self.storage_max_concurrent_queries,
77-
max_stream_queries: self.storage_max_stream_queries,
78-
replication_factor: self.storage_replication_factor,
7975
}
8076
}
8177
}
8278

8379
/// The configuration of the key value store in use.
8480
#[derive(Clone, Debug, Deserialize, Serialize)]
8581
pub enum StoreConfig {
86-
/// The storage service key-value store
87-
#[cfg(feature = "storage-service")]
88-
Service {
89-
config: ServiceStoreConfig,
90-
namespace: String,
91-
},
9282
/// The memory key value store
9383
Memory {
9484
config: MemoryStoreConfig,
9585
namespace: String,
9686
genesis_path: PathBuf,
9787
},
88+
/// The storage service key-value store
89+
#[cfg(feature = "storage-service")]
90+
Service {
91+
config: ServiceStoreConfig,
92+
namespace: String,
93+
},
9894
/// The RocksDB key value store
9995
#[cfg(feature = "rocksdb")]
10096
RocksDb {
@@ -124,18 +120,18 @@ pub enum StoreConfig {
124120
#[derive(Clone, Debug)]
125121
#[cfg_attr(any(test), derive(Eq, PartialEq))]
126122
pub enum InnerStorageConfig {
127-
/// The storage service description.
128-
#[cfg(feature = "storage-service")]
129-
Service {
130-
/// The endpoint used.
131-
endpoint: String,
132-
},
133123
/// The memory description.
134124
Memory {
135125
/// The path to the genesis configuration. This is needed because we reinitialize
136126
/// memory databases from the genesis config everytime.
137127
genesis_path: PathBuf,
138128
},
129+
/// The storage service description.
130+
#[cfg(feature = "storage-service")]
131+
Service {
132+
/// The endpoint used.
133+
endpoint: String,
134+
},
139135
/// The RocksDB description.
140136
#[cfg(feature = "rocksdb")]
141137
RocksDb {
@@ -430,25 +426,11 @@ impl StorageConfig {
430426
&self,
431427
options: &CommonStorageOptions,
432428
) -> Result<StoreConfig, anyhow::Error> {
433-
let common_config = options.common_store_config();
434429
let namespace = self.namespace.clone();
435430
match &self.inner_storage_config {
436-
#[cfg(feature = "storage-service")]
437-
InnerStorageConfig::Service { endpoint } => {
438-
let endpoint = endpoint.clone();
439-
let inner_config = ServiceStoreInternalConfig {
440-
endpoint,
441-
common_config: common_config.reduced(),
442-
};
443-
let config = ServiceStoreConfig {
444-
inner_config,
445-
storage_cache_config: common_config.storage_cache_config,
446-
};
447-
Ok(StoreConfig::Service { config, namespace })
448-
}
449431
InnerStorageConfig::Memory { genesis_path } => {
450432
let config = MemoryStoreConfig {
451-
common_config: common_config.reduced(),
433+
max_stream_queries: options.storage_max_stream_queries,
452434
};
453435
let genesis_path = genesis_path.clone();
454436
Ok(StoreConfig::Memory {
@@ -457,21 +439,58 @@ impl StorageConfig {
457439
genesis_path,
458440
})
459441
}
442+
#[cfg(feature = "storage-service")]
443+
InnerStorageConfig::Service { endpoint } => {
444+
let inner_config = ServiceStoreInternalConfig {
445+
endpoint: endpoint.clone(),
446+
max_concurrent_queries: options.storage_max_concurrent_queries,
447+
max_stream_queries: options.storage_max_stream_queries,
448+
};
449+
let config = ServiceStoreConfig {
450+
inner_config,
451+
storage_cache_config: options.storage_cache_config(),
452+
};
453+
Ok(StoreConfig::Service { config, namespace })
454+
}
460455
#[cfg(feature = "rocksdb")]
461456
InnerStorageConfig::RocksDb { path, spawn_mode } => {
462-
let path_buf = path.to_path_buf();
463-
let path_with_guard = PathWithGuard::new(path_buf);
464-
let config = RocksDbStoreConfig::new(*spawn_mode, path_with_guard, common_config);
457+
let path_with_guard = PathWithGuard::new(path.to_path_buf());
458+
let inner_config = RocksDbStoreInternalConfig {
459+
spawn_mode: *spawn_mode,
460+
path_with_guard,
461+
max_stream_queries: options.storage_max_stream_queries,
462+
};
463+
let config = RocksDbStoreConfig {
464+
inner_config,
465+
storage_cache_config: options.storage_cache_config(),
466+
};
465467
Ok(StoreConfig::RocksDb { config, namespace })
466468
}
467469
#[cfg(feature = "dynamodb")]
468470
InnerStorageConfig::DynamoDb { use_dynamodb_local } => {
469-
let config = DynamoDbStoreConfig::new(*use_dynamodb_local, common_config);
471+
let inner_config = DynamoDbStoreInternalConfig {
472+
use_dynamodb_local: *use_dynamodb_local,
473+
max_concurrent_queries: options.storage_max_concurrent_queries,
474+
max_stream_queries: options.storage_max_stream_queries,
475+
};
476+
let config = DynamoDbStoreConfig {
477+
inner_config,
478+
storage_cache_config: options.storage_cache_config(),
479+
};
470480
Ok(StoreConfig::DynamoDb { config, namespace })
471481
}
472482
#[cfg(feature = "scylladb")]
473483
InnerStorageConfig::ScyllaDb { uri } => {
474-
let config = ScyllaDbStoreConfig::new(uri.to_string(), common_config);
484+
let inner_config = ScyllaDbStoreInternalConfig {
485+
uri: uri.clone(),
486+
max_stream_queries: options.storage_max_stream_queries,
487+
max_concurrent_queries: options.storage_max_concurrent_queries,
488+
replication_factor: options.storage_replication_factor,
489+
};
490+
let config = ScyllaDbStoreConfig {
491+
inner_config,
492+
storage_cache_config: options.storage_cache_config(),
493+
};
475494
Ok(StoreConfig::ScyllaDb { config, namespace })
476495
}
477496
#[cfg(all(feature = "rocksdb", feature = "scylladb"))]
@@ -480,12 +499,27 @@ impl StorageConfig {
480499
spawn_mode,
481500
uri,
482501
} => {
483-
let first_config = RocksDbStoreConfig::new(
484-
*spawn_mode,
485-
path_with_guard.clone(),
486-
common_config.clone(),
487-
);
488-
let second_config = ScyllaDbStoreConfig::new(uri.to_string(), common_config);
502+
let inner_config = RocksDbStoreInternalConfig {
503+
spawn_mode: *spawn_mode,
504+
path_with_guard: path_with_guard.clone(),
505+
max_stream_queries: options.storage_max_stream_queries,
506+
};
507+
let first_config = RocksDbStoreConfig {
508+
inner_config,
509+
storage_cache_config: options.storage_cache_config(),
510+
};
511+
512+
let inner_config = ScyllaDbStoreInternalConfig {
513+
uri: uri.clone(),
514+
max_stream_queries: options.storage_max_stream_queries,
515+
max_concurrent_queries: options.storage_max_concurrent_queries,
516+
replication_factor: options.storage_replication_factor,
517+
};
518+
let second_config = ScyllaDbStoreConfig {
519+
inner_config,
520+
storage_cache_config: options.storage_cache_config(),
521+
};
522+
489523
let config = DualStoreConfig {
490524
first_config,
491525
second_config,
@@ -578,9 +612,8 @@ impl StoreConfig {
578612
namespace,
579613
genesis_path,
580614
} => {
581-
let store_config = MemoryStoreConfig::new(config.common_config.max_stream_queries);
582615
let mut storage = DbStorage::<MemoryStore, _>::maybe_create_and_connect(
583-
&store_config,
616+
&config,
584617
&namespace,
585618
wasm_runtime,
586619
)

linera-storage-service/src/client.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ use linera_views::store::TestKeyValueStore;
1919
use linera_views::{
2020
batch::{Batch, WriteOperation},
2121
lru_caching::LruCachingStore,
22-
store::{
23-
AdminKeyValueStore, CommonStoreInternalConfig, ReadableKeyValueStore, WithError,
24-
WritableKeyValueStore,
25-
},
22+
store::{AdminKeyValueStore, ReadableKeyValueStore, WithError, WritableKeyValueStore},
2623
FutureSyncExt,
2724
};
2825
use serde::de::DeserializeOwned;
@@ -430,11 +427,10 @@ impl AdminKeyValueStore for ServiceStoreClientInternal {
430427

431428
async fn connect(config: &Self::Config, namespace: &str) -> Result<Self, ServiceStoreError> {
432429
let semaphore = config
433-
.common_config
434430
.max_concurrent_queries
435431
.map(|n| Arc::new(Semaphore::new(n)));
436432
let namespace = bcs::to_bytes(namespace)?;
437-
let max_stream_queries = config.common_config.max_stream_queries;
433+
let max_stream_queries = config.max_stream_queries;
438434
let mut start_key = vec![KeyPrefix::Key as u8];
439435
start_key.extend(&namespace);
440436
let prefix_len = namespace.len() + 1;
@@ -557,15 +553,10 @@ impl TestKeyValueStore for ServiceStoreClientInternal {
557553
pub fn service_config_from_endpoint(
558554
endpoint: &str,
559555
) -> Result<ServiceStoreInternalConfig, ServiceStoreError> {
560-
let common_config = CommonStoreInternalConfig {
556+
Ok(ServiceStoreInternalConfig {
557+
endpoint: endpoint.to_string(),
561558
max_concurrent_queries: None,
562559
max_stream_queries: 100,
563-
replication_factor: 1,
564-
};
565-
let endpoint = endpoint.to_string();
566-
Ok(ServiceStoreInternalConfig {
567-
endpoint,
568-
common_config,
569560
})
570561
}
571562

linera-storage-service/src/common.rs

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

66
use linera_base::command::resolve_binary;
7-
use linera_views::{
8-
lru_caching::LruCachingConfig,
9-
store::{CommonStoreInternalConfig, KeyValueStoreError},
10-
};
7+
use linera_views::{lru_caching::LruCachingConfig, store::KeyValueStoreError};
118
use serde::{Deserialize, Serialize};
129
use thiserror::Error;
1310
use tonic::Status;
@@ -85,8 +82,10 @@ pub fn storage_service_test_endpoint() -> Result<String, ServiceStoreError> {
8582
pub struct ServiceStoreInternalConfig {
8683
/// The endpoint used by the shared store
8784
pub endpoint: String,
88-
/// The common configuration code
89-
pub common_config: CommonStoreInternalConfig,
85+
/// Maximum number of concurrent database queries allowed for this client.
86+
pub max_concurrent_queries: Option<usize>,
87+
/// Preferred buffer size for async streams.
88+
pub max_stream_queries: usize,
9089
}
9190

9291
/// The config type

0 commit comments

Comments
 (0)