Make it possible to disable RocksDB completely (#11537)

* Make it possible to disable RocksDB completely

* Make ParityDB non-optional

* Address review comments
This commit is contained in:
Nazar Mokrynskyi
2022-06-14 19:55:56 +03:00
committed by GitHub
parent 06cf8ad076
commit f9ea8b8d0f
11 changed files with 59 additions and 60 deletions
+11 -7
View File
@@ -30,15 +30,13 @@
pub mod offchain;
#[cfg(any(feature = "with-kvdb-rocksdb", test))]
pub mod bench;
mod children;
#[cfg(feature = "with-parity-db")]
mod parity_db;
mod stats;
mod storage_cache;
#[cfg(any(feature = "with-kvdb-rocksdb", test))]
#[cfg(any(feature = "rocksdb", test))]
mod upgrade;
mod utils;
@@ -94,7 +92,6 @@ use sp_trie::{prefixed_key, MemoryDB, PrefixedMemoryDB};
pub use sc_state_db::PruningMode;
pub use sp_database::Database;
#[cfg(any(feature = "with-kvdb-rocksdb", test))]
pub use bench::BenchmarkingState;
const CACHE_HEADERS: usize = 8;
@@ -106,7 +103,6 @@ const DEFAULT_CHILD_RATIO: (usize, usize) = (1, 10);
pub type DbState<B> =
sp_state_machine::TrieBackend<Arc<dyn sp_state_machine::Storage<HashFor<B>>>, HashFor<B>>;
#[cfg(feature = "with-parity-db")]
/// Length of a [`DbHash`].
const DB_HASH_LEN: usize = 32;
@@ -330,6 +326,7 @@ pub enum DatabaseSource {
cache_size: usize,
},
/// Load a RocksDB database from a given path. Recommended for most uses.
#[cfg(feature = "rocksdb")]
RocksDb {
/// Path to the database.
path: PathBuf,
@@ -362,7 +359,9 @@ impl DatabaseSource {
// IIUC this is needed for polkadot to create its own dbs, so until it can use parity db
// I would think rocksdb, but later parity-db.
DatabaseSource::Auto { paritydb_path, .. } => Some(paritydb_path),
DatabaseSource::RocksDb { path, .. } | DatabaseSource::ParityDb { path } => Some(path),
#[cfg(feature = "rocksdb")]
DatabaseSource::RocksDb { path, .. } => Some(path),
DatabaseSource::ParityDb { path } => Some(path),
DatabaseSource::Custom { .. } => None,
}
}
@@ -374,7 +373,11 @@ impl DatabaseSource {
*paritydb_path = p.into();
true
},
DatabaseSource::RocksDb { ref mut path, .. } |
#[cfg(feature = "rocksdb")]
DatabaseSource::RocksDb { ref mut path, .. } => {
*path = p.into();
true
},
DatabaseSource::ParityDb { ref mut path } => {
*path = p.into();
true
@@ -388,6 +391,7 @@ impl std::fmt::Display for DatabaseSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self {
DatabaseSource::Auto { .. } => "Auto",
#[cfg(feature = "rocksdb")]
DatabaseSource::RocksDb { .. } => "RocksDb",
DatabaseSource::ParityDb { .. } => "ParityDb",
DatabaseSource::Custom { .. } => "Custom",