Repository navigation
db: reject a corrupt freelist at open instead of panicking mid-commit - #1348
Open
tony1233200 wants to merge 1 commit into
Open
tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
A freelist containing an invalid page id, an entry at or above the
high-water mark, or a duplicate was accepted at open and only died
later, mid-commit, with a panic ('invalid page allocation: 0',
'page N already freed', 'freelist pgid (N) above high water mark').
Validate the loaded freelist in loadFreelist and report the problem
as an error from Open (and on the Tx.Check channel) instead.
Fixes etcd-io#1319 (freelist rows).
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tony1233200 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A corrupt freelist was accepted at open and only died later, in the middle of a commit, with a panic:
invalid page allocation: 0,page N already freed, orfreelist pgid (N) above high water mark.Opennow validates the cheap structural invariants the writer always maintains — every entry is a real page id (never a meta page), lies below the high-water mark, and appears at most once — and fails with a clear error instead.Changes
db.go:loadFreelistnow returns an error (stored so repeat calls see the same result);validateFreelistchecks the loaded ids viaCopyall(free + pending, both backends share it).db.go(Open): a failed freelist load closes the DB and returns the error, like the other open failures.tx_check.go(Tx.check): a failed freelist load is reported on the check channel instead of proceeding with a corrupt freelist.freelist_validate_test.go+testdata/issue1319/: regression tests using the reproducer databases attached to Reader accepts pages violating writer invariants, freelist and page checks miss them #1319.Repro (before the fix, on main
a1121b9)All three reproducer databases opened fine and panicked at
Commit:bbolt_freelist.go_117.db→panic: invalid page allocation: 0bbolt_freelist.go_175.db→panic: page 2 already freedbbolt_node.go_375.db→panic: freelist pgid (8960) above high water mark (4)After the fix,
OpenwithPreLoadFreelist: truereturns e.g.freelist contains invalid page id 0/freelist page id 8960 is at or above the high-water mark 4. (The new fixture test fails on unpatched main —Openreturns a nil error — and passes with the fix.)Tests
go test -run 'TestLoadFreelistRejectsInvalidEntries|TestValidateFreelistRejectsDuplicateEntries' -count=1 .— passgo test -p 1 -count=1 -skip 'TestConcurrent|TestSimulate|TestQuick' .— pass (array freelist)TEST_FREELIST_TYPE=hashmap go test -p 1 -count=1 -skip 'TestConcurrent|TestSimulate|TestQuick' .— passgo test -p 1 -count=1 ./internal/...— passgo vet ./...— clean except the pre-existingreflect.ValueOfcopylocks note indb_test.go:1507, which the file itself marks//nolint:govetgofmtclean;gofumptclean on the new test file (thedb.go/tx_check.gogofumpt diffs are pre-existing lines elsewhere in those files, verified against unpatched main, and left untouched)Note: the full non-
-shortsuite was not run to completion on this small VM —TestBucket_Delete_FreelistOverflow(a bulk-write test doing ~8k fdatasync commits, on a code path this change does not touch) exceeds a 300s timeout here; the repo's own default test timeout is 30m. The-shortsuites above, which cover the load/check paths this change touches, pass on both freelist backends.Notes / scope
bbolt_db.go_1359.db,bbolt_bucket.go_570.db— nil bucket in a cursor walk) and theoverflow_past_hwm.dboverlap case are separate mechanisms and are not covered here; the HWM side of the overlap case is already addressed by tx: reject page ids at or above the high-water mark in Tx.page #1346/tx: flag overflow spans that pass the high-water mark in Tx.Check #1347.meta.pgid, or a duplicate (its ownFree/mergeSpanspaths panic on those).