From 65baef9e0e48b90e555baa954a2f22d81806bfbd Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 21 May 2024 15:43:04 +0800 Subject: [PATCH] core/rawdb: fsync data file --- core/rawdb/freezer_batch.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/rawdb/freezer_batch.go b/core/rawdb/freezer_batch.go index 8e3c18f9a9..4e1b38df29 100644 --- a/core/rawdb/freezer_batch.go +++ b/core/rawdb/freezer_batch.go @@ -180,14 +180,17 @@ func (batch *freezerTableBatch) maybeCommit() error { return nil } -// commit writes the batched items to the backing freezerTable. Note neither index -// nor data file are fsync'd after the file write, the recent write can be lost +// commit writes the batched items to the backing freezerTable. Note index +// file isn't fsync'd after the file write, the recent write can be lost // after the power failure. func (batch *freezerTableBatch) commit() error { _, err := batch.t.head.Write(batch.dataBuffer) if err != nil { return err } + if err := batch.t.head.Sync(); err != nil { + return err + } dataSize := int64(len(batch.dataBuffer)) batch.dataBuffer = batch.dataBuffer[:0]