Repository navigation
fix(sql): preserve locking read retries across LIMIT - #30268
Conversation
Drain the remaining lock input after a retry becomes necessary, acquiring its locks without forwarding obsolete batches. This keeps batched lock acquisition while preventing LIMIT from suppressing the pending retry error. Add operator, SQL protocol, and distributed regressions for limited locking reads, prepared reuse, session row limits, cancellation, and remote lock owners.
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? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 886048dc196d2553aa43ae4cf6e1465201570ef9
Assessment: approve
Reviewed the complete six-file delta and affected callers. The fix keeps retry ownership in LockOp, prevents LIMIT from hiding pending retries, and preserves uncontended streaming and cleanup contracts. No actionable defect remains.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Complete LockOp normal and race suites each passed 196 named tests without failures or skips.
-
All seven affected operator tests passed 100 race repetitions each. The original production code failed the new LIMIT regression as expected.
-
The two-CN SQL regression passed all 11 scenarios normally, with race detection, and in four repeated race runs.
-
Reconciled 17 command/source/exit/log records; verified preflight, native provenance, formatting, diff checks and unchanged source. Evidence: /home/xupeng/.local/state/mo-bot/jobs/0cbc8a1bb3beeac39bd9e008/attempt-1/evidence-audit.json.
-
Frozen candidate CI reports successful UT, SCA, coverage, shared build and both BVT groups. Reviewed the added SQL/result pair and its group selection.
Limitations:
-
Individual mo-tester logs and the linked issue body were not supplied. BVT success relies on the frozen CI snapshot, supplemented by locally executed public SQL regressions.
-
No performance benchmark was run. Uncontended streaming is tested; conflict-only draining deliberately completes the existing lock-acquisition policy.
Merge Queue Status
This pull request spent 44 minutes 17 seconds in the queue, with no time running CI. ReasonPull request #30268 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. Waiting for any of
All conditions
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 #30245 (4.2 release line). ## What this PR does / why we need it: Backport #30268 (main commit `493d8b8181b7d74bed91e360874a3dd35223f276`) to `4.2-dev`. A locking read with `LIMIT 1` can return an obsolete row after waiting for a concurrent update because LIMIT stops pulling before LockOp reports its pending retry. The backport drains and locks the remaining input without forwarding obsolete batches, then returns the retry. Uncontended execution remains streaming. The production function is identical to the merged main fix; no other production code changes. Release compatibility adaptations are limited to tests: add the timestamp-waiter and actual-waiter probes absent on this branch, update the three existing retry-timing expectations, and retain 4.2's committed-row result for the RR session cases. The unchanged release source passes both no-LIMIT controls but fails both LIMIT controls with old value `0` instead of `1`; this backport passes all 11 SQL scenarios. Main-only definition-fence tests are not introduced. Validation on Linux amd64 / Go 1.26.4, based on `9adce306ff4efa9754fd8d9cce051386a1eb0190`: - Built task-owned native libraries with `make -j4 cgo` and used the repository CGo test wrapper. - Complete LockOp normal and race suites: 134 named passes each. Adaptive focused race repetitions: new operator root 66, the two conflict roots 100 each, and the row-version root 81; all passed. - Operator LIMIT regression fails against the exact original release production source. Public SQL negative controls independently confirm RC and RR session no-LIMIT reads return `1`, while LIMIT reads return `0` before the fix. - SQL regression: all 11 scenarios pass normally. All 11 scenarios also pass with race detection and in the separate adaptive race run (measured 17.13 s, 30 s budget, count=1). - Distributed `locking_read_limit_retry.sql`: normal mo-tester comparison twice on the same fresh instance, 31/31 statements each; database removal verified between runs and after the second run; fixture stopped. - Incremental configured golangci-lint v2.6.2, `go vet`, gofmt, and diff checks passed for the affected packages. Tradeoff: a pending retry finishes acquiring the remaining input locks, so a conflicting limited query can process additional input. This preserves the existing lock-acquisition policy. Full release CI remains pending; this PR does not itself publish a new 4.2.x release.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #30245
What this PR does / why we need it:
SELECT ... LIMIT 1 FOR UPDATEcan return an obsolete row after waiting for a concurrent update. LockOp saved the required retry error until child EOF, but LIMIT could stop pulling input before that error was returned.Once a retry is needed, LockOp now consumes the remaining input and acquires its locks without forwarding obsolete batches, then reports the retry error. This preserves the existing collect-all-locks retry policy and keeps uncontended execution streaming. Child errors and cancellation terminate draining; a later definition change retains its plan-rebuild error priority.
Validation:
-race; the new operator test and six affected existing tests each pass 100 race repetitions.TestIssue30245LockingReadRetriesBeforeLimitpasses normally and with-race -count=3, covering 11 scenarios including prepared reuse, implicit session limits, FOR SHARE, cross-CN lock ownership, rollback, RR conflicts, and UPDATE after waiting.locking_read_limit_retry.sqlpasses normal mo-tester comparison twice on the same fresh instance: 31/31 statements each run, with teardown verified before reuse.go vet, golangci-lint v2.14.0, gofmt, and diff checks pass.-short -covermode=set(15,404 named passes, 2 existing skips). Covered-fulltext regressions also pass with-raceand with CI'smatrixone_testcoverage tag. The complete LockOp race suite and the 11-scenario SQL race regression pass again.