Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

New database trait #5549

Merged
merged 27 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5128437
Introduce trait
gavofyork Apr 6, 2020
67aee75
The trait
gavofyork Apr 6, 2020
901b8de
Generic
gavofyork Apr 6, 2020
4df786f
Basic impls.
gavofyork Apr 6, 2020
0ffa2d7
Remove unneeded bounds
gavofyork Apr 6, 2020
6880b2c
Minor changes
gavofyork Apr 6, 2020
e25020e
Switch over to the new DB trait
arkpar Apr 7, 2020
65a660e
Merge branch 'master' of github.com:paritytech/substrate into gav-db-…
arkpar Apr 7, 2020
ad4b010
Integrated parity-db and added CLI for db selection
arkpar Apr 7, 2020
2f6402c
Default impl.
gavofyork Apr 7, 2020
22eaf93
Merge branch 'gav-db-trait' of github.com:paritytech/substrate into g…
gavofyork Apr 7, 2020
35bc233
Merge remote-tracking branch 'origin/master' into gav-db-trait
gavofyork Apr 8, 2020
49e197e
Fix logs.
gavofyork Apr 8, 2020
2e64815
Started integrating subdb
arkpar Apr 8, 2020
0161486
Apply suggestions from code review
arkpar Apr 9, 2020
14e319a
Apply suggestions from code review
gavofyork Apr 13, 2020
817663e
Enable subdb
gavofyork Apr 13, 2020
f5e2de2
Merge remote-tracking branch 'origin/master' into gav-db-trait
gavofyork Apr 13, 2020
9404815
Bump parity-db
arkpar Apr 13, 2020
8c69d5a
Fixed CLI macro
arkpar Apr 14, 2020
3207558
Fixed browser build
arkpar Apr 14, 2020
1b8ffb9
Fixed features
arkpar Apr 14, 2020
262819e
Merge branch 'master' of github.com:paritytech/substrate into gav-db-…
arkpar Apr 15, 2020
beccecf
Sort out features
arkpar Apr 15, 2020
6e69a80
Merge branch 'master' of github.com:paritytech/substrate into gav-db-…
arkpar Apr 15, 2020
e22f4d1
Use parity-db from crates.io
arkpar Apr 15, 2020
16c813a
Typo
arkpar Apr 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ members = [
"primitives/consensus/vrf",
"primitives/core",
"primitives/chain-spec",
"primitives/database",
"primitives/debug-derive",
"primitives/storage",
"primitives/externalities",
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ cli = [
"node-transaction-factory",
"sc-cli",
"frame-benchmarking-cli",
"sc-service/rocksdb",
"sc-service/db",
"structopt",
"substrate-build-script-utils",
]
Expand Down
4 changes: 2 additions & 2 deletions bin/node/testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
pallet-balances = { version = "2.0.0-dev", path = "../../../frame/balances" }
sc-client = { version = "0.8.0-dev", path = "../../../client/" }
sc-client-db = { version = "0.8.0-dev", path = "../../../client/db/", features = ["kvdb-rocksdb"] }
sc-client-db = { version = "0.8.0-dev", path = "../../../client/db/", features = ["kvdb-rocksdb", "parity-db"] }
sc-client-api = { version = "2.0.0-dev", path = "../../../client/api/" }
codec = { package = "parity-scale-codec", version = "1.3.0" }
pallet-contracts = { version = "2.0.0-dev", path = "../../../frame/contracts" }
Expand Down Expand Up @@ -54,4 +54,4 @@ fs_extra = "1"
[dev-dependencies]
criterion = "0.3.0"
sc-cli = { version = "0.8.0-dev", path = "../../../client/cli" }
sc-service = { version = "0.8.0-dev", path = "../../../client/service", features = ["rocksdb"] }
sc-service = { version = "0.8.0-dev", path = "../../../client/service", features = ["db"] }
2 changes: 1 addition & 1 deletion bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl BenchDb {
state_cache_size: 16*1024*1024,
state_cache_child_ratio: Some((0, 100)),
pruning: PruningMode::ArchiveAll,
source: sc_client_db::DatabaseSettingsSrc::Path {
source: sc_client_db::DatabaseSettingsSrc::RocksDb {
path: dir.into(),
cache_size: 512,
},
Expand Down
1 change: 1 addition & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sp-blockchain = { version = "2.0.0-dev", path = "../primitives/blockchain" }
sp-state-machine = { version = "0.8.0-dev", path = "../primitives/state-machine" }
sc-telemetry = { version = "2.0.0-dev", path = "telemetry" }
sp-trie = { version = "2.0.0-dev", path = "../primitives/trie" }
sp-database = { version = "2.0.0-dev", path = "../primitives/database" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.8.0-dev", path = "../utils/prometheus" }
tracing = "0.1.10"

Expand Down
14 changes: 14 additions & 0 deletions client/cli/src/arg_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/commands/export_blocks_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
9 changes: 8 additions & 1 deletion client/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),*
}
}

arkpar marked this conversation as resolved.
Show resolved Hide resolved
fn database(&self) -> $crate::Result<::std::option::Option<$crate::Database>> {
match self {
$($enum::$variant(cmd) => cmd.database()),*
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/commands/purge_chain_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down
23 changes: 20 additions & 3 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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)?,
Expand Down
17 changes: 16 additions & 1 deletion client/cli/src/params/import_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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.
Expand Down
Loading