From 1f1d711c4960e245f7087d851f94cce5789446f0 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 18 Sep 2023 10:24:45 +0000 Subject: [PATCH] core/rawdb: no need to run truncateFile for readonly mode Signed-off-by: jsvisa --- core/rawdb/freezer_table.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/rawdb/freezer_table.go b/core/rawdb/freezer_table.go index fc6316c953..2595834740 100644 --- a/core/rawdb/freezer_table.go +++ b/core/rawdb/freezer_table.go @@ -211,8 +211,10 @@ func (t *freezerTable) repair() error { } } // Ensure the index is a multiple of indexEntrySize bytes - if overflow := stat.Size() % indexEntrySize; overflow != 0 { - truncateFreezerFile(t.index, stat.Size()-overflow) // New file can't trigger this path + if !t.readonly { + if overflow := stat.Size() % indexEntrySize; overflow != 0 { + truncateFreezerFile(t.index, stat.Size()-overflow) // New file can't trigger this path + } } // Retrieve the file sizes and prepare for truncation if stat, err = t.index.Stat(); err != nil { @@ -269,7 +271,7 @@ func (t *freezerTable) repair() error { // Keep truncating both files until they come in sync contentExp = int64(lastIndex.offset) - for contentExp != contentSize { + for !t.readonly && contentExp != contentSize { verbose = true // Truncate the head file to the last offset pointer if contentExp < contentSize {