tx: detect cycles in recursivelyCheckPageKeyOrderInternal#1195
Open
ivangsm wants to merge 1 commit intoetcd-io:mainfrom
Open
tx: detect cycles in recursivelyCheckPageKeyOrderInternal#1195ivangsm wants to merge 1 commit intoetcd-io:mainfrom
ivangsm wants to merge 1 commit intoetcd-io:mainfrom
Conversation
recursivelyCheckPageKeyOrderInternal walks branch children without tracking pages it has already entered, so a corrupted db whose branch references one of its own ancestors drives the goroutine stack to overflow even after forEachPageInternal (etcd-io#1194) stops looping. Thread a visited set through the recursion, emit a single "page cycle detected" error on revisit, and return so the outer Check continues to surface other diagnostics. Related to etcd-io#701 / etcd-io#581. Signed-off-by: Iván Salazar <ivangio.salazar@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ivangsm 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.
Summary
tx.Check()runs two recursive walkers fromcheckInvariantProperties:forEachPage(fixed by #1194) andrecursivelyCheckPageKeyOrder. Thesecond walker does not track visited pages, so a db with a branch page
that references one of its own ancestors still drives the goroutine stack
to overflow during a
Check, even with #1194 applied.This threads a
visited map[common.Pgid]struct{}through the recursion.On a revisit the function emits one
page cycle detected at pgId:%derror to the check channel and returns, so
Checkfinishes and surfacesany other diagnostics instead of crashing the process.
The accompanying whitebox test reproduces the corruption pattern from
#701 (copy a branch page over a leaf descendant to form a back-edge) and
asserts that the walker terminates with the expected error.
Partially addresses #581. Companion to #1194. Follows tjungblu's
follow-up ask in #701.
A third cycle-sensitive walker remains — the cursor-driven
b.ForEachBucketpath insiderecursivelyCheckBucket— and is beingtracked separately; it is not a mechanical patch and will get its own
issue/PR.
Test plan
go test -run TestTx_recursivelyCheckPageKeyOrder_CycleTerminatespasses with the fix and stack-overflows without it.TEST_FREELIST_TYPE=array BBOLT_VERIFY=all go test -short ./...passes.TEST_FREELIST_TYPE=hashmap BBOLT_VERIFY=all go test -short ./...passes.make fmtclean.