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: fix freezer validation #26251

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Changes from all commits
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
25 changes: 15 additions & 10 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,30 +318,35 @@ func (f *Freezer) Sync() error {
return nil
}

// validate checks that every table has the same length.
// validate checks that every table has the same boundary.
// Used instead of `repair` in readonly mode.
func (f *Freezer) validate() error {
if len(f.tables) == 0 {
return nil
}
var (
length uint64
name string
head uint64
tail uint64
name string
)
// Hack to get length of any table
// Hack to get boundary of any table
for kind, table := range f.tables {
length = atomic.LoadUint64(&table.items)
head = atomic.LoadUint64(&table.items)
tail = atomic.LoadUint64(&table.itemHidden)
name = kind
break
}
// Now check every table against that length
// Now check every table against those boundaries.
for kind, table := range f.tables {
items := atomic.LoadUint64(&table.items)
if length != items {
return fmt.Errorf("freezer tables %s and %s have differing lengths: %d != %d", kind, name, items, length)
if head != atomic.LoadUint64(&table.items) {
return fmt.Errorf("freezer tables %s and %s have differing head: %d != %d", kind, name, atomic.LoadUint64(&table.items), head)
}
if tail != atomic.LoadUint64(&table.itemHidden) {
return fmt.Errorf("freezer tables %s and %s have differing tail: %d != %d", kind, name, atomic.LoadUint64(&table.itemHidden), tail)
}
}
atomic.StoreUint64(&f.frozen, length)
atomic.StoreUint64(&f.frozen, head)
atomic.StoreUint64(&f.tail, tail)
return nil
}

Expand Down