Skip to content

Commit 545f4c5

Browse files
authored
core/rawdb: no need to run truncateFile for readonly mode (#28145)
Avoid truncating files, if ancients are opened in readonly mode. With this change, we return error instead of trying (and failing) to repair
1 parent 5b9cbe3 commit 545f4c5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

core/rawdb/freezer_table.go

+6
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ func (t *freezerTable) repair() error {
212212
}
213213
// Ensure the index is a multiple of indexEntrySize bytes
214214
if overflow := stat.Size() % indexEntrySize; overflow != 0 {
215+
if t.readonly {
216+
return fmt.Errorf("index file(path: %s, name: %s) size is not a multiple of %d", t.path, t.name, indexEntrySize)
217+
}
215218
truncateFreezerFile(t.index, stat.Size()-overflow) // New file can't trigger this path
216219
}
217220
// Retrieve the file sizes and prepare for truncation
@@ -270,6 +273,9 @@ func (t *freezerTable) repair() error {
270273
// Keep truncating both files until they come in sync
271274
contentExp = int64(lastIndex.offset)
272275
for contentExp != contentSize {
276+
if t.readonly {
277+
return fmt.Errorf("freezer table(path: %s, name: %s, num: %d) is corrupted", t.path, t.name, lastIndex.filenum)
278+
}
273279
verbose = true
274280
// Truncate the head file to the last offset pointer
275281
if contentExp < contentSize {

0 commit comments

Comments
 (0)