Repository navigation
fix(core/rawdb): return the iterator error from InspectDatabase - #2723
Merged
gzliudan merged 1 commit intoOct 16, 2026
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
gzliudan
requested review from
AnilChinchawale,
anunay-xin,
benjamin202410,
liam-lai and
wanwiset25
October 3, 2026 15:37
gzliudan
force-pushed
the
fix-rawdb-inspect-iterator-error
branch
from
October 6, 2026 07:56
6cc4754 to
cc8e782
Compare
benjamin202410
approved these changes
Oct 13, 2026
gzliudan
force-pushed
the
fix-rawdb-inspect-iterator-error
branch
4 times, most recently
from
October 14, 2026 04:14
f239ea8 to
d47bf69
Compare
anunay-xin
approved these changes
Oct 14, 2026
wanwiset25
approved these changes
Oct 15, 2026
gzliudan
force-pushed
the
fix-rawdb-inspect-iterator-error
branch
3 times, most recently
from
October 16, 2026 09:00
97a46fc to
6fd664e
Compare
ported from go-ethereum ethereum#32506 InspectDatabase walked the keyspace and never consulted it.Error(), so a walk that the database aborted printed a table built from a partial scan and returned nil, which reads as "inspection passed" to whoever ran db inspect. Only the per-key accounting was affected; nothing on the consensus or sync paths reads this function, its single caller is the db inspect command. Upstream landed the check as part of parallelising the traversal, so its InspectDatabase is a worker closure over per-range stat structs driven by an errgroup. The version here is the single-threaded one and the two do not line up line for line, so only the semantics are ported: report the pending iterator error once the walk ends. The defect predates dev-upgrade, hence a separate commit rather than a fixup. The test also pins the user-visible half of the early return, by capturing os.Stdout around the call: an aborted walk must render nothing, and a clean walk over the same fixture must still render the report, down to its per-category rows and a non-zero total. Upstream orders it the same way - its workers return the iterator error and eg.Wait short-circuits before the table is rendered - but upstream has no test for either function, so the assertion is ours. One direction alone cannot tell an early return apart from a function that never renders anything. Confirmed with go test -overlay, both directions: deleting the check fails the first assertion with got <nil>, moving it below table.Render() fails the second one on the table built from the partial scan. The capture helper drains the pipe from its own goroutine and restores os.Stdout through t.Cleanup, so the walk cannot deadlock against the pipe buffer. The aborted-walk fixture is shared with TestDeleteDanglingHashesIteratorError, which landed with XinFinOrg#2707; it lives in accessors_chain_test.go, so this test keeps no copy of its own. The zero-total assertion counts the total rows it recognises and fails when it finds none, so a column layout it no longer matches cannot leave the check silently vacuous.
gzliudan
force-pushed
the
fix-rawdb-inspect-iterator-error
branch
from
October 16, 2026 09:10
6fd664e to
b88ee21
Compare
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.
Proposed changes
InspectDatabasewalks a keyspace with an iterator and never consultedit.Error(), so a walk that the database aborted on an I/O error was indistinguishable from one that ran to the end - both leave the loop onNext() == false. It then rendered a table built from the partial scan and returned nil, which reads as "inspection passed" to whoever randb inspect. Only the per-key accounting is affected: nothing on the consensus or sync paths reads this function, and its single caller is thedb inspectcommand (cmd/XDC/dbcmd.go:210).The fix reports the pending iterator error once the walk ends, before the report is rendered. Upstream does report it, as part of go-ethereum ethereum#32506, but that change landed inside a parallelisation of the traversal (a worker closure over per-range stat structs driven by an errgroup) while the function here is the single-threaded version, so only the semantics are ported, not the shape. The defect predates
dev-upgrade, so it lands as its own commit rather than a fixup.This is the same class of gap that #2707 fixes one function over in
DeleteDanglingHashes, split out into its own PR. It carries no dependency on that PR; the only overlap is the shared test fixtures, whichdev-upgradealready carries (see the note below).Tests
TestInspectDatabaseIteratorErrorwrapsethdb.Databasein a test-only store whoseNewIteratorhands out an iterator that stops after one key and reports an error, so a truncated walk is reproducible without a production seam. It also capturesos.Stdoutaround the call, which pins the check on both sides: an aborted walk must render nothing, and a clean walk over the same fixture must still render the report, down to its per-category rows and a non-zero total. One direction alone cannot tell an early return apart from a function that never renders anything.Both directions are confirmed with
go test -overlay, each failing on a different assertion:it.Error()check fails withexpected the iterator error to be returned, got <nil>- the pre-fix behaviour;table.Render()fails on the table built from the partial scan, which is what pins it as an early return rather than a trailing one. The capture helper drains the pipe from its own goroutine and restoresos.Stdoutthrought.Cleanup, so the walk cannot deadlock against the pipe buffer.make allandmake quick-testpass on the branch.Note on the shared test fixture
The store that aborts the walk mid-iteration, and the headers it walks, come from the fixtures
failingIterator,failingIterStoreandwriteOrphanHeadersincore/rawdb/accessors_chain_test.go.dev-upgradecarries them since #2707 landed, andTestDeleteDanglingHashesIteratorErrorandTestDeleteDanglingHashesCleanWalkuse them too. This branch keeps no copy of its own, so the two share one declaration per symbol and can land in either order.Types of changes
Impacted Components
Checklist
The three network-facing items are not applicable here: the change only alters an error path that surfaces when the database itself fails mid-walk, so the wire format, consensus rules, storage layout and API signatures are untouched, and nodes running this build coexist with older ones unchanged. Reaching the changed line end to end needs an I/O failure while a keyspace is being walked, which cannot be produced by configuration; the unit test drives it through the injected iterator instead.