Skip to content

Conversation

owanikin
Copy link

Issue Addressed

#7911

Proposed Changes

  • Add migration v29 for Redb file-format upgrade.
  • Introduce migration_schema_v29.rs with:
    • Upgrade path gated under the redb feature.
    • Explicit irreversible downgrade (returns error).
  • Register migration in schema_change.rs.

pub fn downgrade_from_v29<T: BeaconChainTypes>(
_d: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
) -> Result<Vec<KeyValueStoreOp>, Error> {
Err(Error::MigrationError("Cannot downgrade from v29: Redb file format upgrade is irreversible".to_string()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the downgrade should only fail if redb is enabled and the database backend is redb

In all other cases it should just be a no-op

@eserilev
Copy link
Member

Just wanted to document here that redb v2.6.2 creates the db using the v3 format by default

https://docs.rs/redb/2.6.2/src/redb/db.rs.html#1202-1220

So once we push this change, new redb databases will be using the correct v3 format as well

@eserilev eserilev marked this pull request as ready for review September 8, 2025 21:44
Copy link
Member

@eserilev eserilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sticking through with this! This looks really good, mostly just have some things to remove

pub fn upgrade_to_v29<T: BeaconChainTypes>(
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
) -> Result<Vec<KeyValueStoreOp>, Error> {
if db.is_redb() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was nice for testing, but we no longer need this, you can just call upgrade

}
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(redb) => {
info!("Running Redb v29 migration");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets update to this log to "Updating Redb file format to v3"

match self {
#[cfg(feature = "leveldb")]
BeaconNodeBackend::LevelDb(_) => {
info!("LevelDB upgrade: no migration needed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets update this log to "LevelDB, no upgrade required" and downgrade this log to debug

Comment on lines 273 to 277
#[cfg(feature = "redb")]
let _database_backend = DatabaseBackend::Redb;
#[cfg(feature = "leveldb")]
let database_backend = DatabaseBackend::LevelDb;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, this must be something I pushed up, we can remove this

@@ -82,6 +84,8 @@ pub struct HotColdDB<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
historic_state_cache: Mutex<HistoricStateCache<E>>,
/// Chain spec.
pub spec: Arc<ChainSpec>,
/// Database backend type
pub database_backend: Option<DatabaseBackend>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this as well

@@ -1,3 +1,5 @@
#[cfg(feature = "redb")]
use crate::config::DatabaseBackend;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

@@ -242,6 +246,7 @@ impl<E: EthSpec> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> {
config,
hierarchy,
spec,
database_backend: None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

@@ -294,6 +304,7 @@ impl<E: EthSpec> HotColdDB<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>> {
config,
hierarchy,
spec,
database_backend: Some(database_backend),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove as well

@@ -12,7 +12,7 @@ rust-version = "1.88.0"
normal = ["target_check"]

[features]
default = ["slasher-lmdb", "beacon-node-leveldb"]
default = ["slasher-lmdb", "beacon-node-redb"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set default back to leveldb (sorry I think I pushed up this change)

#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(redb) => {
info!("Updating Redb file format to v3");
redb.upgrade()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note thta upgrade returns true is successful and false if its already in the v3 format

https://docs.rs/redb/2.6.2/redb/struct.Database.html#method.upgrade

In all other failure cases it will raise an error

Copy link
Member

@eserilev eserilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@michaelsproul whenever you have a chance, would be great to get your review as well. Thanks!

@eserilev eserilev added the ready-for-review The code is ready for review label Sep 9, 2025
Copy link

mergify bot commented Sep 9, 2025

Some required checks have failed. Could you please take a look @owanikin? 🙏

@mergify mergify bot added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Sep 9, 2025
@eserilev
Copy link
Member

eserilev commented Sep 9, 2025

@owanikin we have a small ci failure, can you run cargo sort --workspace and push those changes up when you get the chance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database waiting-on-author The reviewer has suggested changes and awaits thier implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants