Repository navigation
fix(#11811): guarded UPDATE and MATCH ... SET no longer write a record that stopped matching their WHERE - #11823
shaunpatterson wants to merge 5 commits into
Conversation
…te a record that stopped matching their WHERE - SQL: the UPDATE's WHERE is evaluated again on a record modify() reloaded after a concurrent commit; a record that no longer matches is skipped. - openCypher: a SET whose rows were selected by a WHERE or a pattern property map refuses a reloaded record with the retryable conflict. - Regression tests in ConcurrentRecordWriteTest.StaleReadModify. Fixes ArcadeData#11808
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 45 minutes. View limit details
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. |
|
This pull request is closed, so it cannot be queued. Reopen it to get the box back. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 84 |
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.
|
Triage: Review of #11823The change fixes #11808 ( What the PR does
Non-blocking suggestions
|
…ern or other records stopped matching - MERGE: a matched record a concurrent commit changed so that it no longer matches the pattern is refused with the retryable conflict, at the match and again when ON MATCH SET (or an absorbed SET) reloads it; one that still matches keeps building on the commit. - MATCH/WITH predicates: before a SET writes a row, every record of the row is checked against its committed content, not only the write target, so a WHERE on one alias no longer lets a write to another alias through. - ImmutableDocument.latestIfChangedSinceRead() reads the newest committed content without touching the record the row holds. - Tests in ConcurrentRecordWriteTest.StaleReadModify.
|
Triage: Review of #11823 (fixes #11808)Summary: The fix closes a real compare-and-set hole. Under READ_COMMITTED, a guarded SQL What I checked
Suggestions (non-blocking)
Overall this looks correct and well scoped. |
# Conflicts: # engine/src/main/java/com/arcadedb/query/opencypher/executor/CypherExecutionPlan.java
|
Triage: Triage of #11823 (fixes #11808). No security hazard found, and the diff contains nothing aimed at the reviewer. What it does
The fix targets the right class of bug. The severity ( Tests
Minor notes, none blocking
|
# Conflicts: # engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/SetClauseApplier.java
|
Triage: Review of #11823This fixes the guarded UPDATE / MATCH ... SET compare-and-set race from #11808. That issue is labelled What I checked
Non-blocking suggestions
Overall this is solid and well tested. |
|
This branch now conflicts with main and is not auto-rebased: main already contains an equivalent fix (#11818, SelectionPredicates) and #11808 is closed. The branch carries a competing design (RowGuards, a BiPredicate stillSelected) in SetClauseApplier, ConvertToUpdatableResultStep and UpdateExecutionPlanner. What it adds beyond main is the MERGE pattern check in MergeStep (main passes SelectionPredicates.NONE there). Suggest porting only that part onto SelectionPredicates and closing this PR. |
|
Thanks for this. Main moved under it: #11826 (fixes #11818) landed the re-check of the selecting predicates for SQL This PR now conflicts in
Both are tracked in #12593 now. Could you rebase onto main, rebuild those two on top of |
Part of #11811: the guarded UPDATE /
MATCH ... SEThalf, reported as #11808 and closed as a duplicate of #11811. The guardedDELETEhalf of #11811 (#11810) is not covered here.Summary
A guarded
UPDATE ... WHERE(SQL) orMATCH ... WHERE ... SET(openCypher) could write a record that no longer satisfied itsWHERE. UnderREAD_COMMITTED, if a concurrent commit changed the record between the statement's read andmodify(), the executors cleared the stale-read flag (#8610) because the assigned values are re-evaluated on the reloaded content. The predicate was not re-evaluated, so two callers could both win a compare-and-set such asUPDATE T SET claimed = true WHERE claimed IS NULL.Changes
ConvertToUpdatableResultStepreceives the UPDATE'sWhereClause. Whenmodify()reloaded different content, theWHEREis evaluated again on the reloaded record and the record is skipped if it no longer matches. Only a reloaded record pays for the second evaluation.RowGuardsrecords on the statement context whether the rows are selected by a predicate (aWHERE, or a property map in a pattern).SetClauseApplierrefuses a reloaded record with the retryableConcurrentModificationExceptionin that case, so the statement runs again and its predicate sees the committed state. A statement with no predicate (MATCH (v:V) SET v.n = v.n + 1) is unchanged and still builds on the reloaded content.MATCH (a:A), (b:B) WHERE a.claimed IS NULL SET b.flag = true). Before a guarded SET writes a row,RowGuards.refuseIfRowChangedcompares every record the row binds with its committed content (ImmutableDocument.latestIfChangedSinceRead(), which reads the newest content without touching the record the row holds; a page whose version did not move costs no read) and refuses the row with the retryable conflict if one changed.MERGE: its pattern is the predicate.MergeStepchecks each record it matched against its committed content; one a concurrent commit changed so that it no longer matches the pattern (or deleted) refuses the statement with the retryable conflict, so the retry matches, or creates, what the pattern selects now. A record that still matches stays matched, so the hot upsertMERGE (c:C {id: $id}) ON MATCH SET c.n = c.n + 1keeps building on a concurrent increment instead of retrying. The ON MATCH SET (and a SET the MERGE absorbed) checks the pattern again on a write targetmodify()reloaded.ConcurrentRecordWriteTest.StaleReadModifyusing the existing in-statement interleaving helper: SQL and Cypher (WHEREand pattern property) guarded updates write nothing, a SQLWHEREthat still matches keeps building on the concurrent write,MERGE ... ON MATCH SETon a record that stopped matching writes nothing, aWHEREon one alias stops a SET on another, a MERGE pattern on one alias stops an ON MATCH SET on another, and a MERGE whose record still matches commits.How to test
The three guarded tests of the first commit fail on
main("Expecting value to be false but was true") and pass here.End to end, the repro from the issue (
cas_race.py, 8 threads, HTTP session transactions and autocommit, SQL and Cypher) went from 1 to 14 rounds with two winners per 150 to 0 in 1,200 rounds with this change. The hot-counter case (UPDATE C SET n = n + 1 WHERE id = 'a'from 8 threads) shows the same conflict rate as before (255 and 246 failed statements out of 1,200).Review round (5ecdaf1)
Both review findings held:
RowGuards.hasRowPredicatenever looked at the MERGE clause, soMERGE (v:V {n: 0}) ON MATCH SET v.claimed = truewrote a record a concurrent commit had moved ton = 5. Flagging MERGE as guarded would have turned every contended upsert into a retry (CypherConcurrentWriteTest.onMatchSetSeesTheIncrementCommittedAfterTheMatchasserts it commits), so the pattern is checked again on the committed content instead.MATCH (v:V), (w:W) WHERE v.n = 0 SET w.claimed = truewrotewaftervstopped matching.New tests, each failing on the previous head of this branch (22d2633) and passing here:
cypherMergeOnMatchSetWhosePatternStoppedMatchingInsideTheStatementWritesNothing,cypherSetOnAnotherAliasWhoseWhereStoppedMatchingInsideTheStatementWritesNothing,cypherMergeOnMatchSetOnAnotherAliasWhosePatternStoppedMatchingInsideTheStatementWritesNothing;cypherMergeOnMatchSetOnAnotherAliasWhosePatternStillMatchesCommitsis the counterpart and passes on both.Scope: the checks run where a write clause applies a row: SET, ON MATCH SET, and a SET a MERGE absorbed. Without read-set validation at commit, a commit landing after that check and before this transaction commits still changes a record the row was selected by (the target itself is checked at commit, as it is written). An anonymous node or relationship of a MERGE path pattern is not bound in the row and is not checked; a single anonymous MERGE node is.
Tests run: the whole engine module without the
slowandbenchmarkgroups, 27,746 tests: 27,715 passed, 22 skipped, 9 failed. After merging main (48a1109), the 9 failing tests' classes and the guard tests were run again:CypherCountChainStartsAtSelectiveEndIssue11594Test(fixed on main by #11828),ColumnarEquivalenceTest,FacetOracleSelfTest,FacetExecutorTermsTest,ConcurrentRecordWriteTest(34) andCypherConcurrentWriteTest(33) all passed. The remaining 2 wereReplicatedApplyPublicationTesttiming failures, which also fail on main's CI.Bug prevention
DELETEhas the same shape and is Guarded DELETE can remove a record a concurrent transaction just updated so the WHERE no longer holds #11810, now tracked in [concurrency] Guarded UPDATE and DELETE (WHERE on a stale read) are not atomic under READ_COMMITTED #11811.Overlap with #11826
#11826 (#11818) fixes the same race: the SQL
UPDATEpart (ConvertToUpdatableResultStepevaluates the WHERE again on reloaded content) is the same approach in both, and both changeSetClauseApplierandImmutableDocument. #11826 also covers openCypherREMOVEandDELETEand SQLDELETE, and re-evaluates the openCypher predicates instead of refusing every reloaded guarded row. This PR covers what #11826 lists as not covered:MERGE ... ON MATCH SETand a predicate on a record the clause does not write. Whichever lands first, the other needs a rework, not just a merge.