linera_storage_runtime/
common_options.rs

1// Copyright (c) Zefchain Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use linera_storage::{StorageCacheConfig, DEFAULT_CLEANUP_INTERVAL_SECS};
5use linera_views::lru_prefix_cache::StorageCacheConfig as ViewsStorageCacheConfig;
6
7#[derive(Clone, Debug, clap::Parser)]
8pub struct CommonStorageOptions {
9    /// The maximal number of simultaneous queries to the database
10    #[arg(long, global = true)]
11    pub storage_max_concurrent_queries: Option<usize>,
12
13    /// The maximal number of simultaneous stream queries to the database
14    #[arg(long, default_value = "10", global = true)]
15    pub storage_max_stream_queries: usize,
16
17    /// The maximal memory used in the storage cache.
18    #[arg(long, default_value = "10000000", global = true)]
19    pub storage_max_cache_size: usize,
20
21    /// The maximal size of a value entry in the storage cache.
22    #[arg(long, default_value = "1000000", global = true)]
23    pub storage_max_value_entry_size: usize,
24
25    /// The maximal size of a find-keys entry in the storage cache.
26    #[arg(long, default_value = "1000000", global = true)]
27    pub storage_max_find_keys_entry_size: usize,
28
29    /// The maximal size of a find-key-values entry in the storage cache.
30    #[arg(long, default_value = "1000000", global = true)]
31    pub storage_max_find_key_values_entry_size: usize,
32
33    /// The maximal number of entries in the storage cache.
34    #[arg(long, default_value = "1000", global = true)]
35    pub storage_max_cache_entries: usize,
36
37    /// The maximal memory used in the value cache.
38    #[arg(long, default_value = "10000000", global = true)]
39    pub storage_max_cache_value_size: usize,
40
41    /// The maximal memory used in the find_keys_by_prefix cache.
42    #[arg(long, default_value = "10000000", global = true)]
43    pub storage_max_cache_find_keys_size: usize,
44
45    /// The maximal memory used in the find_key_values_by_prefix cache.
46    #[arg(long, default_value = "10000000", global = true)]
47    pub storage_max_cache_find_key_values_size: usize,
48
49    /// The maximal number of entries in the blob cache.
50    #[arg(long, default_value = "1000", global = true)]
51    pub blob_cache_size: usize,
52
53    /// The maximal number of entries in the confirmed block cache.
54    #[arg(long, default_value = "1000", global = true)]
55    pub confirmed_block_cache_size: usize,
56
57    /// The maximal number of entries in the assembled certificate cache.
58    #[arg(long, default_value = "1000", global = true)]
59    pub certificate_cache_size: usize,
60
61    /// The maximal number of entries in the raw certificate cache.
62    #[arg(long, default_value = "1000", global = true)]
63    pub certificate_raw_cache_size: usize,
64
65    /// The maximal number of entries in the event cache.
66    #[arg(long, default_value = "1000", global = true)]
67    pub event_cache_size: usize,
68
69    /// Interval in seconds between weak reference cleanup sweeps in value caches.
70    #[arg(long, default_value_t = DEFAULT_CLEANUP_INTERVAL_SECS, global = true)]
71    pub cache_cleanup_interval_secs: u64,
72
73    /// The replication factor for the keyspace
74    #[arg(long, default_value = "1", global = true)]
75    pub storage_replication_factor: u32,
76}
77
78impl CommonStorageOptions {
79    pub fn with_defaults() -> Self {
80        use clap::Parser as _;
81        Self::parse_from(std::iter::empty::<String>())
82    }
83
84    pub fn storage_cache_config(&self) -> StorageCacheConfig {
85        StorageCacheConfig {
86            blob_cache_size: self.blob_cache_size,
87            confirmed_block_cache_size: self.confirmed_block_cache_size,
88            certificate_cache_size: self.certificate_cache_size,
89            certificate_raw_cache_size: self.certificate_raw_cache_size,
90            event_cache_size: self.event_cache_size,
91            cache_cleanup_interval_secs: self.cache_cleanup_interval_secs,
92        }
93    }
94
95    pub fn views_storage_cache_config(&self) -> ViewsStorageCacheConfig {
96        ViewsStorageCacheConfig {
97            max_cache_size: self.storage_max_cache_size,
98            max_value_entry_size: self.storage_max_value_entry_size,
99            max_find_keys_entry_size: self.storage_max_find_keys_entry_size,
100            max_find_key_values_entry_size: self.storage_max_find_key_values_entry_size,
101            max_cache_entries: self.storage_max_cache_entries,
102            max_cache_value_size: self.storage_max_cache_value_size,
103            max_cache_find_keys_size: self.storage_max_cache_find_keys_size,
104            max_cache_find_key_values_size: self.storage_max_cache_find_key_values_size,
105        }
106    }
107}