Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/rawdb: freezer index repair #29792

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
core/rawdb: polish
  • Loading branch information
rjl493456442 committed Sep 9, 2024
commit 0fe416d704aae15990f563588f6d28dd3057269e
21 changes: 14 additions & 7 deletions core/rawdb/freezer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ func (t *freezerTable) repairIndex() error {
continue
}
// Ensure that the first non-head index refers to the earliest file,
// or the next file if the earliest file is not sufficient to
// place the first item.
// or the next file if the earliest file has no space to place the
// first item.
if offset == indexEntrySize {
if entry.filenum != head.filenum && entry.filenum != head.filenum+1 {
log.Error("Corrupted index item detected", "earliest", head.filenum, "filenumber", entry.filenum)
Expand All @@ -474,11 +474,18 @@ func (t *freezerTable) repairIndex() error {
return nil
}

// checkIndexItems checks the validity of two consecutive index items. The index
// item is regarded as invalid if:
// - file number of two index items are not same and not monotonically increasing
// - data offset of two index items with same file number are out of order
// - zero data offset with an increasing file number
// checkIndexItems validates the correctness of two consecutive index items based
// on the following rules:
//
// - The file number of two consecutive index items must either be the same or
// increase monotonically. If the file number decreases or skips in a
// non-sequential manner, the index item is considered invalid.
//
// - For index items with the same file number, the data offset must be in
// non-decreasing order. Note: Two index items with the same file number
// and the same data offset are permitted if the entry size is zero.
//
// - The first index item in a new data file must not have a zero data offset.
func (t *freezerTable) checkIndexItems(a, b indexEntry) error {
if b.filenum != a.filenum && b.filenum != a.filenum+1 {
return fmt.Errorf("index items with inconsistent file number, prev: %d, next: %d", a.filenum, b.filenum)
Expand Down