Skip to content

Commit

Permalink
max_total_wal_size (paritytech#29)
Browse files Browse the repository at this point in the history
* adds static `db_config.max_total_wal_size`, pinned to `40 GB` to match current documentation @ https://github.com/PolymeshAssociation/polymesh-tools/blob/7d8146deb459ffca3de6cd5da270928a529f233c/docs/operator/README.md#node-resource-requirements : `It is recommended that you reserve an additional 40GB of disk space for the WAL.`

* adds cli flag `--db-max-total-wal-size` to allow specifying `db_config.max_total_wal_size`

* adds cli flag `--db-max-total-wal-size` to allow specifying `db_config.max_total_wal_size`

* adds cli flag `--db-max-total-wal-size` to allow specifying `db_config.max_total_wal_size`

Co-authored-by: Quinn Diggity <git@quinn.dev>

Max wal size (paritytech#30)

* Use `Option<u64>` for max_total_wal_size.

Signed-off-by: Robert G. Jakabosky <rjakabosky+neopallium@neoawareness.com>
  • Loading branch information
quinndiggitypolymath authored and Neopallium committed Sep 30, 2024
1 parent 518d106 commit 2cf3399
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion substrate/bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub enum DatabaseType {
impl DatabaseType {
fn into_settings(self, path: PathBuf) -> sc_client_db::DatabaseSource {
match self {
Self::RocksDb => sc_client_db::DatabaseSource::RocksDb { path, cache_size: 512 },
Self::RocksDb => sc_client_db::DatabaseSource::RocksDb { path, cache_size: 512, max_total_wal_size: None },
Self::ParityDb => sc_client_db::DatabaseSource::ParityDb { path },
}
}
Expand Down
15 changes: 12 additions & 3 deletions substrate/client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
Ok(self.database_params().map(|x| x.database_cache_size()).unwrap_or_default())
}

/// Get the database max total wal size.
///
/// By default this is retrieved from `DatabaseParams` if it is available. Otherwise its `None`.
fn database_max_total_wal_size(&self) -> Result<Option<u64>> {
Ok(self.database_params().map(|x| x.database_max_total_wal_size()).unwrap_or_default())
}

/// Get the database backend variant.
///
/// By default this is retrieved from `DatabaseParams` if it is available. Otherwise its `None`.
Expand All @@ -213,14 +220,15 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
&self,
base_path: &PathBuf,
cache_size: usize,
max_total_wal_size: Option<u64>,
database: Database,
) -> Result<DatabaseSource> {
let role_dir = "full";
let rocksdb_path = base_path.join("db").join(role_dir);
let paritydb_path = base_path.join("paritydb").join(role_dir);
Ok(match database {
#[cfg(feature = "rocksdb")]
Database::RocksDb => DatabaseSource::RocksDb { path: rocksdb_path, cache_size },
Database::RocksDb => DatabaseSource::RocksDb { path: rocksdb_path, cache_size, max_total_wal_size },
Database::ParityDb => DatabaseSource::ParityDb { path: paritydb_path },
Database::ParityDbDeprecated => {
eprintln!(
Expand All @@ -229,7 +237,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
);
DatabaseSource::ParityDb { path: paritydb_path }
},
Database::Auto => DatabaseSource::Auto { paritydb_path, rocksdb_path, cache_size },
Database::Auto => DatabaseSource::Auto { paritydb_path, rocksdb_path, cache_size, max_total_wal_size },
})
}

Expand Down Expand Up @@ -451,6 +459,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
let net_config_dir = config_dir.join(DEFAULT_NETWORK_CONFIG_PATH);
let client_id = C::client_id();
let database_cache_size = self.database_cache_size()?.unwrap_or(1024);
let database_max_total_wal_size = self.database_max_total_wal_size()?;
let database = self.database()?.unwrap_or(
#[cfg(feature = "rocksdb")]
{
Expand Down Expand Up @@ -485,7 +494,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
DCV::p2p_listen_port(),
)?,
keystore,
database: self.database_config(&config_dir, database_cache_size, database)?,
database: self.database_config(&config_dir, database_cache_size, database_max_total_wal_size, database)?,
data_path: config_dir,
trie_cache_maximum_size: self.trie_cache_maximum_size()?,
state_pruning: self.state_pruning()?,
Expand Down
9 changes: 9 additions & 0 deletions substrate/client/cli/src/params/database_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub struct DatabaseParams {
/// Limit the memory the database cache can use.
#[arg(long = "db-cache", value_name = "MiB")]
pub database_cache_size: Option<usize>,

/// Limit the total storage capacity that the database can use for WAL files.
#[clap(long = "db-max-total-wal-size", value_name = "MiB")]
pub database_max_total_wal_size: Option<u64>,
}

impl DatabaseParams {
Expand All @@ -41,4 +45,9 @@ impl DatabaseParams {
pub fn database_cache_size(&self) -> Option<usize> {
self.database_cache_size
}

/// Limit the total storage capacity that the database can use for WAL files.
pub fn database_max_total_wal_size(&self) -> Option<u64> {
self.database_max_total_wal_size
}
}
4 changes: 4 additions & 0 deletions substrate/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ pub enum DatabaseSource {
rocksdb_path: PathBuf,
/// Cache size in MiB. Used only by `RocksDb` variant of `DatabaseSource`.
cache_size: usize,
/// Max total WAL size in MiB. Used only by `RocksDb` variant of `DatabaseSource`.
max_total_wal_size: Option<u64>,
},
/// Load a RocksDB database from a given path. Recommended for most uses.
#[cfg(feature = "rocksdb")]
Expand All @@ -326,6 +328,8 @@ pub enum DatabaseSource {
path: PathBuf,
/// Cache size in MiB.
cache_size: usize,
/// Max total WAL size in MiB.
max_total_wal_size: Option<u64>,
},

/// Load a ParityDb database from a given path.
Expand Down
11 changes: 7 additions & 4 deletions substrate/client/db/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@ fn open_database_at<Block: BlockT>(
let db: Arc<dyn Database<DbHash>> = match &db_source {
DatabaseSource::ParityDb { path } => open_parity_db::<Block>(path, db_type, create)?,
#[cfg(feature = "rocksdb")]
DatabaseSource::RocksDb { path, cache_size } =>
open_kvdb_rocksdb::<Block>(path, db_type, create, *cache_size)?,
DatabaseSource::RocksDb { path, cache_size, max_total_wal_size } =>
open_kvdb_rocksdb::<Block>(path, db_type, create, *cache_size, *max_total_wal_size)?,
DatabaseSource::Custom { db, require_create_flag } => {
if *require_create_flag && !create {
return Err(OpenDbError::DoesNotExist)
}
db.clone()
},
DatabaseSource::Auto { paritydb_path, rocksdb_path, cache_size } => {
DatabaseSource::Auto { paritydb_path, rocksdb_path, cache_size, max_total_wal_size } => {
// check if rocksdb exists first, if not, open paritydb
match open_kvdb_rocksdb::<Block>(rocksdb_path, db_type, false, *cache_size) {
match open_kvdb_rocksdb::<Block>(rocksdb_path, db_type, false, *cache_size, *max_total_wal_size) {
Ok(db) => db,
Err(OpenDbError::NotEnabled(_)) | Err(OpenDbError::DoesNotExist) =>
open_parity_db::<Block>(paritydb_path, db_type, create)?,
Expand Down Expand Up @@ -299,6 +299,7 @@ fn open_kvdb_rocksdb<Block: BlockT>(
db_type: DatabaseType,
create: bool,
cache_size: usize,
max_total_wal_size: Option<u64>,
) -> OpenDbResult {
// first upgrade database to required version
match crate::upgrade::upgrade_db::<Block>(path, db_type) {
Expand All @@ -311,6 +312,7 @@ fn open_kvdb_rocksdb<Block: BlockT>(
// and now open database assuming that it has the latest version
let mut db_config = kvdb_rocksdb::DatabaseConfig::with_columns(NUM_COLUMNS);
db_config.create_if_missing = create;
db_config.max_total_wal_size = max_total_wal_size.map(|m| m << 20);

let mut memory_budget = std::collections::HashMap::new();
match db_type {
Expand Down Expand Up @@ -349,6 +351,7 @@ fn open_kvdb_rocksdb<Block: BlockT>(
_db_type: DatabaseType,
_create: bool,
_cache_size: usize,
_max_total_wal_size: Option<u64>,
) -> OpenDbResult {
Err(OpenDbError::NotEnabled("with-kvdb-rocksdb"))
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn node_config<
transaction_pool: Default::default(),
network: network_config,
keystore: KeystoreConfig::Path { path: root.join("key"), password: None },
database: DatabaseSource::RocksDb { path: root.join("db"), cache_size: 128 },
database: DatabaseSource::RocksDb { path: root.join("db"), cache_size: 128, max_total_wal_size: None },
trie_cache_maximum_size: Some(16 * 1024 * 1024),
state_pruning: Default::default(),
blocks_pruning: BlocksPruning::KeepFinalized,
Expand Down

0 comments on commit 2cf3399

Please sign in to comment.