Repository navigation
fix(#6196): a placeholder's content record says whose it is, even when it had to spill - #6287
Conversation
…n it had to spill A content record is recognised by the NEGATIVE size marker its slot carries, and every reader that walks a page skips it on that basis. A content record no page can host whole has no size in its slot at all - it is a chunk chain - and writeMultiPageRecord stamped the plain FIRST_CHUNK marker of an ordinary multi-page record on its head, losing the one thing that said the slot was somebody else's. A scan then handed those bytes out twice, under two different RIDs; count() counted them twice; check() reported a multi-page record where there was a surrogate. The head chunk of a content record now carries FIRST_CHUNK_PLACEHOLDER_CONTENT (-4), in the one value the marker namespace still had free between NEXT_CHUNK and the negated sizes. It is one zigzag byte, exactly like the markers either side of it, so the stored format grows by nothing. Every reader that walks or rewrites the CHAIN accepts both heads (isChunkHead); the readers that decide whether a slot is a RECORD - scan, count, existsRecord, getRecordInternal without readPlaceHolderContent - accept only FIRST_CHUNK. The commit-time disjoint-slot merge keeps the head-chunk rebase for it under a slot kind of its own, so the marker the replay expects on the committed page is the one the write started from. Databases written before this hold the ambiguous shape, and only the pointer that leads to it can tell it from a real record. Rather than have every reader tolerate it for ever, CHECK DATABASE now follows each placeholder pointer, reports a content record still stored the old way as an error naming its RID, and CHECK DATABASE FIX repairs it by rewriting that one marker - a repair, never a deletion: not a byte of the record, its chunk header or its chain is touched.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
🟢 Coverage 84.62% diff coverage · -6.53% coverage variation
Metric Results Coverage variation ✅ -6.53% coverage variation Diff coverage ✅ 84.62% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (2a88019) 158956 125396 78.89% Head commit (e0b8aa2) 191396 (+32440) 138480 (+13084) 72.35% (-6.53%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#6287) 117 99 84.62% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Review: fix(#6196) — placeholder content markerI read through the full diff ( Correctness
One thing worth confirming intentional
Tests
Style / minor
Didn't run the full build in this environment ( |
…can of an old database Code review on #6287. Until the FIX has run, the ambiguous content record is still handed out under a RID of its own, and an application that scans a type and writes back what it got can reach it directly - where nothing tells it apart from a record and the write lands on content a placeholder pointer still references. Pre-existing behaviour, and the marker is what closes it, but it is worth saying where a reader of the release notes will look for it. Also states in check() that the reconciliation corrects the RETURNED totals only: the per-page tallies of the verbose log describe the page as the walk found it, which is what a physical-layout log is for.
ReviewThis is an unusually well-documented fix, and I went through Correctness
Test coverageThe new Minor/non-blocking
Overall: this looks correct, thorough, and unusually well-reasoned for a subtle on-disk-format bug — nice work. I didn't find any bugs that would block merging. |
…started from Code review round 2 on #6287: the slot-kind/marker agreement in rebaseRecordOnPage was new logic with no direct test. Driven through rebaseRecordOnPage the way Issue6129ChunkedSlotMergeTest already drives the tracking guards, and for the same reason - no write path produces the transition it refuses, so going through the engine would prove nothing about the guard. Both refusals AND both positive controls, so a guard that refused everything would not pass. Also states the cost of following the pointers in check(): one page fetch per placeholder POINTER, every one of them and not only the chunked case, against a pass that already reads every page and walks every chunk chain.
ReviewThis is a careful, well-documented fix for a real duplicate-scan bug (#6196), and the change is unusually thorough for its size: it introduces a new on-disk marker in the one free slot the zigzag namespace had ( I traced every call site that previously compared against Things that check out:
Two observations, neither of which I'd block on:
Test coverage is strong: the new Nothing here looks incorrect or missing to me; this reads as ready to merge modulo whatever the team wants to do with the two minor observations above. |
…at a verbose run shows Code review round 3 on #6287, both points documentation. The probe costs one page fetch per placeholder pointer on every run, including on a database this build created or one already repaired. The obvious saving - a persisted 'no legacy shape here' flag set by a successful FIX - is not taken, and the javadoc now says why: the flag would have to stay true through every way old bytes reach a repaired database (a restore from an older backup, an HA follower resynced from an older leader, a file a older binary opened and handed back), and a flag that is wrong makes check() skip the one question that finds the shape. The release notes now also name the reporting detail a verbose run against an unrepaired database shows: only the returned totals are reconciled, so a page's own tally disagrees with them for a record the reconciliation moved. Deliberate - a physical-layout log describes the page as the walk found it - but it reads as a bug report if nobody said so.
ReviewThis is a well-scoped, carefully reasoned fix for a real correctness bug (double-counted/duplicated records for a placeholder whose content spilled into a chunk chain). The marker choice ( Minor:
|
…d once, not twice Code review round 4 on #6287. Two independent defects can meet on one record: a content head still wearing the ambiguous FIRST_CHUNK marker whose chunk chain is ALSO broken. The broken-chain branch force-deletes it and reports it; the ambiguity reconciliation that runs after the pass then found the same position in its set, tried to repair a slot that was already zeroed, failed, and emitted a second error and a 'could not be repaired' warning naming a record that was no longer there. Reporting only - the deletion itself was correct, and deletedRecordsAfterFix already listed the right RID - but the surrounding code is careful about exactly this kind of double-booking. The reconciliation now asks again whether the slot still holds the ambiguous shape, and skips it when it does not. The general form of the guard rather than a membership test against deletedRecordsAfterFix: whatever removed or rewrote the slot, and whoever reported it, it is no longer this pass's to report. It costs one page fetch per head actually FOUND in the legacy shape, a set that is empty on every database this build wrote. Tested by aLegacyContentHeadWithABrokenChainIsReportedOnce, which reports 2 errors and the spurious warning without the guard. isLegacyAmbiguousContentHead now also bounds against the page-count snapshot check() took rather than re-reading it, so both of its questions are answered against the bucket the walk covered.
Review of #6287 — placeholder content records with a chunked chain no longer duplicateI traced the fix through every touch point in Correctness checks that passed:
Test coverage is genuinely thorough: reproduction of the duplicate ( Minor/non-blocking observations:
No security or performance concerns beyond the bounded, well-justified |
…t its own RID Code review round 5 on #6287. The update and delete guards for the new marker mirror what the negated-size shape has always done, and the existing tests reached them only indirectly, through the pointer. Driven through LocalBucket rather than through a document on purpose: content.asDocument() is refused one layer earlier, by the read that will not hand out a content record, so it would never reach the two guards this is about. Both assertions go red without them.
Review of #6287I read through the full diff ( Correctness
Test coverageGood breadth: the new PerformanceThe one added cost is SecurityNo concerns. This is purely on-disk storage-engine bookkeeping; no new external input parsing, no serialization of untrusted data, no new dependency. Minor, non-blocking observations
Nice work tracking down and closing an ambiguity that's been latent since the placeholder/chunk mechanisms were built. |
…rs lead to Code review round 6 on #6287 asked for a second pair of eyes on the repair, since it mutates data on the strength of one invariant: a placeholder pointer leads to the content record written for it and nothing else. A corrupted pointer breaks that, and a repair made on it hides a real record from scans - documented as reversible and accepted, but one form of that corruption can be RECOGNISED rather than merely tolerated. A content record belongs to exactly one pointer, so a second pointer leading to the same slot is proof that a pointer is corrupted, and nothing in the bucket says which. That case is now reported and the marker left exactly as found: the marker is unrecoverable information - it says whose the record is - so refusing beats guessing. Costs nothing: the pointers were already being collected in a set, and a duplicate is what add() returning false already told us. Tested by aContentHeadTwoPointersLeadToIsReportedAndLeftAlone, which fabricates the second pointer over a neighbouring record and goes red without the refusal. It drops its type at the end, since the corruption it builds is deliberately the kind FIX cannot repair.
ReviewI did a static read-through of the full diff (I wasn't able to run OverallThis is a well-scoped fix. The new Things I looked at closely and didn't find bugs in
One thing worth a second pair of eyes (not asking for a change, just flagging)
Test coverage
Nice attention to detail overall (e.g. release notes spell out the "run FIX before a read-modify-write scan on an unrepaired DB" operational caveat, and the |
…ch is redundant Two review rounds on #6287 stopped to re-derive that the marker test next to the flag cannot be false on its own - the throw at the top of the branch already rules it out. It is kept so the line states its own precondition rather than borrowing one from thirty lines up, and the comment now says that instead of implying both halves are load-bearing.
ReviewI traced this through Correctness
I didn't find a correctness bug in the core logic. I was not able to run Test coverage Good breadth in Nits (non-blocking)
Security / performance No security concerns. Performance-wise, the one added cost is Nice work tracking down a genuinely subtle ambiguous-on-disk-shape bug and closing both the read-path duplication and the legacy-database repair story in one PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6287 +/- ##
==========================================
+ Coverage 70.12% 70.14% +0.02%
==========================================
Files 1839 1839
Lines 158956 159043 +87
Branches 33534 33557 +23
==========================================
+ Hits 111463 111568 +105
+ Misses 33599 33577 -22
- Partials 13894 13898 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes #6196.
What was wrong
SELECT FROM Doccould return the same record twice, under two different RIDs, andcount(@rid)counted ittwice with it. One record shape reached it: a placeholder whose CONTENT record was too large for any page to
hold whole.
A content record is recognised by the NEGATIVE size marker its slot carries, and every reader that walks a page
skips it on that basis. A content record no page can host whole has no size in its slot at all - it is a chunk
chain - so
writeMultiPageRecordstamped the plainFIRST_CHUNKmarker of an ordinary multi-page record on itshead, and the one thing that said the slot belonged to somebody else was gone at that moment. There was nowhere
else it was written down: the head chunk of a placeholder's content was indistinguishable from the head chunk of
a real record.
So
scan()handed the bytes out as a document of their own, in addition to handing the same bytes out throughthe pointer that references them.
count()counted them.check()had the mirror of the same confusion,counting the record under
totalMultiPageRecordsand never undertotalSurrogateRecords.The fix, and why not the issue's own alternative
The issue offered two. The cheaper one - "stop creating the shape: refuse to place a content record that cannot
fit a page, i.e. make the spill branch of
updateRecordInternalfall through to chunks for the RECORD ITSELF" -turns out not to be available. That branch is reached exactly when
availableSpaceInCurrentPage < MINIMUM_SPACE_FOR_FIRST_CHUNK, afterslotEnlargementForChunkHeadhas already tried to claim the missing bytesthrough the in-page shift: the slot genuinely cannot host a 14-byte chunk header, so the record itself cannot
spill in place, and relocating its content is the only thing left. The premise that the fallback "says nothing
about whether the content will fit a page" is right, but it is not what makes the fallback necessary.
So the marker,
FIRST_CHUNK_PLACEHOLDER_CONTENT= -4: the one value the namespace still had free betweenNEXT_CHUNK(-3) and the negated sizes (< -5), one zigzag byte exactly like the markers either side of it. Thestored format grows by nothing.
Three refinements over the issue's sketch:
Two predicates instead of a dozen open-coded pairs.
isChunkHead(marker)for every reader that walks orrewrites the CHAIN (the header, the region and the chain are identical for the two heads), and
isPlaceholderContent(marker)for the readers that decide whether a slot is a RECORD, which is the one placethe two differ.
scan,count,existsRecordandgetRecordInternalwithoutreadPlaceHolderContentdeliberately test
== FIRST_CHUNKand notisChunkHead, each with a comment saying so.The disjoint-slot merge keeps working on this shape. A head-chunk update of a content record was
rebasable before A placeholder whose CONTENT record had to spill into chunks is returned TWICE by a scan #6196 and stays rebasable, under a
SLOT_KIND_FIRST_CHUNK_PLACEHOLDER_CONTENTof its own -the same replay, differing only in the marker it expects to still find on the committed page, which is
exactly what a kind is for ("the same bytes behind a different marker are a different record"). Poisoning the
page instead would have been simpler and would have cost this shape the concurrency Slot merge does not cover records that outgrew their page: chunked and placeholder updates poison the page unconditionally #6129 gave it.
Old databases are repaired, not tolerated for ever. The issue accepted that "existing databases keep
producing the ambiguous shape and the readers have to tolerate both for ever". They do not have to: only the
pointer can tell the two apart, and
check()already walks every pointer. It now follows each one (one pageread per placeholder, on a shape that is rare to begin with), reports a content record still stored the old
way as an error naming its RID, and
CHECK DATABASE FIXrewrites that one marker. It is a repair and never adeletion - not a byte of the record, its chunk header or its chain is touched, so it is reversible even in
the corrupted-pointer case the javadoc spells out. The identification is collected during the pass and
reconciled after it, so the answer does not depend on whether the content record happens to sit on a page the
walk had already left behind.
Verification
New
Issue6196PlaceholderContentChainTest(3 tests), all three red onmainbefore the fix:aPlaceholderWhoseContentSpilledIsScannedOnce- the issue as reported: one copy in a scan,surrogate=1andmultiPage=1incheck(), and the head chunk invisible toexistsRecordand to a direct load.theContentChainKeepsItsMarkerThroughEveryRewrite- large -> larger -> small -> large -> delete, with themarker and the copy count asserted at each step and the chain freed with the pointer at the end.
checkDatabaseFixRepairsALegacyAmbiguousContentRecord- the marker byte is written back toFIRST_CHUNKtofabricate a pre-fix database, the duplicate is asserted to be there,
CHECK DATABASEreports it,CHECK DATABASE FIXrepairs it without deleting anything, and the duplicate is gone.Issue6178ChunkCollapseTest.aPlaceholderContentStoredAsAChainIsNeverCollapsedasserted the bug deliberately(with a pointer to #6196 saying so); that line now asserts one copy.
Issue5279ConcurrentUpdateTest's rebuiltplaceholder now proves the rebuild by the chunks it gained rather than by a
totalMultiPageRecordsthatcorrectly no longer counts it.
The whole
enginemodule suite is green (-DexcludedGroups=benchmark,vector,slow).Follow-up
#6286: with the shape no longer ambiguous, the one transition still missing is the COLLAPSE of a content
record's chain back into a negated-size record when it shrinks inside its slot. The #6178 guard stays until
collapseChunkChainToRecordcan write that marker.