Skip to content

Commit 913fee4

Browse files
authored
core/rawdb: skip setting flushOffset in read-only mode (#31173)
This PR addresses a flaw in the freezer table upgrade path. In v1.15.0, freezer table v2 was introduced, including an additional field (`flushOffset`) maintained in the metadata file. To ensure backward compatibility, an upgrade path was implemented for legacy freezer tables by setting `flushOffset` to the size of the index file. However, if the freezer table is opened in read-only mode, this file write operation is rejected, causing Geth to shut down entirely. Given that invalid items in the freezer index file can be detected and truncated, all items in freezer v0 index files are guaranteed to be complete. Therefore, when operating in read-only mode, it is safe to use the freezer data without performing an upgrade.
1 parent 8ec4a06 commit 913fee4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

core/rawdb/freezer_table.go

+7
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,13 @@ func (t *freezerTable) repairIndex() error {
405405
// If legacy metadata is detected, attempt to recover the offset from the
406406
// index file to avoid clearing the entire table.
407407
if t.metadata.version == freezerTableV1 {
408+
// Skip truncation if the legacy metadata is opened in read-only mode.
409+
// Since all items in the legacy index file were forcibly synchronized,
410+
// data integrity is guaranteed. Therefore, it's safe to leave any extra
411+
// items untruncated in this special scenario.
412+
if t.readonly {
413+
return nil
414+
}
408415
t.logger.Info("Recovering freezer flushOffset for legacy table", "offset", size)
409416
return t.metadata.setFlushOffset(size, true)
410417
}

0 commit comments

Comments
 (0)