Skip to content

Commit 8e68926

Browse files
fsync during backfill to prevent DB corruption (sigp#5144)
1 parent 7862c71 commit 8e68926

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

beacon_node/beacon_chain/src/historical_blocks.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
206206
drop(sig_timer);
207207

208208
// Write the I/O batches to disk.
209+
// We fsync after each write because we need the writes to the blob and freezer DB to
210+
// be persisted if the writes to the hot DB are persisted. Without fsync we could end up
211+
// in a situation where the hot DB's anchor is updated but the actual blocks are forgotten
212+
// from disk.
209213
self.store.blobs_db.do_atomically(blob_batch)?;
214+
self.store.blobs_db.sync()?;
210215
self.store.cold_db.do_atomically(cold_batch)?;
216+
self.store.cold_db.sync()?;
211217

212218
let mut anchor_and_blob_batch = Vec::with_capacity(2);
213219

@@ -237,6 +243,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
237243
.compare_and_set_anchor_info(Some(anchor_info), Some(new_anchor))?,
238244
);
239245
self.store.hot_db.do_atomically(anchor_and_blob_batch)?;
246+
self.store.hot_db.sync()?;
240247

241248
// If backfill has completed and the chain is configured to reconstruct historic states,
242249
// send a message to the background migrator instructing it to begin reconstruction.

0 commit comments

Comments
 (0)