Skip to content

Commit f3b7888

Browse files
Compact more when pruning states (#6667)
* Compact more when pruning states * Merge branch 'release-v6.0.1' into compact-more
1 parent 775fa67 commit f3b7888

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

beacon_node/beacon_chain/src/schema_change/migration_schema_v22.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn delete_old_schema_freezer_data<T: BeaconChainTypes>(
152152
db.cold_db.do_atomically(cold_ops)?;
153153

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

157157
Ok(())
158158
}

beacon_node/store/src/hot_cold_store.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,45 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
24842484
Ok(())
24852485
}
24862486

2487+
/// Run a compaction pass on the freezer DB to free up space used by deleted states.
2488+
pub fn compact_freezer(&self) -> Result<(), Error> {
2489+
let current_schema_columns = vec![
2490+
DBColumn::BeaconColdStateSummary,
2491+
DBColumn::BeaconStateSnapshot,
2492+
DBColumn::BeaconStateDiff,
2493+
DBColumn::BeaconStateRoots,
2494+
];
2495+
2496+
// We can remove this once schema V21 has been gone for a while.
2497+
let previous_schema_columns = vec![
2498+
DBColumn::BeaconState,
2499+
DBColumn::BeaconStateSummary,
2500+
DBColumn::BeaconBlockRootsChunked,
2501+
DBColumn::BeaconStateRootsChunked,
2502+
DBColumn::BeaconRestorePoint,
2503+
DBColumn::BeaconHistoricalRoots,
2504+
DBColumn::BeaconRandaoMixes,
2505+
DBColumn::BeaconHistoricalSummaries,
2506+
];
2507+
let mut columns = current_schema_columns;
2508+
columns.extend(previous_schema_columns);
2509+
2510+
for column in columns {
2511+
info!(
2512+
self.log,
2513+
"Starting compaction";
2514+
"column" => ?column
2515+
);
2516+
self.cold_db.compact_column(column)?;
2517+
info!(
2518+
self.log,
2519+
"Finishing compaction";
2520+
"column" => ?column
2521+
);
2522+
}
2523+
Ok(())
2524+
}
2525+
24872526
/// Return `true` if compaction on finalization/pruning is enabled.
24882527
pub fn compact_on_prune(&self) -> bool {
24892528
self.config.compact_on_prune
@@ -2875,6 +2914,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
28752914
//
28762915
// We can remove this once schema V21 has been gone for a while.
28772916
let previous_schema_columns = vec![
2917+
DBColumn::BeaconState,
28782918
DBColumn::BeaconStateSummary,
28792919
DBColumn::BeaconBlockRootsChunked,
28802920
DBColumn::BeaconStateRootsChunked,
@@ -2916,7 +2956,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
29162956
self.cold_db.do_atomically(cold_ops)?;
29172957

29182958
// In order to reclaim space, we need to compact the freezer DB as well.
2919-
self.cold_db.compact()?;
2959+
self.compact_freezer()?;
29202960

29212961
Ok(())
29222962
}

0 commit comments

Comments
 (0)