From dfebbcf52a0e5e318cbe9fc592f136ba3a9d238c Mon Sep 17 00:00:00 2001 From: Aleksandr Logunov Date: Wed, 8 Mar 2023 17:47:33 +0400 Subject: [PATCH] fix: order of guarded and non-guarded db migration (#8672) In https://github.com/near/nearcore/pull/8617 we introduced new DB migration (deprecating Peers column). But before it we had another migration indicating creation of flat storage columns, currently guarded by compilation flag. Actually, we should put "peers" migration **before** "flat state" migration, because for nodes which don't have flat state enabled, intermediate version in `match` will be missing. We didn't see it because we also didn't update `DB_VERSION`, which essentially means that nodes didn't trigger any migrations yet. Here I also bump `DB_VERSION`, so nodes will run "peers" migration and then "flat state" migration if compilation flag is enabled. The only outcome is that our custom nodes which have flat state **will not** run "peers" migration, but this is fine. cc @saketh-are --- core/store/src/metadata.rs | 2 +- core/store/src/migrations.rs | 4 ++-- nearcore/src/migrations.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/store/src/metadata.rs b/core/store/src/metadata.rs index 27b9ade55af..161cc383d94 100644 --- a/core/store/src/metadata.rs +++ b/core/store/src/metadata.rs @@ -3,7 +3,7 @@ pub type DbVersion = u32; /// Current version of the database. pub const DB_VERSION: DbVersion = - if cfg!(feature = "protocol_feature_flat_state") { 35 } else { 34 }; + if cfg!(feature = "protocol_feature_flat_state") { 36 } else { 35 }; /// Database version at which point DbKind was introduced. const DB_VERSION_WITH_KIND: DbVersion = 34; diff --git a/core/store/src/migrations.rs b/core/store/src/migrations.rs index d1ece60611b..8d36e00c18b 100644 --- a/core/store/src/migrations.rs +++ b/core/store/src/migrations.rs @@ -305,11 +305,11 @@ pub fn migrate_33_to_34(store: &Store, mut is_node_archival: bool) -> anyhow::Re Ok(()) } -/// Migrates the database from version 35 to 36. +/// Migrates the database from version 34 to 35. /// /// This involves deleting contents of Peers column which is now /// deprecated and no longer used. -pub fn migrate_35_to_36(store: &Store) -> anyhow::Result<()> { +pub fn migrate_34_to_35(store: &Store) -> anyhow::Result<()> { let mut update = store.store_update(); update.delete_all(DBCol::_Peers); update.commit()?; diff --git a/nearcore/src/migrations.rs b/nearcore/src/migrations.rs index bceceaea981..3967647b490 100644 --- a/nearcore/src/migrations.rs +++ b/nearcore/src/migrations.rs @@ -153,13 +153,13 @@ impl<'a> near_store::StoreMigrator for Migrator<'a> { 33 => { near_store::migrations::migrate_33_to_34(store, self.config.client_config.archive) } + 34 => near_store::migrations::migrate_34_to_35(store), #[cfg(feature = "protocol_feature_flat_state")] - 34 => { - tracing::info!(target: "migrations", "Migrating DB version from 34 to 35. Flat storage data will be created on disk."); + 35 => { + tracing::info!(target: "migrations", "Migrating DB version from 35 to 36. Flat storage data will be created on disk."); tracing::info!(target: "migrations", "It will happen in parallel with regular block processing. ETA is 5h for RPC node and 10h for archival node."); Ok(()) } - 35 => near_store::migrations::migrate_35_to_36(store), DB_VERSION.. => unreachable!(), } }