paritydb support for parachains db. (#4838)

* parity db subsystem without cache and no splitted column

* fmt

* fix path (auto from parity-db fail)

* lru cache for db column with cache

* Revert "lru cache for db column with cache"

This reverts commit ae177bc5e107a075eff6a21f651218ada6599b74.

* Write_lock mutex

* theoric code for bridges

* revert changes

* Revert bridge changes

* fix spec_version

* update parity db

* test purge-db

* Use specific ordered collection with paritydb.

* Revert "Use specific ordered collection with paritydb."

This reverts commit 8b66d0a4ae914cba1af0f44050d45dd6d9327c6b.

* fix chain selection tests.

* remove patch

* fix auto.

* Remove useless exists directory method

* purge chain without parity-db removal

* spellcheck

* renamings and filtering.

* fix assertion

* format

* update parity-db and fmt

* Auto keep using rocksdb when it exists.

* Revert "Auto keep using rocksdb when it exists."

This reverts commit cea49b32ae590bdce31fed5c45f3c028ae0c7564.

* Update kvdb version.
This commit is contained in:
cheme
2022-03-03 12:49:38 +01:00
committed by GitHub
parent eaa96a27a3
commit d5ddb1a809
22 changed files with 591 additions and 85 deletions
+25 -4
View File
@@ -856,10 +856,31 @@ where
);
}
let parachains_db = crate::parachains_db::open_creating(
config.database.path().ok_or(Error::DatabasePathRequired)?.into(),
crate::parachains_db::CacheSizes::default(),
)?;
let parachains_db = match &config.database {
DatabaseSource::RocksDb { path, .. } => crate::parachains_db::open_creating_rocksdb(
path.clone(),
crate::parachains_db::CacheSizes::default(),
)?,
DatabaseSource::ParityDb { path, .. } => crate::parachains_db::open_creating_paritydb(
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(),
)?
} 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.");
},
};
let availability_config = AvailabilityConfig {
col_data: crate::parachains_db::REAL_COLUMNS.col_availability_data,
+1 -1
View File
@@ -79,7 +79,7 @@ where
/// Runtime client generic, providing the `ProvieRuntimeApi` trait besides others.
pub runtime_client: Arc<RuntimeClient>,
/// The underlying key value store for the parachains.
pub parachains_db: Arc<dyn kvdb::KeyValueDB>,
pub parachains_db: Arc<dyn polkadot_node_subsystem_util::database::Database>,
/// Underlying network service implementation.
pub network_service: Arc<sc_network::NetworkService<Block, Hash>>,
/// Underlying authority discovery service.
+38 -2
View File
@@ -14,7 +14,9 @@
//! A `RocksDB` instance for storing parachain data; availability data, and approvals.
#[cfg(feature = "full-node")]
use {kvdb::KeyValueDB, std::io, std::path::PathBuf, std::sync::Arc};
use {
polkadot_node_subsystem_util::database::Database, std::io, std::path::PathBuf, std::sync::Arc,
};
#[cfg(feature = "full-node")]
mod upgrade;
@@ -31,6 +33,7 @@ pub(crate) mod columns {
pub const COL_APPROVAL_DATA: u32 = 2;
pub const COL_CHAIN_SELECTION_DATA: u32 = 3;
pub const COL_DISPUTE_COORDINATOR_DATA: u32 = 4;
pub const ORDERED_COL: &[u32] = &[COL_AVAILABILITY_META, COL_CHAIN_SELECTION_DATA];
}
/// Columns used by different subsystems.
@@ -83,7 +86,10 @@ pub(crate) fn other_io_error(err: String) -> io::Error {
/// Open the database on disk, creating it if it doesn't exist.
#[cfg(feature = "full-node")]
pub fn open_creating(root: PathBuf, cache_sizes: CacheSizes) -> io::Result<Arc<dyn KeyValueDB>> {
pub fn open_creating_rocksdb(
root: PathBuf,
cache_sizes: CacheSizes,
) -> io::Result<Arc<dyn Database>> {
use kvdb_rocksdb::{Database, DatabaseConfig};
let path = root.join("parachains").join("db");
@@ -107,6 +113,36 @@ pub fn open_creating(root: PathBuf, cache_sizes: CacheSizes) -> io::Result<Arc<d
std::fs::create_dir_all(&path_str)?;
upgrade::try_upgrade_db(&path)?;
let db = Database::open(&db_config, &path_str)?;
let db =
polkadot_node_subsystem_util::database::kvdb_impl::DbAdapter::new(db, columns::ORDERED_COL);
Ok(Arc::new(db))
}
/// Open a parity db database.
#[cfg(feature = "full-node")]
pub fn open_creating_paritydb(
root: PathBuf,
_cache_sizes: CacheSizes,
) -> io::Result<Arc<dyn Database>> {
let path = root.join("parachains");
let path_str = path
.to_str()
.ok_or_else(|| other_io_error(format!("Bad database path: {:?}", path)))?;
std::fs::create_dir_all(&path_str)?;
let mut options = parity_db::Options::with_columns(&path, columns::NUM_COLUMNS as u8);
for i in columns::ORDERED_COL {
options.columns[*i as usize].btree_index = true;
}
let db = parity_db::Db::open_or_create(&options)
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{:?}", err)))?;
let db = polkadot_node_subsystem_util::database::paritydb_impl::DbAdapter::new(
db,
columns::ORDERED_COL,
);
Ok(Arc::new(db))
}