Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
v2 to v3 migration drops COL_DISPUTE_COORDINATOR_DATA instead of cl…
Browse files Browse the repository at this point in the history
…earing it
  • Loading branch information
tdimitrov committed May 16, 2023
1 parent b938b92 commit 39ae191
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
4 changes: 2 additions & 2 deletions node/service/src/parachains_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ 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;
#[cfg(test)]
pub const COL_SESSION_WINDOW_DATA: u32 = 5;

pub const ORDERED_COL: &[u32] =
&[COL_AVAILABILITY_META, COL_CHAIN_SELECTION_DATA, COL_DISPUTE_COORDINATOR_DATA];
}

pub mod v3 {
pub const NUM_COLUMNS: u32 = 6;
pub const NUM_COLUMNS: u32 = 5;
pub const COL_AVAILABILITY_DATA: u32 = 0;
pub const COL_AVAILABILITY_META: u32 = 1;
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 COL_SESSION_WINDOW_DATA: u32 = 5; // not used

pub const ORDERED_COL: &[u32] =
&[COL_AVAILABILITY_META, COL_CHAIN_SELECTION_DATA, COL_DISPUTE_COORDINATOR_DATA];
Expand Down
23 changes: 4 additions & 19 deletions node/service/src/parachains_db/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,15 @@ fn rocksdb_migrate_from_version_1_to_2(path: &Path) -> Result<(), Error> {
}

fn rocksdb_migrate_from_version_2_to_3(path: &Path) -> Result<(), Error> {
use kvdb::{DBOp, DBTransaction};
use kvdb_rocksdb::{Database, DatabaseConfig};

let db_path = path
.to_str()
.ok_or_else(|| super::other_io_error("Invalid database path".into()))?;
let db_cfg = DatabaseConfig::with_columns(super::columns::v2::NUM_COLUMNS);
let db = Database::open(&db_cfg, db_path)?;

// Wipe all entries in one operation.
let ops = vec![DBOp::DeletePrefix {
col: super::columns::v2::COL_SESSION_WINDOW_DATA,
prefix: kvdb::DBKey::from_slice(b""),
}];
let mut db = Database::open(&db_cfg, db_path)?;

db.write(DBTransaction { ops })?;
db.remove_last_column()?;

Ok(())
}
Expand Down Expand Up @@ -264,7 +257,6 @@ pub(crate) fn paritydb_version_1_config(path: &Path) -> parity_db::Options {
}

/// Database configuration for version 2.
#[cfg(test)]
pub(crate) fn paritydb_version_2_config(path: &Path) -> parity_db::Options {
let mut options =
parity_db::Options::with_columns(&path, super::columns::v2::NUM_COLUMNS as u8);
Expand Down Expand Up @@ -328,9 +320,8 @@ fn paritydb_migrate_from_version_1_to_2(path: &Path) -> Result<(), Error> {
/// Migration from version 2 to version 3:
/// - clear any columns used by `RollingSessionWindow`
fn paritydb_migrate_from_version_2_to_3(path: &Path) -> Result<(), Error> {
parity_db::clear_column(path, super::columns::v2::COL_SESSION_WINDOW_DATA as u8)
.map_err(|e| other_io_error(format!("Error clearing COL_SESSION_WINDOW_DATA {:?}", e)))?;

parity_db::Db::drop_last_column(&mut paritydb_version_2_config(path))
.map_err(|e| other_io_error(format!("Error removing COL_SESSION_WINDOW_DATA {:?}", e)))?;
Ok(())
}

Expand Down Expand Up @@ -503,9 +494,6 @@ mod tests {
let db = Db::open(&paritydb_version_3_config(&path)).unwrap();

assert_eq!(db.num_columns(), columns::v3::NUM_COLUMNS as u8);

// ensure column is empty
assert!(db.get(COL_SESSION_WINDOW_DATA as u8, &test_key.to_vec()).unwrap().is_none());
}

#[test]
Expand Down Expand Up @@ -542,8 +530,5 @@ mod tests {
let db = Database::open(&db_cfg, db_path).unwrap();

assert_eq!(db.num_columns(), super::columns::v3::NUM_COLUMNS);

// Ensure data is actually removed
assert!(db.get(COL_SESSION_WINDOW_DATA, b"1337").unwrap().is_none());
}
}

0 comments on commit 39ae191

Please sign in to comment.