From d90bb048bf802e15c5347e247c31315579134608 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 30 Jan 2024 16:07:11 +1100 Subject: [PATCH] `fsync` during backfill to prevent DB corruption --- beacon_node/beacon_chain/src/historical_blocks.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/beacon_node/beacon_chain/src/historical_blocks.rs b/beacon_node/beacon_chain/src/historical_blocks.rs index c8c56514461..83f092611ba 100644 --- a/beacon_node/beacon_chain/src/historical_blocks.rs +++ b/beacon_node/beacon_chain/src/historical_blocks.rs @@ -206,8 +206,14 @@ impl BeaconChain { drop(sig_timer); // Write the I/O batches to disk. + // We fsync after each write because we need the writes to the blob and freezer DB to + // be persisted if the writes to the hot DB are persisted. Without fsync we could end up + // in a situation where the hot DB's anchor is updated but the actual blocks are forgotten + // from disk. self.store.blobs_db.do_atomically(blob_batch)?; + self.store.blobs_db.sync()?; self.store.cold_db.do_atomically(cold_batch)?; + self.store.cold_db.sync()?; let mut anchor_and_blob_batch = Vec::with_capacity(2); @@ -237,6 +243,7 @@ impl BeaconChain { .compare_and_set_anchor_info(Some(anchor_info), Some(new_anchor))?, ); self.store.hot_db.do_atomically(anchor_and_blob_batch)?; + self.store.hot_db.sync()?; // If backfill has completed and the chain is configured to reconstruct historic states, // send a message to the background migrator instructing it to begin reconstruction.