Skip to content

Commit

Permalink
Auto keep using rocksdb when it exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheme committed Feb 21, 2022
1 parent 4cb2ade commit cea49b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
26 changes: 19 additions & 7 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,18 +865,30 @@ where
path.parent().ok_or(Error::DatabasePathRequired)?.into(),
crate::parachains_db::CacheSizes::default(),
)?,
DatabaseSource::Auto { paritydb_path, rocksdb_path, .. } =>
if paritydb_path.is_dir() && paritydb_path.exists() {
crate::parachains_db::open_creating_paritydb(
paritydb_path.parent().ok_or(Error::DatabasePathRequired)?.into(),
crate::parachains_db::CacheSizes::default(),
)?
DatabaseSource::Auto { paritydb_path, rocksdb_path, .. } => {
let paritydb_path_parent: std::path::PathBuf =
paritydb_path.parent().ok_or(Error::DatabasePathRequired)?.into();
if paritydb_path_parent.is_dir() && paritydb_path_parent.exists() {
let hybrid_parachains_path =
crate::parachains_db::rocksdb_parachain_path(paritydb_path);
if hybrid_parachains_path.is_dir() && hybrid_parachains_path.exists() {
crate::parachains_db::open_creating_rocksdb(
paritydb_path.clone(),
crate::parachains_db::CacheSizes::default(),
)?
} else {
crate::parachains_db::open_creating_paritydb(
paritydb_path_parent,
crate::parachains_db::CacheSizes::default(),
)?
}
} else {
crate::parachains_db::open_creating_rocksdb(
rocksdb_path.clone(),
crate::parachains_db::CacheSizes::default(),
)?
},
}
},
DatabaseSource::Custom { .. } => {
unimplemented!("No polkadot subsystem db for custom source.");
},
Expand Down
9 changes: 8 additions & 1 deletion node/service/src/parachains_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ pub(crate) fn other_io_error(err: String) -> io::Error {
io::Error::new(io::ErrorKind::Other, err)
}

/// Path to the parachain rocksdb directory.
/// `root` is the rocskdb default directory.
#[cfg(feature = "full-node")]
pub fn rocksdb_parachain_path(root: &PathBuf) -> PathBuf {
root.join("parachains").join("db")
}

/// Open the database on disk, creating it if it doesn't exist.
#[cfg(feature = "full-node")]
pub fn open_creating_rocksdb(
Expand All @@ -92,7 +99,7 @@ pub fn open_creating_rocksdb(
) -> io::Result<Arc<dyn Database>> {
use kvdb_rocksdb::{Database, DatabaseConfig};

let path = root.join("parachains").join("db");
let path = rocksdb_parachain_path(&root);

let mut db_config = DatabaseConfig::with_columns(columns::NUM_COLUMNS);

Expand Down

0 comments on commit cea49b3

Please sign in to comment.