Repository navigation
fix(#6120): fold the index entries on RESTORE DOCUMENT/VERTEX/EDGE - #6123
Conversation
…hough unreachable PR #6119 code review traced the call graph and found the guard cannot fire today: both callers derive the offset from getLastRecordPositionInPage(), whose getRecordPositionInPage() already rejects a non-zero entry below contentHeaderSize. Kept, but the reachability argument is now stated in place so the next reader does not have to re-derive it.
RESTORE put the record back in its bucket but never re-added its index entries, so after a restore an index-resolved query missed the record while a full scan returned it, and a UNIQUE index never learned the key had come back - leaving it free to hand the same key to a second record unchallenged. Same "wrong answer indistinguishable from a right one" family as #6069 and #6096, but on every indexed query rather than on a counter. LocalBucket.restoreRecordAtPosition() performs only the physical page write, exactly like bucket-level create/delete. Everything a create folds on top of it is the caller's job, and having each RESTORE call site do that by hand is precisely how the record-count delta was missed in #6069 and the index entries here: four call sites, four chances to forget, and the #6082 fix could not even be shared with GraphEngine without inverting the package dependency direction. So the primitive moves down to where the equivalent create bookkeeping already lives: DatabaseInternal.restoreRecord(record, bucket, position), implemented in LocalDatabase beside createRecordNoLock. It folds the bucket record-count delta (#6069), the transaction record cache, the index entries (#6120) and the new-record registration a rollback needs (#4562/#4940). RESTORE DOCUMENT/VERTEX/EDGE and GraphEngine.restoreVertexAt all route through it, and RestoreStatementSupport's hand-rolled copy is gone. Two deliberate departures from createRecordNoLock, both because RESTORE is admin repair rather than user DML: no validate()/setDefaultValues() (a mandatory-property check would block a structure-only shell restore exactly when the emergency repair is needed) and no create events (firing user triggers on a repair is a behaviour change well beyond this gap). Six regression tests, each confirmed red with the fold removed: the document/vertex/edge SQL arms, the UNIQUE-index duplicate rejection a restored key now gets, the Java API via restoreRecord with a populated record, and the rollback identity reset. No index test on GraphEngine.restoreVertexAt: it restores a property-less shell, and a null-valued indexed property produces no index entry on any path, insert included, so such a test would be vacuous. ServerDatabase and RaftReplicatedDatabase gain the delegating override the new interface method requires.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 22 |
🟢 Coverage 81.08% diff coverage · -6.59% coverage variation
Metric Results Coverage variation ✅ -6.59% coverage variation Diff coverage ✅ 81.08% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (59e590a) 156148 122572 78.50% Head commit (908c8a5) 188618 (+32470) 135629 (+13057) 71.91% (-6.59%) 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 (#6123) 37 30 81.08% 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 Solid fix, and the write-up makes the reasoning easy to verify against the diff. The core idea of moving the "everything a create folds on top of the physical page write" bookkeeping down into Correctness
One behavioral gap vs createRecordNoLock In the default configuration ( Minor / nit
Design departures (validate/setDefaultValues and create events skipped) Tests One gap acknowledged in the PR description itself: no index-specific test on Summary |
… parity with create PR #6123 code review raised three points, all valid. The substantive one: restoreRecord called getTransaction() directly, so on a database opened with setAutoTransaction(true) a plain INSERT would wrap itself in an implicit transaction while RESTORE DOCUMENT/VERTEX/EDGE threw TransactionException. Not a regression - the helper it replaced did the same - but RESTORE should not be the one statement that behaves differently from an INSERT for those callers. It now uses the same checkTransactionIsActive(autoTransaction) + implicit commit/rollback frame as createRecordNoLock. The review offered a javadoc note as the cheaper option; parity is the better one, and it costs a try/finally. Second: restoreRecord did not reject an already-persistent record, so a future misuse would silently overwrite the identity of a live record rather than failing. It now raises the same IllegalArgumentException createRecordNoLock does. Verified this does not catch RESTORE EDGE, whose shell comes from the MutableEdge(database, type, out, in) constructor and is non-persistent like the others. Third: an out-of-order import in RaftReplicatedDatabase. The interface javadoc now also states the transaction contract and both deliberate departures from create (no validate()/default values, no create events), so the next reader does not have to trace the call graph to establish what the review just established. Two tests, both confirmed red against the fix removed - the auto-transaction one failing with exactly the "Transaction not begun" the review predicted. Full engine suite: 11717 tests, 1 failure - Issue5279ConcurrentUpdateTest, which fails identically on clean main.
ReviewThis is a well-scoped fix with strong regression coverage (6 tests, each verified red against the fold removed per the PR description) and clear documentation of the two deliberate departures from One correctness issue found on close reading:
|
PR #6123 second review flagged that restoreRecordInTransaction called indexer.createDocument() before transaction.registerNewRecord(), the opposite of createRecordNoLock's order, so an exception from the indexer would skip the rollback identity reset and leave a dangling RID on the caller's object. The conclusion is right and the reorder costs nothing, so it is applied. The mechanism the review cited is not, and the comment now records both so the question is not reopened later: the review named the unique-constraint path exercised by restoreDocumentEnforcesTheUniqueIndexOnTheRestoredKey, but a duplicate key is detected at COMMIT, not inline - measured directly, restoreRecord returns normally with an identity, the DuplicatedKeyException comes out of commit(), and the rollback already resets the identity to null. A regression test written to that scenario would pass with and without the reorder, so none was added. What does make the order matter is that Index.put() can throw inline: checkIsValid() on a dropped or invalidated index, and convertKeys() on a key it cannot coerce. Reaching either needs an index dropped or corrupted mid-transaction, which is contrived enough that a test would pin the scaffolding rather than the behaviour, so this stands as defensive parity with createRecordNoLock rather than a covered fix.
|
Addressed in e1c1ee8 — with one correction to the finding, since it changes what the code should say. The reorder is applied. The cited mechanism does not reproduce, though. The review names the unique-constraint path exercised by
(This also corrects the first review on this PR, which said the ordering "does not matter here". It does — just not via the duplicate-key path.) What does make the order matter: The code comment now records both halves — the reachable inline throws, and the fact that the unique path is not one of them — so this doesn't get re-litigated on the next read. Verification: restore tests plus a |
|
Review Solid fix, and the PR description/commit history shows the tricky bits (auto-transaction parity, persistent-record rejection, register-before-index ordering) were already caught and addressed across the four commits. I read through the full diff plus the surrounding Correctness
Test coverage Minor / non-blocking
Not re-litigating No correctness, security, or performance issues found. I could not run |
PR #6123 third review nit: the DOC_TYPE-specific countByScan() added earlier duplicated the parametrized countByScan(String) almost line for line. It now delegates.
ReviewThis is a solid fix for a real correctness bug (index entries silently missing after Two things worth a look before merge: 1.
|
…mmit PR #6123 fourth review raised two contract gaps around the new primitive. Both are real and both are now closed. 1. The implicit auto-transaction was opened before executeInReadLock and committed after it, so only the physical write was inside the lock. createRecord wraps ALL of createRecordNoLock - checkTransactionIsActive, the work and the implicit commit/rollback - in a single read lock, and the gap left a window unique in this class for an executeInWriteLock caller (drop(), close()) to interleave between the page write and the commit that persists it. The whole body is now one read lock, matching the sibling. Verified no deadlock: the auto-transaction regression test drives an implicit commit from inside the lock and passes, which is possible only because commit() does not need the write lock (the same reason createRecord's shape works). 2. restoreRecordInTransaction did not fold poisonEdgeAppendPage for MutableEdgeSegment/StripeDirectory the way createRecordNoLock does. A restored edge chunk is absent from the committed version of its page, so replaying this transaction's appends against that page at commit would target the wrong bytes. No current caller restores one - every RESTORE arm passes a document/vertex/edge shell - but this is a general Record-typed method on a shared interface, so the review's options were a javadoc note or a guard. Folding the same poison is better than either: a future caller gets correct behaviour instead of a documented trap. Note restoreRecordAtPosition already poisons the SLOT merge; this is the separate commutative edge-append merge. Restore tests plus a Restore*/Transaction*/Concurren*/Drop*/Close*/Lock*/ Database* subset: 489 tests, 1 failure - Issue5279ConcurrentUpdateTest, which fails identically on clean main.
|
Both points were valid — fixed in 908c8a5. 1. Implicit commit outside the read lock. Confirmed against the sibling: Worth recording why this is safe, since it is the one thing that could have gone wrong: committing while holding a read lock would deadlock if 2. Missing The javadoc's "two deliberate departures" list stays accurate — folding this means it was never a third departure. Verification: On the sandbox note: understood that this review was manual tracing only. Local runs have been backing each commit — the prior one had a full engine suite at 11717 tests with the same single pre-existing failure. |
ReviewI read through the full diff plus the surrounding code ( OverallThis is a solid, well-scoped fix. The root cause diagnosis (index bookkeeping folded into
The two deliberate departures from Minor findings (not blocking)
Nits
Nothing here rises to a correctness or security concern. The iterative review history on this PR (auto-transaction parity, persistent-record guard, registration-before-indexing ordering, single-lock-window fix, edge-append poisoning) already caught the substantive issues; what's left is test-coverage polish. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6123 +/- ##
========================================
Coverage 69.72% 69.72%
========================================
Files 1821 1821
Lines 156148 156275 +127
Branches 32959 32979 +20
========================================
+ Hits 108873 108967 +94
- Misses 33615 33644 +29
- Partials 13660 13664 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes #6120. Follow-up to #6119 (#6096), which merged before this was ready.
What was wrong
RESTOREput the record back in its bucket but never re-added its index entries. After a restore, an index-resolved query missed the record while a full scan returned it:And a UNIQUE index never learned the key had come back, leaving it free to hand that same key to a second record unchallenged. Same "wrong answer indistinguishable from a right one" family as #6069 and #6096, but on every indexed query rather than on a counter.
The fix, and why it is not a one-liner
LocalBucket.restoreRecordAtPosition()performs only the physical page write, exactly like bucket-level create/delete. Everything a create folds on top of it is the caller's job - and having each RESTORE call site do that by hand is precisely how the record-count delta was missed in #6069 and the index entries here. Four call sites, four chances to forget, and #6082's shared helper could not even be reused byGraphEngine.restoreVertexAtwithout inverting the package dependency direction (that PR's review raised it and correctly declined).So the primitive moves down to where the equivalent create bookkeeping already lives:
DatabaseInternal.restoreRecord(record, bucket, position), implemented inLocalDatabasebesidecreateRecordNoLock. It folds:count(*)reads (RESTORE DOCUMENT does not restore the bucket record count: count(*) reports one fewer than a full scan, and it persists #6069)RESTORE DOCUMENT/VERTEX/EDGEandGraphEngine.restoreVertexAtall route through it;RestoreStatementSupport's hand-rolled copy is gone. One place to forget instead of four.Two deliberate departures from
createRecordNoLockBoth because RESTORE is admin repair, not user DML:
validate()/setDefaultValues()- a mandatory-property check would block a structure-only shell restore exactly when the emergency repair is needed.Worth a maintainer opinion: both are now explicit decisions rather than accidents, and the second one means a restored record silently skips
onAfterCreate. I lean toward documenting the contract in the SQL reference rather than changing it.Verification
Six regression tests, each confirmed red with the fold removed:
RestoreSqlStatementTest.restoreDocumentReindexesTheRestoredRecordRestoreSqlStatementTest.restoreVertexReindexesTheRestoredRecordRestoreSqlStatementTest.restoreEdgeReindexesTheRestoredRecordRestoreSqlStatementTest.restoreDocumentEnforcesTheUniqueIndexOnTheRestoredKey- the duplicate rejection a restored key now getsRestoreRecordAtPositionTest.restoreRecordReindexesTheRestoredRecord- the Java API, viarestoreRecordwith a populated recordRestoreRecordAtPositionTest.rollingBackARestoreLeavesNoDanglingIdentityOnTheShellNo index test on
GraphEngine.restoreVertexAt: it restores a property-less shell, and I verified a null-valued indexed property produces no index entry on any path, insert included - so such a test would be vacuous. It is covered for the count fold (#6069) as before, and shares this fold throughrestoreRecord.Full
enginesuite: 11715 tests, 1 failure -Issue5279ConcurrentUpdateTest.growingUpdatesUnderContentionKeepTheDatabaseConsistent, which fails identically on cleanmain(verified by stashing this change). Whole project compiles;ServerDatabaseandRaftReplicatedDatabasegain the delegating override the new interface method requires.Also carries
072430913, the doc commit answering PR #6119's review point about thecontentEndOffset()header guard being unreachable - it was pushed too late to reach that merge.