Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ serde_json = "1.0.81"
thiserror = "1.0.31"
kvdb = "0.11.0"
kvdb-rocksdb = { version = "0.15.2", optional = true }
parity-db = { version = "0.3.13", optional = true }
parity-db = { version = "0.3.16", optional = true }
async-trait = "0.1.53"
lru = "0.7"

Expand Down
62 changes: 61 additions & 1 deletion node/service/src/parachains_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@

#[cfg(feature = "full-node")]
use {
polkadot_node_subsystem_util::database::Database, std::io, std::path::PathBuf, std::sync::Arc,
polkadot_node_subsystem_util::database::Database,
std::io,
std::path::{Path, PathBuf},
std::sync::Arc,
};

#[cfg(feature = "full-node")]
mod upgrade;

const LOG_TARGET: &str = "parachain::db";

#[cfg(any(test, feature = "full-node"))]
pub(crate) mod columns {
pub mod v0 {
Expand Down Expand Up @@ -120,6 +125,59 @@ pub fn open_creating_rocksdb(
Ok(Arc::new(db))
}

fn fix_columns(
path: &Path,
options: parity_db::Options,
allowed_columns: Vec<u32>,
) -> io::Result<()> {
// Figure out which columns to delete. This will be determined by inspecting
// the metadata file.
if let Ok(Some(metadata)) = parity_db::Options::load_metadata(&path) {
let columns_to_clear = metadata
.columns
.into_iter()
.enumerate()
.filter(|(idx, _)| allowed_columns.contains(&(*idx as u32)))
.filter_map(|(idx, opts)| {
let changed = opts != options.columns[idx];
if changed {
gum::debug!(
target: LOG_TARGET,
"Column {} will be cleared. Old options: {:?}, New options: {:?}",
idx,
opts,
options.columns[idx]
);
Some(idx)
} else {
None
}
})
.collect::<Vec<_>>();

if columns_to_clear.len() > 0 {
gum::debug!(
target: LOG_TARGET,
"Database column changes detected, need to cleanup {} columns.",
columns_to_clear.len()
);
}

for column in columns_to_clear {
gum::debug!(target: LOG_TARGET, "Clearing column {}", column,);
parity_db::clear_column(path, column.try_into().expect("Invalid column ID"))
.map_err(|e| other_io_error(format!("Error clearing column {:?}", e)))?;
}

// Write the updated column options.
options
.write_metadata(path, &metadata.salt)
.map_err(|e| other_io_error(format!("Error writing metadata {:?}", e)))?;
}

Ok(())
}

/// Open a parity db database.
#[cfg(feature = "full-node")]
pub fn open_creating_paritydb(
Expand All @@ -138,6 +196,8 @@ pub fn open_creating_paritydb(
options.columns[*i as usize].btree_index = true;
}

fix_columns(&path, options.clone(), vec![columns::COL_DISPUTE_COORDINATOR_DATA])?;

let db = parity_db::Db::open_or_create(&options)
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{:?}", err)))?;

Expand Down