mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
Make RocksDB optional in client-db (#2686)
This commit is contained in:
committed by
André Silva
parent
902c9d03f2
commit
3a0c52f2b1
@@ -9,8 +9,8 @@ parking_lot = "0.7.1"
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
|
kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
|
||||||
# FIXME replace with release as soon as our rocksdb changes are released upstream https://github.com/paritytech/parity-common/issues/88
|
# FIXME replace with release as soon as our rocksdb changes are released upstream https://github.com/paritytech/parity-common/issues/88
|
||||||
kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
|
kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d", optional = true }
|
||||||
kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d", optional = true }
|
kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
|
||||||
lru-cache = "0.1.1"
|
lru-cache = "0.1.1"
|
||||||
hash-db = { version = "0.12" }
|
hash-db = { version = "0.12" }
|
||||||
primitives = { package = "substrate-primitives", path = "../../primitives" }
|
primitives = { package = "substrate-primitives", path = "../../primitives" }
|
||||||
@@ -24,11 +24,10 @@ trie = { package = "substrate-trie", path = "../../trie" }
|
|||||||
consensus_common = { package = "substrate-consensus-common", path = "../../consensus/common" }
|
consensus_common = { package = "substrate-consensus-common", path = "../../consensus/common" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
|
|
||||||
substrate-keyring = { path = "../../keyring" }
|
substrate-keyring = { path = "../../keyring" }
|
||||||
test-client = { package = "substrate-test-client", path = "../../test-client" }
|
test-client = { package = "substrate-test-client", path = "../../test-client" }
|
||||||
env_logger = { version = "0.6" }
|
env_logger = { version = "0.6" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
test-helpers = ["kvdb-memorydb"]
|
test-helpers = []
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ use runtime_primitives::BuildStorage;
|
|||||||
use state_machine::backend::Backend as StateBackend;
|
use state_machine::backend::Backend as StateBackend;
|
||||||
use executor::RuntimeInfo;
|
use executor::RuntimeInfo;
|
||||||
use state_machine::{CodeExecutor, DBValue};
|
use state_machine::{CodeExecutor, DBValue};
|
||||||
use crate::utils::{Meta, db_err, meta_keys, open_database, read_db, block_id_to_lookup_key, read_meta};
|
use crate::utils::{Meta, db_err, meta_keys, read_db, block_id_to_lookup_key, read_meta};
|
||||||
use client::leaves::{LeafSet, FinalizationDisplaced};
|
use client::leaves::{LeafSet, FinalizationDisplaced};
|
||||||
use client::children;
|
use client::children;
|
||||||
use state_db::StateDb;
|
use state_db::StateDb;
|
||||||
@@ -572,8 +572,19 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
|
|||||||
///
|
///
|
||||||
/// The pruning window is how old a block must be before the state is pruned.
|
/// The pruning window is how old a block must be before the state is pruned.
|
||||||
pub fn new(config: DatabaseSettings, canonicalization_delay: u64) -> Result<Self, client::error::Error> {
|
pub fn new(config: DatabaseSettings, canonicalization_delay: u64) -> Result<Self, client::error::Error> {
|
||||||
let db = open_database(&config, columns::META, "full")?;
|
Self::new_inner(config, canonicalization_delay)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "kvdb-rocksdb")]
|
||||||
|
fn new_inner(config: DatabaseSettings, canonicalization_delay: u64) -> Result<Self, client::error::Error> {
|
||||||
|
let db = crate::utils::open_database(&config, columns::META, "full")?;
|
||||||
|
Backend::from_kvdb(db as Arc<_>, config.pruning, canonicalization_delay, config.state_cache_size)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "kvdb-rocksdb"))]
|
||||||
|
fn new_inner(config: DatabaseSettings, canonicalization_delay: u64) -> Result<Self, client::error::Error> {
|
||||||
|
log::warn!("Running without the RocksDB feature. The database will NOT be saved.");
|
||||||
|
let db = Arc::new(kvdb_memorydb::create(crate::utils::NUM_COLUMNS));
|
||||||
Backend::from_kvdb(db as Arc<_>, config.pruning, canonicalization_delay, config.state_cache_size)
|
Backend::from_kvdb(db as Arc<_>, config.pruning, canonicalization_delay, config.state_cache_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ use runtime_primitives::traits::{
|
|||||||
};
|
};
|
||||||
use consensus_common::well_known_cache_keys;
|
use consensus_common::well_known_cache_keys;
|
||||||
use crate::cache::{DbCacheSync, DbCache, ComplexBlockId, EntryType as CacheEntryType};
|
use crate::cache::{DbCacheSync, DbCache, ComplexBlockId, EntryType as CacheEntryType};
|
||||||
use crate::utils::{self, meta_keys, Meta, db_err, open_database,
|
use crate::utils::{self, meta_keys, Meta, db_err, read_db, block_id_to_lookup_key, read_meta};
|
||||||
read_db, block_id_to_lookup_key, read_meta};
|
|
||||||
use crate::DatabaseSettings;
|
use crate::DatabaseSettings;
|
||||||
use log::{trace, warn, debug};
|
use log::{trace, warn, debug};
|
||||||
|
|
||||||
@@ -72,8 +71,19 @@ impl<Block> LightStorage<Block>
|
|||||||
{
|
{
|
||||||
/// Create new storage with given settings.
|
/// Create new storage with given settings.
|
||||||
pub fn new(config: DatabaseSettings) -> ClientResult<Self> {
|
pub fn new(config: DatabaseSettings) -> ClientResult<Self> {
|
||||||
let db = open_database(&config, columns::META, "light")?;
|
Self::new_inner(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "kvdb-rocksdb")]
|
||||||
|
fn new_inner(config: DatabaseSettings) -> ClientResult<Self> {
|
||||||
|
let db = crate::utils::open_database(&config, columns::META, "light")?;
|
||||||
|
Self::from_kvdb(db as Arc<_>)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "kvdb-rocksdb"))]
|
||||||
|
fn new_inner(_config: DatabaseSettings) -> ClientResult<Self> {
|
||||||
|
log::warn!("Running without the RocksDB feature. The database will NOT be saved.");
|
||||||
|
let db = Arc::new(kvdb_memorydb::create(crate::utils::NUM_COLUMNS));
|
||||||
Self::from_kvdb(db as Arc<_>)
|
Self::from_kvdb(db as Arc<_>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use std::io;
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use kvdb::{KeyValueDB, DBTransaction};
|
use kvdb::{KeyValueDB, DBTransaction};
|
||||||
|
#[cfg(feature = "kvdb-rocksdb")]
|
||||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
@@ -195,6 +196,7 @@ pub fn db_err(err: io::Error) -> client::error::Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Open RocksDB database.
|
/// Open RocksDB database.
|
||||||
|
#[cfg(feature = "kvdb-rocksdb")]
|
||||||
pub fn open_database(config: &DatabaseSettings, col_meta: Option<u32>, db_type: &str) -> client::error::Result<Arc<KeyValueDB>> {
|
pub fn open_database(config: &DatabaseSettings, col_meta: Option<u32>, db_type: &str) -> client::error::Result<Arc<KeyValueDB>> {
|
||||||
let mut db_config = DatabaseConfig::with_columns(Some(NUM_COLUMNS));
|
let mut db_config = DatabaseConfig::with_columns(Some(NUM_COLUMNS));
|
||||||
db_config.memory_budget = config.cache_size;
|
db_config.memory_budget = config.cache_size;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives"
|
|||||||
consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
|
consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
|
||||||
network = { package = "substrate-network", path = "../../core/network" }
|
network = { package = "substrate-network", path = "../../core/network" }
|
||||||
client = { package = "substrate-client", path = "../../core/client" }
|
client = { package = "substrate-client", path = "../../core/client" }
|
||||||
client_db = { package = "substrate-client-db", path = "../../core/client/db" }
|
client_db = { package = "substrate-client-db", path = "../../core/client/db", features = ["kvdb-rocksdb"] }
|
||||||
parity-codec = "3.3"
|
parity-codec = "3.3"
|
||||||
substrate-executor = { path = "../../core/executor" }
|
substrate-executor = { path = "../../core/executor" }
|
||||||
transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" }
|
transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" }
|
||||||
|
|||||||
Reference in New Issue
Block a user