Skip to content

debugIteratePrefixLatest: skip DB entries within file range #20355

@sudeepdino008

Description

@sudeepdino008

Parent issue

Part of #16239 -- avoiding inconsistency due to lexicographic prune.

Problem

In db/state/domain_stream.go, debugIteratePrefixLatest pushes DB entries into the priority heap even when their step is already covered by segment files. After a partial (lexicographic) prune, the DB may retain stale entries with steps within the file range — these should never be queried.

The initial DB cursor entry is pushed with endTxNum: math.MaxUint64, which always wins over file entries. The advance loop computes endTxNum from the step but still pushes entries within the file range into the heap.

Fix

Compute filesEndTxNum := dt.files.EndTxNum() once, then in both the initial DB push and the advance loop, skip any DB entry whose step.ToTxNum(stepSize) < filesEndTxNum. Only push DB entries whose step is beyond the file range.

This matches the "don't query DB for data that is in files" pattern already applied to History (#20360, #20361) and InvertedIndex (#20362).

Test

TestDomain_IteratePrefix_PrefersFilesOverDB: writes entries across two steps, builds files, deletes the latest DB dup to simulate partial prune, verifies file value is returned instead of stale DB value.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions