Skip to content

Commit

Permalink
Extend the cache support.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik committed Nov 17, 2024
1 parent 92115c7 commit f74f349
Show file tree
Hide file tree
Showing 22 changed files with 1,049 additions and 194 deletions.
4 changes: 1 addition & 3 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ A Byzantine-fault tolerant sidechain with low-latency finality and high throughp
* `--max-stream-queries <MAX_STREAM_QUERIES>` — The maximal number of simultaneous stream queries to the database

Default value: `10`
* `--cache-size <CACHE_SIZE>` — The maximal number of entries in the storage cache

Default value: `1000`
* `--storage-cache-policy <STORAGE_CACHE_POLICY>` — The storage cache policy
* `--retry-delay-ms <RETRY_DELAY>` — Delay increment for retrying to connect to a validator

Default value: `1000`
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions linera-client/src/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use linera_core::client::BlanketMessagePolicy;
use linera_execution::{
committee::ValidatorName, ResourceControlPolicy, WasmRuntime, WithWasmDefault as _,
};
use linera_views::store::CommonStoreConfig;
use linera_views::{lru_caching::read_storage_cache_policy, store::CommonStoreConfig};

#[cfg(feature = "fs")]
use crate::config::GenesisConfig;
Expand Down Expand Up @@ -114,9 +114,9 @@ pub struct ClientOptions {
#[arg(long, default_value = "10")]
pub max_stream_queries: usize,

/// The maximal number of entries in the storage cache.
#[arg(long, default_value = "1000")]
pub cache_size: usize,
/// The storage cache policy
#[arg(long)]
pub storage_cache_policy: Option<String>,

/// Subcommand.
#[command(subcommand)]
Expand Down Expand Up @@ -177,10 +177,11 @@ impl ClientOptions {
}

fn common_config(&self) -> CommonStoreConfig {
let storage_cache_policy = read_storage_cache_policy(self.storage_cache_policy.clone());
CommonStoreConfig {
max_concurrent_queries: self.max_concurrent_queries,
max_stream_queries: self.max_stream_queries,
cache_size: self.cache_size,
storage_cache_policy,
}
}

Expand Down
9 changes: 6 additions & 3 deletions linera-indexer/lib/src/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use linera_views::{
RocksDbStoreInternalConfig,
},

Check warning on line 11 in linera-indexer/lib/src/rocks_db.rs

View workflow job for this annotation

GitHub Actions / lint-cargo-fmt

Diff in /home/runner/work/linera-protocol/linera-protocol/linera-indexer/lib/src/rocks_db.rs
store::{AdminKeyValueStore, CommonStoreInternalConfig},
lru_caching::read_storage_cache_policy,
};

use crate::{
Expand All @@ -31,9 +32,9 @@ pub struct RocksDbConfig {
/// The maximal number of simultaneous stream queries to the database
#[arg(long, default_value = "10")]
pub max_stream_queries: usize,
/// The maximal number of entries in the storage cache.
#[arg(long, default_value = "1000")]
cache_size: usize,
/// The file of the storage cache policy
#[arg(long)]
storage_cache_policy: Option<String>,
}

pub type RocksDbRunner = Runner<RocksDbStore, RocksDbConfig>;
Expand All @@ -45,6 +46,8 @@ impl RocksDbRunner {
max_concurrent_queries: config.client.max_concurrent_queries,
max_stream_queries: config.client.max_stream_queries,
};
let storage_cache_policy =
read_storage_cache_policy(config.client.storage_cache_policy.clone());
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
Expand Down
11 changes: 7 additions & 4 deletions linera-indexer/lib/src/scylla_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

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

use crate::{
Expand All @@ -25,9 +26,9 @@ pub struct ScyllaDbConfig {
/// The maximal number of simultaneous stream queries to the database
#[arg(long, default_value = "10")]
pub max_stream_queries: usize,
/// The maximal number of entries in the storage cache.
#[arg(long, default_value = "1000")]
cache_size: usize,
/// The storage cache policy
#[arg(long)]
storage_cache_policy: Option<String>,
}

pub type ScyllaDbRunner = Runner<ScyllaDbStore, ScyllaDbConfig>;
Expand All @@ -39,6 +40,8 @@ impl ScyllaDbRunner {
max_concurrent_queries: config.client.max_concurrent_queries,
max_stream_queries: config.client.max_stream_queries,
};
let storage_cache_policy =
read_storage_cache_policy(config.client.storage_cache_policy.clone());
let namespace = config.client.table.clone();
let root_key = &[];
let inner_config = ScyllaDbStoreInternalConfig {
Expand Down
11 changes: 6 additions & 5 deletions linera-service/src/proxy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use linera_rpc::{
use linera_service::prometheus_server;
use linera_service::util;
use linera_storage::Storage;
use linera_views::store::CommonStoreConfig;
use linera_views::{lru_caching::read_storage_cache_policy, store::CommonStoreConfig};
use tokio::task::JoinSet;
use tokio_util::sync::CancellationToken;
use tracing::{error, info, instrument};
Expand Down Expand Up @@ -68,9 +68,9 @@ pub struct ProxyOptions {
#[arg(long, default_value = "10")]
max_stream_queries: usize,

/// The maximal number of entries in the storage cache.
#[arg(long, default_value = "1000")]
cache_size: usize,
/// The storage cache policy
#[arg(long)]
storage_cache_policy: Option<String>,

/// Path to the file describing the initial user chains (aka genesis state)
#[arg(long = "genesis")]
Expand Down Expand Up @@ -375,10 +375,11 @@ fn main() -> Result<()> {

impl ProxyOptions {
async fn run(&self) -> Result<()> {
let storage_cache_policy = read_storage_cache_policy(self.storage_cache_policy.clone());
let common_config = CommonStoreConfig {
max_concurrent_queries: self.max_concurrent_queries,
max_stream_queries: self.max_stream_queries,
cache_size: self.cache_size,
storage_cache_policy,
};
let full_storage_config = self.storage_config.add_common_config(common_config).await?;
let genesis_config: GenesisConfig = util::read_json(&self.genesis_config_path)?;
Expand Down
24 changes: 13 additions & 11 deletions linera-service/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use linera_rpc::{
use linera_service::prometheus_server;
use linera_service::util;
use linera_storage::Storage;
use linera_views::store::CommonStoreConfig;
use linera_views::{lru_caching::read_storage_cache_policy, store::CommonStoreConfig};
use serde::Deserialize;
use tokio::task::JoinSet;
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -356,9 +356,9 @@ enum ServerCommand {
#[arg(long, default_value = "10")]
max_stream_queries: usize,

/// The maximal number of entries in the storage cache.
#[arg(long, default_value = "1000")]
cache_size: usize,
/// The storage cache policy
#[arg(long)]
storage_cache_policy: Option<String>,
},

/// Act as a trusted third-party and generate all server configurations
Expand Down Expand Up @@ -397,9 +397,9 @@ enum ServerCommand {
#[arg(long, default_value = "10")]
max_stream_queries: usize,

/// The maximal number of entries in the storage cache.
#[arg(long, default_value = "1000")]
cache_size: usize,
/// The storage cache policy
#[arg(long)]
storage_cache_policy: Option<String>,
},

/// Replaces the configurations of the shards by following the given template.
Expand Down Expand Up @@ -500,7 +500,7 @@ async fn run(options: ServerOptions) {
max_loaded_chains,
max_concurrent_queries,
max_stream_queries,
cache_size,
storage_cache_policy,
} => {
linera_version::VERSION_INFO.log();

Expand All @@ -525,10 +525,11 @@ async fn run(options: ServerOptions) {
max_loaded_chains,
};
let wasm_runtime = wasm_runtime.with_wasm_default();
let storage_cache_policy = read_storage_cache_policy(storage_cache_policy);
let common_config = CommonStoreConfig {
max_concurrent_queries,
max_stream_queries,
cache_size,
storage_cache_policy,
};
let full_storage_config = storage_config
.add_common_config(common_config)
Expand Down Expand Up @@ -584,14 +585,15 @@ async fn run(options: ServerOptions) {
genesis_config_path,
max_concurrent_queries,
max_stream_queries,
cache_size,
storage_cache_policy,
} => {
let genesis_config: GenesisConfig =
util::read_json(&genesis_config_path).expect("Failed to read initial chain config");
let storage_cache_policy = read_storage_cache_policy(storage_cache_policy);
let common_config = CommonStoreConfig {
max_concurrent_queries,
max_stream_queries,
cache_size,
storage_cache_policy,
};
let full_storage_config = storage_config
.add_common_config(common_config)
Expand Down
7 changes: 6 additions & 1 deletion linera-storage-service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use linera_views::metering::MeteredStore;
use linera_views::store::TestKeyValueStore;
use linera_views::{
batch::{Batch, WriteOperation},
lru_caching::LruCachingStore,
lru_caching::{CachingStore, StorageCachePolicy, DEFAULT_STORAGE_CACHE_POLICY},
store::{
AdminKeyValueStore, CommonStoreInternalConfig, ReadableKeyValueStore, WithError,
WritableKeyValueStore,
Expand Down Expand Up @@ -60,6 +60,7 @@ pub struct ServiceStoreClientInternal {
channel: Channel,
semaphore: Option<Arc<Semaphore>>,
max_stream_queries: usize,
storage_cache_policy: StorageCachePolicy,
namespace: Vec<u8>,
start_key: Vec<u8>,
}
Expand Down Expand Up @@ -392,13 +393,15 @@ impl AdminKeyValueStore for ServiceStoreClientInternal {
.max_concurrent_queries
.map(|n| Arc::new(Semaphore::new(n)));
let max_stream_queries = config.common_config.max_stream_queries;
let storage_cache_policy = config.common_config.storage_cache_policy.clone();
let namespace = Self::namespace_as_vec(namespace)?;
let mut start_key = namespace.clone();
start_key.extend(root_key);
Ok(Self {
channel,
semaphore,
max_stream_queries,
storage_cache_policy,
namespace,
start_key,
})
Expand All @@ -408,13 +411,15 @@ impl AdminKeyValueStore for ServiceStoreClientInternal {
let channel = self.channel.clone();
let semaphore = self.semaphore.clone();
let max_stream_queries = self.max_stream_queries;
let storage_cache_policy = self.storage_cache_policy.clone();
let namespace = self.namespace.clone();
let mut start_key = namespace.clone();
start_key.extend(root_key);
Ok(Self {
channel,
semaphore,
max_stream_queries,
storage_cache_policy,
namespace,
start_key,
})
Expand Down
4 changes: 4 additions & 0 deletions linera-storage-service/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
use std::path::PathBuf;

use linera_base::command::resolve_binary;
#[cfg(with_testing)]
use linera_views::lru_caching::DEFAULT_STORAGE_CACHE_POLICY;
#[cfg(with_metrics)]
use linera_views::metering::KeyValueStoreMetrics;
use linera_views::{
lru_caching::LruSplittingConfig,
store::{CommonStoreInternalConfig, KeyValueStoreError},
Expand Down
1 change: 1 addition & 0 deletions linera-views/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ rand = { workspace = true, features = ["small_rng"] }
rocksdb = { workspace = true, optional = true }
scylla = { workspace = true, optional = true }
serde.workspace = true
serde_json.workspace = true
sha3.workspace = true
static_assertions.workspace = true
tempfile.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion linera-views/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ We provide an implementation of the trait `KeyValueStore` for the following key-
The trait `KeyValueStore` was designed so that more storage solutions can be easily added in the future.

The `KeyValueStore` trait is also implemented for several internal constructions of clients:
* The `LruCachingStore<K>` client implements the Least Recently Used (LRU)
* The `CachingStore<K>` client implements the Least Recently Used (LRU)
caching of reads into the client.
* The `ViewContainer<C>` client implements a key-value store client from a context.
* The `ValueSplittingStore<K>` implements a client for which the
Expand Down
5 changes: 4 additions & 1 deletion linera-views/src/backends/dynamo_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ use crate::store::TestKeyValueStore;
use crate::{
batch::SimpleUnorderedBatch,
journaling::{DirectWritableKeyValueStore, JournalConsistencyError, JournalingKeyValueStore},
lru_caching::{LruCachingStore, LruSplittingConfig},
lru_caching::{LruCachingStore, LruSplittingConfig, StorageCachePolicy},

Check failure on line 45 in linera-views/src/backends/dynamo_db.rs

View workflow job for this annotation

GitHub Actions / lint-cargo-doc

unresolved imports `crate::lru_caching::LruCachingStore`, `crate::lru_caching::LruSplittingConfig`

Check failure on line 45 in linera-views/src/backends/dynamo_db.rs

View workflow job for this annotation

GitHub Actions / lint-cargo-clippy

unresolved imports `crate::lru_caching::LruCachingStore`, `crate::lru_caching::LruSplittingConfig`
store::{
AdminKeyValueStore, CommonStoreInternalConfig, KeyIterable, KeyValueIterable,
KeyValueStoreError, ReadableKeyValueStore, WithError,
},

Check warning on line 49 in linera-views/src/backends/dynamo_db.rs

View workflow job for this annotation

GitHub Actions / lint-cargo-fmt

Diff in /home/runner/work/linera-protocol/linera-protocol/linera-views/src/backends/dynamo_db.rs
value_splitting::{ValueSplittingError, ValueSplittingStore},
};

#[cfg(with_testing)]
use crate::{lru_caching::DEFAULT_STORAGE_CACHE_POLICY, store::TestKeyValueStore};

Check failure on line 54 in linera-views/src/backends/dynamo_db.rs

View workflow job for this annotation

GitHub Actions / lint-cargo-doc

the name `TestKeyValueStore` is defined multiple times

Check failure on line 54 in linera-views/src/backends/dynamo_db.rs

View workflow job for this annotation

GitHub Actions / lint-cargo-clippy

the name `TestKeyValueStore` is defined multiple times

/// Name of the environment variable with the address to a LocalStack instance.
const LOCALSTACK_ENDPOINT: &str = "LOCALSTACK_ENDPOINT";

Expand Down
3 changes: 2 additions & 1 deletion linera-views/src/backends/indexed_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use thiserror::Error;
use crate::{
batch::{Batch, WriteOperation},
common::get_upper_bound_option,
lru_caching::DEFAULT_STORAGE_CACHE_POLICY,
store::{
CommonStoreConfig, KeyValueStoreError, LocalAdminKeyValueStore, LocalReadableKeyValueStore,
LocalWritableKeyValueStore, WithError,
Expand All @@ -31,7 +32,7 @@ impl IndexedDbStoreConfig {
let common_config = CommonStoreConfig {
max_concurrent_queries: None,
max_stream_queries,
cache_size: 1000,
storage_cache_policy: DEFAULT_STORAGE_CACHE_POLICY,
};
Self { common_config }
}
Expand Down
Loading

0 comments on commit f74f349

Please sign in to comment.