Repository navigation
fix(plan): lock base rows before irregular update fanout - #27144
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
a3a8af9 to
49a1f7a
Compare
49a1f7a to
e9ea9b5
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review completed at e9ea9b5. No blocking findings.
Verified the invariant end to end: for synchronous IVF/fulltext/master UPDATE maintenance, the shared row-image SINK is now downstream of the existing LOCK_OP, and the runtime lock operator acquires all base/regular-index targets for each batch before that batch can fan out to hidden-table delete/insert consumers. Ordinary and async-index UPDATE routes keep their prior topology.
Also checked projection/remapping closure (including multi-target selector columns and existing preserved-lock users), lock-table/no-row handling, hidden-table key conflicts, and cancel/retry behavior. Local validation passed: full ./pkg/sql/plan tests and the three new focused tests under -race.
Merge Queue Status
This pull request spent 14 minutes 32 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #27144 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes #27124 Backport of #27144. Related to #27142, #26925, and #26518. ## What this PR does / why we need it: ### Root cause #26518 moved synchronous IVF/full-text UPDATE maintenance to separate top-level steps that consume a shared materialized final-row image. The existing base/regular-index `LOCK_OP` remained downstream of that materialization in only the main `MULTI_UPDATE` consumer. The base consumer and hidden-index consumers could therefore acquire locks in opposite order: ```text T1: base row -> waits for IVF/full-text hidden row T2: IVF/full-text hidden row -> waits for base row ``` #26925 removes false self-cycles from deadlock detection, but it cannot remove these real two-transaction cycles. ### Fix For UPDATEs with synchronous irregular-index maintenance, move the existing base/regular-index `LOCK_OP` before the shared row-image `SINK`: ```text final row image -> existing LOCK_OP -> shared SINK -> base MULTI_UPDATE -> irregular delete maintenance -> irregular insert maintenance ``` Preserve the complete positional row image through the moved lock gate so all sink consumers continue to resolve the same columns. This is a semantic backport because the original main commit conflicts with the current 4.2 planner implementation. It retains #27144's lock-order invariant while adapting to the 4.2 UPDATE fanout helper. 4.2 does not support master-index UPDATE, so the regression covers its reachable IVF and full-text paths. ### Risk assessment - No new lock, lock mode, release rule, RPC, or lockservice behavior is introduced. - Normal UPDATEs keep `MULTI_UPDATE -> LOCK_OP`. - Synchronous IVF/full-text UPDATEs execute the same lock operation once, earlier in the same transaction. - Async indexes remain CDC-only. ### Tests - Verified the new planner regression fails on clean 4.2-dev `aaac5956fd` for both IVF and full-text because the maintenance fanout has no upstream base lock. - `pkg/sql/plan` full package test. - Focused planner regressions with `-count=10`. - `go vet ./pkg/sql/plan`. - `TestIssue26341CancelAndRetryFulltextUpdate` embedded three-CN regression, covering lock blocking, cancellation, rollback, retry, and hidden-index consistency.
…n#27144) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27142 Related to matrixorigin#27124, matrixorigin#26925, and matrixorigin#26518. ## What this PR does / why we need it: ### Root cause matrixorigin#26518 moved synchronous IVF/full-text UPDATE maintenance to separate top-level steps that consume a shared materialized final-row image. The pre-existing base-table `LOCK_OP` remained downstream of that materialization in only the main `MULTI_UPDATE` consumer. The main consumer and hidden-index consumers could therefore acquire locks independently: ```text T1: base row -> waits for IVF entries row T2: IVF entries row -> waits for base row ``` Production logs after the false self-cycle fix in matrixorigin#26925 contain real cycles between two different transactions updating the same primary key. These are genuine wait edges, so changing deadlock detection would hide the symptom rather than repair the lock order. ### Fix For UPDATEs with synchronous irregular-index maintenance, move the existing base/regular-index `LOCK_OP` before the shared row-image `SINK`: ```text final row image -> existing LOCK_OP -> shared SINK -> base MULTI_UPDATE -> irregular delete maintenance -> irregular insert maintenance ``` Every downstream consumer now receives a row only after its base lock has been acquired. A second transaction updating the same primary key waits at that gate before it can acquire a hidden-table lock. This PR does not add locks or change lock modes, commit-time release, RPC formats, or lockservice behavior. UPDATEs without synchronous irregular maintenance keep their existing plan shape. Async indexes remain CDC-only. ### Risk assessment - Normal UPDATEs do not enter the changed branch. - Synchronous IVF/full-text UPDATEs execute the same lock operation earlier in the same transaction; uncontended lock work and lock cardinality are unchanged. - Lock failure/cancellation now happens before hidden-table maintenance starts, reducing partial-work exposure. - Existing embedded full-text coverage verifies blocking, cancellation, rollback, retry, and hidden-index consistency. ### Tests - Added a deterministic planner regression for both IVF and full-text asserting that the shared maintenance sink depends on the base-table lock. - Added a control asserting ordinary UPDATE keeps `LOCK_OP` directly at the DML input. - Verified the new invariant fails on unfixed main and passes with this PR. - `go build -mod=readonly ./pkg/sql/plan` - `go vet -mod=readonly ./pkg/sql/plan` - `go test -count=1 ./pkg/sql/plan` - `go test -race -count=1 ./pkg/sql/plan` - Focused planner regressions with `-race -count=100` - `TestIssue26341CancelAndRetryFulltextUpdate` embedded-cluster regression Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…n#27144) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27142 Related to matrixorigin#27124, matrixorigin#26925, and matrixorigin#26518. ## What this PR does / why we need it: ### Root cause matrixorigin#26518 moved synchronous IVF/full-text UPDATE maintenance to separate top-level steps that consume a shared materialized final-row image. The pre-existing base-table `LOCK_OP` remained downstream of that materialization in only the main `MULTI_UPDATE` consumer. The main consumer and hidden-index consumers could therefore acquire locks independently: ```text T1: base row -> waits for IVF entries row T2: IVF entries row -> waits for base row ``` Production logs after the false self-cycle fix in matrixorigin#26925 contain real cycles between two different transactions updating the same primary key. These are genuine wait edges, so changing deadlock detection would hide the symptom rather than repair the lock order. ### Fix For UPDATEs with synchronous irregular-index maintenance, move the existing base/regular-index `LOCK_OP` before the shared row-image `SINK`: ```text final row image -> existing LOCK_OP -> shared SINK -> base MULTI_UPDATE -> irregular delete maintenance -> irregular insert maintenance ``` Every downstream consumer now receives a row only after its base lock has been acquired. A second transaction updating the same primary key waits at that gate before it can acquire a hidden-table lock. This PR does not add locks or change lock modes, commit-time release, RPC formats, or lockservice behavior. UPDATEs without synchronous irregular maintenance keep their existing plan shape. Async indexes remain CDC-only. ### Risk assessment - Normal UPDATEs do not enter the changed branch. - Synchronous IVF/full-text UPDATEs execute the same lock operation earlier in the same transaction; uncontended lock work and lock cardinality are unchanged. - Lock failure/cancellation now happens before hidden-table maintenance starts, reducing partial-work exposure. - Existing embedded full-text coverage verifies blocking, cancellation, rollback, retry, and hidden-index consistency. ### Tests - Added a deterministic planner regression for both IVF and full-text asserting that the shared maintenance sink depends on the base-table lock. - Added a control asserting ordinary UPDATE keeps `LOCK_OP` directly at the DML input. - Verified the new invariant fails on unfixed main and passes with this PR. - `go build -mod=readonly ./pkg/sql/plan` - `go vet -mod=readonly ./pkg/sql/plan` - `go test -count=1 ./pkg/sql/plan` - `go test -race -count=1 ./pkg/sql/plan` - Focused planner regressions with `-race -count=100` - `TestIssue26341CancelAndRetryFulltextUpdate` embedded-cluster regression Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…n#27144) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27142 Related to matrixorigin#27124, matrixorigin#26925, and matrixorigin#26518. ## What this PR does / why we need it: ### Root cause matrixorigin#26518 moved synchronous IVF/full-text UPDATE maintenance to separate top-level steps that consume a shared materialized final-row image. The pre-existing base-table `LOCK_OP` remained downstream of that materialization in only the main `MULTI_UPDATE` consumer. The main consumer and hidden-index consumers could therefore acquire locks independently: ```text T1: base row -> waits for IVF entries row T2: IVF entries row -> waits for base row ``` Production logs after the false self-cycle fix in matrixorigin#26925 contain real cycles between two different transactions updating the same primary key. These are genuine wait edges, so changing deadlock detection would hide the symptom rather than repair the lock order. ### Fix For UPDATEs with synchronous irregular-index maintenance, move the existing base/regular-index `LOCK_OP` before the shared row-image `SINK`: ```text final row image -> existing LOCK_OP -> shared SINK -> base MULTI_UPDATE -> irregular delete maintenance -> irregular insert maintenance ``` Every downstream consumer now receives a row only after its base lock has been acquired. A second transaction updating the same primary key waits at that gate before it can acquire a hidden-table lock. This PR does not add locks or change lock modes, commit-time release, RPC formats, or lockservice behavior. UPDATEs without synchronous irregular maintenance keep their existing plan shape. Async indexes remain CDC-only. ### Risk assessment - Normal UPDATEs do not enter the changed branch. - Synchronous IVF/full-text UPDATEs execute the same lock operation earlier in the same transaction; uncontended lock work and lock cardinality are unchanged. - Lock failure/cancellation now happens before hidden-table maintenance starts, reducing partial-work exposure. - Existing embedded full-text coverage verifies blocking, cancellation, rollback, retry, and hidden-index consistency. ### Tests - Added a deterministic planner regression for both IVF and full-text asserting that the shared maintenance sink depends on the base-table lock. - Added a control asserting ordinary UPDATE keeps `LOCK_OP` directly at the DML input. - Verified the new invariant fails on unfixed main and passes with this PR. - `go build -mod=readonly ./pkg/sql/plan` - `go vet -mod=readonly ./pkg/sql/plan` - `go test -count=1 ./pkg/sql/plan` - `go test -race -count=1 ./pkg/sql/plan` - Focused planner regressions with `-race -count=100` - `TestIssue26341CancelAndRetryFulltextUpdate` embedded-cluster regression Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27142
Related to #27124, #26925, and #26518.
What this PR does / why we need it:
Root cause
#26518 moved synchronous IVF/full-text UPDATE maintenance to separate top-level steps that consume a shared materialized final-row image. The pre-existing base-table
LOCK_OPremained downstream of that materialization in only the mainMULTI_UPDATEconsumer.The main consumer and hidden-index consumers could therefore acquire locks independently:
Production logs after the false self-cycle fix in #26925 contain real cycles between two different transactions updating the same primary key. These are genuine wait edges, so changing deadlock detection would hide the symptom rather than repair the lock order.
Fix
For UPDATEs with synchronous irregular-index maintenance, move the existing base/regular-index
LOCK_OPbefore the shared row-imageSINK:Every downstream consumer now receives a row only after its base lock has been acquired. A second transaction updating the same primary key waits at that gate before it can acquire a hidden-table lock.
This PR does not add locks or change lock modes, commit-time release, RPC formats, or lockservice behavior. UPDATEs without synchronous irregular maintenance keep their existing plan shape. Async indexes remain CDC-only.
Risk assessment
Tests
LOCK_OPdirectly at the DML input.go build -mod=readonly ./pkg/sql/plango vet -mod=readonly ./pkg/sql/plango test -count=1 ./pkg/sql/plango test -race -count=1 ./pkg/sql/plan-race -count=100TestIssue26341CancelAndRetryFulltextUpdateembedded-cluster regression