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
@@ -40,8 +40,8 @@ use crate::{
use polkadot_node_primitives::BlockWeight;
use polkadot_primitives::v1::{BlockNumber, Hash};
use kvdb::{DBTransaction, KeyValueDB};
use parity_scale_codec::{Decode, Encode};
use polkadot_node_subsystem_util::database::{DBTransaction, Database};
use std::sync::Arc;
@@ -194,14 +194,14 @@ pub struct Config {
/// The database backend.
pub struct DbBackend {
inner: Arc<dyn KeyValueDB>,
inner: Arc<dyn Database>,
config: Config,
}
impl DbBackend {
/// Create a new [`DbBackend`] with the supplied key-value store and
/// config.
pub fn new(db: Arc<dyn KeyValueDB>, config: Config) -> Self {
pub fn new(db: Arc<dyn Database>, config: Config) -> Self {
DbBackend { inner: db, config }
}
}
@@ -326,7 +326,7 @@ impl Backend for DbBackend {
}
fn load_decode<D: Decode>(
db: &dyn KeyValueDB,
db: &dyn Database,
col_data: u32,
key: &[u8],
) -> Result<Option<D>, Error> {
@@ -387,6 +387,13 @@ fn decode_stagnant_at_key(key: &[u8]) -> Option<Timestamp> {
mod tests {
use super::*;
#[cfg(test)]
fn test_db() -> Arc<dyn Database> {
let db = kvdb_memorydb::create(1);
let db = polkadot_node_subsystem_util::database::kvdb_impl::DbAdapter::new(db, &[0]);
Arc::new(db)
}
#[test]
fn block_height_key_decodes() {
let key = block_height_key(5);
@@ -425,7 +432,7 @@ mod tests {
#[test]
fn write_read_block_entry() {
let db = Arc::new(kvdb_memorydb::create(1));
let db = test_db();
let config = Config { col_data: 0 };
let mut backend = DbBackend::new(db, config);
@@ -455,7 +462,7 @@ mod tests {
#[test]
fn delete_block_entry() {
let db = Arc::new(kvdb_memorydb::create(1));
let db = test_db();
let config = Config { col_data: 0 };
let mut backend = DbBackend::new(db, config);
@@ -486,7 +493,7 @@ mod tests {
#[test]
fn earliest_block_number() {
let db = Arc::new(kvdb_memorydb::create(1));
let db = test_db();
let config = Config { col_data: 0 };
let mut backend = DbBackend::new(db, config);
@@ -515,7 +522,7 @@ mod tests {
#[test]
fn stagnant_at_up_to() {
let db = Arc::new(kvdb_memorydb::create(1));
let db = test_db();
let config = Config { col_data: 0 };
let mut backend = DbBackend::new(db, config);
@@ -571,7 +578,7 @@ mod tests {
#[test]
fn write_read_blocks_at_height() {
let db = Arc::new(kvdb_memorydb::create(1));
let db = test_db();
let config = Config { col_data: 0 };
let mut backend = DbBackend::new(db, config);
@@ -22,10 +22,10 @@ use polkadot_node_subsystem::{
messages::{ChainApiMessage, ChainSelectionMessage},
overseer, FromOverseer, OverseerSignal, SpawnedSubsystem, SubsystemContext, SubsystemError,
};
use polkadot_node_subsystem_util::database::Database;
use polkadot_primitives::v1::{BlockNumber, ConsensusLog, Hash, Header};
use futures::{channel::oneshot, future::Either, prelude::*};
use kvdb::KeyValueDB;
use parity_scale_codec::Error as CodecError;
use std::{
@@ -306,13 +306,13 @@ pub struct Config {
/// The chain selection subsystem.
pub struct ChainSelectionSubsystem {
config: Config,
db: Arc<dyn KeyValueDB>,
db: Arc<dyn Database>,
}
impl ChainSelectionSubsystem {
/// Create a new instance of the subsystem with the given config
/// and key-value store.
pub fn new(config: Config, db: Arc<dyn KeyValueDB>) -> Self {
pub fn new(config: Config, db: Arc<dyn Database>) -> Self {
ChainSelectionSubsystem { config, db }
}
}