Skip to content

Commit b006c0b

Browse files
authored
Revert "core/rawdb: fsync the index file after each freezer write (ethereum#28483)"
This reverts commit aee1721.
1 parent 1b33e18 commit b006c0b

File tree

4 files changed

+10
-28
lines changed

4 files changed

+10
-28
lines changed

core/rawdb/ancient_utils.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package rawdb
1818

1919
import (
2020
"fmt"
21-
"path/filepath"
2221

2322
"github.com/ethereum/go-ethereum/common"
2423
"github.com/ethereum/go-ethereum/ethdb"
@@ -127,8 +126,6 @@ func InspectFreezerTable(ancient string, freezerName string, tableName string, s
127126
switch freezerName {
128127
case chainFreezerName:
129128
path, tables = resolveChainFreezerDir(ancient), chainFreezerNoSnappy
130-
case stateFreezerName:
131-
path, tables = filepath.Join(ancient, freezerName), stateFreezerNoSnappy
132129
default:
133130
return fmt.Errorf("unknown freezer, supported ones: %v", freezers)
134131
}

core/rawdb/freezer_batch.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,27 +182,19 @@ func (batch *freezerTableBatch) maybeCommit() error {
182182

183183
// commit writes the batched items to the backing freezerTable.
184184
func (batch *freezerTableBatch) commit() error {
185-
// Write data. The head file is fsync'd after write to ensure the
186-
// data is truly transferred to disk.
185+
// Write data.
187186
_, err := batch.t.head.Write(batch.dataBuffer)
188187
if err != nil {
189188
return err
190189
}
191-
if err := batch.t.head.Sync(); err != nil {
192-
return err
193-
}
194190
dataSize := int64(len(batch.dataBuffer))
195191
batch.dataBuffer = batch.dataBuffer[:0]
196192

197-
// Write indices. The index file is fsync'd after write to ensure the
198-
// data indexes are truly transferred to disk.
193+
// Write indices.
199194
_, err = batch.t.index.Write(batch.indexBuffer)
200195
if err != nil {
201196
return err
202197
}
203-
if err := batch.t.index.Sync(); err != nil {
204-
return err
205-
}
206198
indexSize := int64(len(batch.indexBuffer))
207199
batch.indexBuffer = batch.indexBuffer[:0]
208200

core/rawdb/freezer_table.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ func (t *freezerTable) repair() error {
215215
if t.readonly {
216216
return fmt.Errorf("index file(path: %s, name: %s) size is not a multiple of %d", t.path, t.name, indexEntrySize)
217217
}
218-
if err := truncateFreezerFile(t.index, stat.Size()-overflow); err != nil {
219-
return err
220-
} // New file can't trigger this path
218+
truncateFreezerFile(t.index, stat.Size()-overflow) // New file can't trigger this path
221219
}
222220
// Retrieve the file sizes and prepare for truncation
223221
if stat, err = t.index.Stat(); err != nil {
@@ -262,8 +260,8 @@ func (t *freezerTable) repair() error {
262260
// Print an error log if the index is corrupted due to an incorrect
263261
// last index item. While it is theoretically possible to have a zero offset
264262
// by storing all zero-size items, it is highly unlikely to occur in practice.
265-
if lastIndex.offset == 0 && offsetsSize/indexEntrySize > 1 {
266-
log.Error("Corrupted index file detected", "lastOffset", lastIndex.offset, "indexes", offsetsSize/indexEntrySize)
263+
if lastIndex.offset == 0 && offsetsSize%indexEntrySize > 1 {
264+
log.Error("Corrupted index file detected", "lastOffset", lastIndex.offset, "items", offsetsSize%indexEntrySize-1)
267265
}
268266
if t.readonly {
269267
t.head, err = t.openFile(lastIndex.filenum, openFreezerFileForReadOnly)
@@ -418,9 +416,6 @@ func (t *freezerTable) truncateHead(items uint64) error {
418416
if err := truncateFreezerFile(t.index, int64(length+1)*indexEntrySize); err != nil {
419417
return err
420418
}
421-
if err := t.index.Sync(); err != nil {
422-
return err
423-
}
424419
// Calculate the new expected size of the data file and truncate it
425420
var expected indexEntry
426421
if length == 0 {
@@ -443,17 +438,13 @@ func (t *freezerTable) truncateHead(items uint64) error {
443438
// Release any files _after the current head -- both the previous head
444439
// and any files which may have been opened for reading
445440
t.releaseFilesAfter(expected.filenum, true)
446-
447441
// Set back the historic head
448442
t.head = newHead
449443
t.headId = expected.filenum
450444
}
451445
if err := truncateFreezerFile(t.head, int64(expected.offset)); err != nil {
452446
return err
453447
}
454-
if err := t.head.Sync(); err != nil {
455-
return err
456-
}
457448
// All data files truncated, set internal counters and return
458449
t.headBytes = int64(expected.offset)
459450
t.items.Store(items)
@@ -598,12 +589,10 @@ func (t *freezerTable) Close() error {
598589
// error on Windows.
599590
doClose(t.index, true, true)
600591
doClose(t.meta, true, true)
601-
602592
// The preopened non-head data-files are all opened in readonly.
603593
// The head is opened in rw-mode, so we sync it here - but since it's also
604594
// part of t.files, it will be closed in the loop below.
605595
doClose(t.head, true, false) // sync but do not close
606-
607596
for _, f := range t.files {
608597
doClose(f, false, true) // close but do not sync
609598
}

core/rawdb/freezer_utils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ func copyFrom(srcPath, destPath string, offset uint64, before func(f *os.File) e
7373
return err
7474
}
7575
f = nil
76-
return os.Rename(fname, destPath)
76+
77+
if err := os.Rename(fname, destPath); err != nil {
78+
return err
79+
}
80+
return nil
7781
}
7882

7983
// openFreezerFileForAppend opens a freezer table file and seeks to the end

0 commit comments

Comments
 (0)