Skip to content

Commit

Permalink
Compact more when pruning states (#6667)
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 32cdb32
Merge: f749988 fc0e0ae
Author: Michael Sproul <michael@sigmaprime.io>
Date:   Thu Dec 12 13:14:32 2024 +1100

    Merge branch 'release-v6.0.1' into compact-more

commit f749988
Author: Michael Sproul <michael@sigmaprime.io>
Date:   Sat Dec 7 12:46:54 2024 +1100

    Compact more when pruning states
  • Loading branch information
michaelsproul committed Dec 13, 2024
1 parent 92edebd commit 4aaab3d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn delete_old_schema_freezer_data<T: BeaconChainTypes>(
db.cold_db.do_atomically(cold_ops)?;

// In order to reclaim space, we need to compact the freezer DB as well.
db.cold_db.compact()?;
db.compact_freezer()?;

Ok(())
}
Expand Down
42 changes: 41 additions & 1 deletion beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,45 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
Ok(())
}

/// Run a compaction pass on the freezer DB to free up space used by deleted states.
pub fn compact_freezer(&self) -> Result<(), Error> {
let current_schema_columns = vec![
DBColumn::BeaconColdStateSummary,
DBColumn::BeaconStateSnapshot,
DBColumn::BeaconStateDiff,
DBColumn::BeaconStateRoots,
];

// We can remove this once schema V21 has been gone for a while.
let previous_schema_columns = vec![
DBColumn::BeaconState,
DBColumn::BeaconStateSummary,
DBColumn::BeaconBlockRootsChunked,
DBColumn::BeaconStateRootsChunked,
DBColumn::BeaconRestorePoint,
DBColumn::BeaconHistoricalRoots,
DBColumn::BeaconRandaoMixes,
DBColumn::BeaconHistoricalSummaries,
];
let mut columns = current_schema_columns;
columns.extend(previous_schema_columns);

for column in columns {
info!(
self.log,
"Starting compaction";
"column" => ?column
);
self.cold_db.compact_column(column)?;
info!(
self.log,
"Finishing compaction";
"column" => ?column
);
}
Ok(())
}

/// Return `true` if compaction on finalization/pruning is enabled.
pub fn compact_on_prune(&self) -> bool {
self.config.compact_on_prune
Expand Down Expand Up @@ -2875,6 +2914,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
//
// We can remove this once schema V21 has been gone for a while.
let previous_schema_columns = vec![
DBColumn::BeaconState,
DBColumn::BeaconStateSummary,
DBColumn::BeaconBlockRootsChunked,
DBColumn::BeaconStateRootsChunked,
Expand Down Expand Up @@ -2916,7 +2956,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
self.cold_db.do_atomically(cold_ops)?;

// In order to reclaim space, we need to compact the freezer DB as well.
self.cold_db.compact()?;
self.compact_freezer()?;

Ok(())
}
Expand Down

0 comments on commit 4aaab3d

Please sign in to comment.