mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
New database trait (#5549)
* Introduce trait * The trait * Generic * Basic impls. * Remove unneeded bounds * Minor changes * Switch over to the new DB trait * Integrated parity-db and added CLI for db selection * Default impl. * Fix logs. * Started integrating subdb * Apply suggestions from code review Co-Authored-By: Cecile Tonglet <cecile@parity.io> * Apply suggestions from code review Co-Authored-By: Nikolay Volf <nikvolf@gmail.com> * Enable subdb * Bump parity-db * Fixed CLI macro * Fixed browser build * Fixed features * Sort out features * Use parity-db from crates.io * Typo Co-authored-by: arkpar <arkady.paronyan@gmail.com> Co-authored-by: Cecile Tonglet <cecile@parity.io> Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
@@ -122,6 +122,20 @@ impl ExecutionStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
/// Database backend
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Database {
|
||||
// Facebooks RocksDB
|
||||
RocksDb,
|
||||
// Subdb. https://github.com/paritytech/subdb/
|
||||
SubDb,
|
||||
// ParityDb. https://github.com/paritytech/parity-db/
|
||||
ParityDb,
|
||||
}
|
||||
}
|
||||
|
||||
/// Default value for the `--execution-syncing` parameter.
|
||||
pub const DEFAULT_EXECUTION_SYNCING: ExecutionStrategy = ExecutionStrategy::NativeElseWasm;
|
||||
/// Default value for the `--execution-import-block` parameter.
|
||||
|
||||
@@ -74,7 +74,7 @@ impl ExportBlocksCmd {
|
||||
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
|
||||
<BB as BlockT>::Hash: std::str::FromStr,
|
||||
{
|
||||
if let DatabaseConfig::Path { ref path, .. } = &config.database {
|
||||
if let DatabaseConfig::RocksDb { ref path, .. } = &config.database {
|
||||
info!("DB path: {}", path.display());
|
||||
}
|
||||
|
||||
|
||||
@@ -204,9 +204,16 @@ macro_rules! substrate_cli_subcommands {
|
||||
&self,
|
||||
base_path: &::std::path::PathBuf,
|
||||
cache_size: usize,
|
||||
database: $crate::Database,
|
||||
) -> $crate::Result<::sc_service::config::DatabaseConfig> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.database_config(base_path, cache_size)),*
|
||||
$($enum::$variant(cmd) => cmd.database_config(base_path, cache_size, database)),*
|
||||
}
|
||||
}
|
||||
|
||||
fn database(&self) -> $crate::Result<::std::option::Option<$crate::Database>> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.database()),*
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ impl PurgeChainCmd {
|
||||
/// Run the purge command
|
||||
pub fn run(&self, config: Configuration) -> error::Result<()> {
|
||||
let db_path = match &config.database {
|
||||
DatabaseConfig::Path { path, .. } => path,
|
||||
DatabaseConfig::RocksDb { path, .. } => path,
|
||||
_ => {
|
||||
eprintln!("Cannot purge custom database implementation");
|
||||
return Ok(());
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::{
|
||||
init_logger, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
|
||||
PruningParams, SharedParams, SubstrateCli,
|
||||
};
|
||||
use crate::arg_enums::Database;
|
||||
use app_dirs::{AppDataType, AppInfo};
|
||||
use names::{Generator, Name};
|
||||
use sc_service::config::{
|
||||
@@ -152,11 +153,26 @@ pub trait CliConfiguration: Sized {
|
||||
.unwrap_or(Default::default()))
|
||||
}
|
||||
|
||||
/// Get the database backend variant.
|
||||
///
|
||||
/// By default this is retrieved from `ImportParams` if it is available. Otherwise its `None`.
|
||||
fn database(&self) -> Result<Option<Database>> {
|
||||
Ok(self.import_params().map(|x| x.database()))
|
||||
}
|
||||
|
||||
/// Get the database configuration.
|
||||
///
|
||||
/// By default this is retrieved from `SharedParams`
|
||||
fn database_config(&self, base_path: &PathBuf, cache_size: usize) -> Result<DatabaseConfig> {
|
||||
Ok(self.shared_params().database_config(base_path, cache_size))
|
||||
fn database_config(&self,
|
||||
base_path: &PathBuf,
|
||||
cache_size: usize,
|
||||
database: Database,
|
||||
) -> Result<DatabaseConfig> {
|
||||
Ok(self.shared_params().database_config(
|
||||
base_path,
|
||||
cache_size,
|
||||
database,
|
||||
))
|
||||
}
|
||||
|
||||
/// Get the state cache size.
|
||||
@@ -376,6 +392,7 @@ pub trait CliConfiguration: 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(128);
|
||||
let database = self.database()?.unwrap_or(Database::RocksDb);
|
||||
let node_key = self.node_key(&net_config_dir)?;
|
||||
let role = self.role(is_dev)?;
|
||||
let max_runtime_instances = self.max_runtime_instances()?.unwrap_or(8);
|
||||
@@ -394,7 +411,7 @@ pub trait CliConfiguration: Sized {
|
||||
node_key,
|
||||
)?,
|
||||
keystore: self.keystore_config(&config_dir)?,
|
||||
database: self.database_config(&config_dir, database_cache_size)?,
|
||||
database: self.database_config(&config_dir, database_cache_size, database)?,
|
||||
state_cache_size: self.state_cache_size()?,
|
||||
state_cache_child_ratio: self.state_cache_child_ratio()?,
|
||||
pruning: self.pruning(is_dev, &role)?,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use crate::arg_enums::{
|
||||
ExecutionStrategy, TracingReceiver, WasmExecutionMethod, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION,
|
||||
DEFAULT_EXECUTION_IMPORT_BLOCK, DEFAULT_EXECUTION_OFFCHAIN_WORKER, DEFAULT_EXECUTION_OTHER,
|
||||
DEFAULT_EXECUTION_SYNCING,
|
||||
DEFAULT_EXECUTION_SYNCING, Database,
|
||||
};
|
||||
use crate::params::PruningParams;
|
||||
use crate::Result;
|
||||
@@ -54,6 +54,16 @@ pub struct ImportParams {
|
||||
#[structopt(flatten)]
|
||||
pub execution_strategies: ExecutionStrategiesParams,
|
||||
|
||||
/// Select database backend to use.
|
||||
#[structopt(
|
||||
long = "database",
|
||||
alias = "db",
|
||||
value_name = "DB",
|
||||
case_insensitive = true,
|
||||
default_value = "RocksDb"
|
||||
)]
|
||||
pub database: Database,
|
||||
|
||||
/// Limit the memory the database cache can use.
|
||||
#[structopt(long = "db-cache", value_name = "MiB")]
|
||||
pub database_cache_size: Option<usize>,
|
||||
@@ -132,6 +142,11 @@ impl ImportParams {
|
||||
pub fn database_cache_size(&self) -> Option<usize> {
|
||||
self.database_cache_size
|
||||
}
|
||||
|
||||
/// Limit the memory the database cache can use.
|
||||
pub fn database(&self) -> Database {
|
||||
self.database
|
||||
}
|
||||
}
|
||||
|
||||
/// Execution strategies parameters.
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
use sc_service::config::DatabaseConfig;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// default sub directory to store database
|
||||
const DEFAULT_DB_CONFIG_PATH: &'static str = "db";
|
||||
use crate::arg_enums::Database;
|
||||
|
||||
/// Shared parameters used by all `CoreParams`.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
@@ -79,10 +77,19 @@ impl SharedParams {
|
||||
&self,
|
||||
base_path: &PathBuf,
|
||||
cache_size: usize,
|
||||
database: Database,
|
||||
) -> DatabaseConfig {
|
||||
DatabaseConfig::Path {
|
||||
path: base_path.join(DEFAULT_DB_CONFIG_PATH),
|
||||
cache_size,
|
||||
match database {
|
||||
Database::RocksDb => DatabaseConfig::RocksDb {
|
||||
path: base_path.join("db"),
|
||||
cache_size,
|
||||
},
|
||||
Database::SubDb => DatabaseConfig::SubDb {
|
||||
path: base_path.join("subdb"),
|
||||
},
|
||||
Database::ParityDb => DatabaseConfig::ParityDb {
|
||||
path: base_path.join("paritydb"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user