Skip to content

[4.2-dev] fix(sql): preserve locking read retries across LIMIT - #30353

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
aptend:fix/4.2-dev-30245-locking-read-limit-retry
Oct 16, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
aptend:fix/4.2-dev-30245-locking-read-limit-retry

Conversation

@aptend

@aptend aptend commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • 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.

Backport matrixorigin#30268 to 4.2-dev to prevent LIMIT from suppressing a pending
locking-read retry. Keep the production callNonBlocking implementation
identical to main and preserve streaming execution without a conflict.

Adapt only tests to the release branch: provide the missing timestamp
waiter and waiter-count helpers, update the three existing retry timing
assertions, and retain the committed-row result for the RR session cells
confirmed by the unmodified no-LIMIT control.

(cherry picked from commit 493d8b8)
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete six-file change at ca03435 against 4.2-dev / 9adce30. No blocking findings.

The ownership/design is appropriate: LockOp retains the existing pending-retry and collect-all-locks policy, while Compile continues to own statement rollback/retry and blocking Output owns buffered results. The fix prevents a stale batch from reaching LIMIT and hiding the retry. It adds no parallel state machine, batch cache, transaction mechanism or configuration. Cancellation is checked through ChildrenCall/Exec on every pull; child/lock errors remain terminal and a later definition change retains the stronger retry error.

The production function is byte-identical to the merged main fix in #30268. I independently checked the release-specific RR behavior: with only the production function reverted to base, RC and RR no-LIMIT controls return 1, whereas both LIMIT cases incorrectly return 0. The head passes both. Preserving 4.2's behavior rather than importing main's RR conflict-error expectation is correct for this backport.

Independent local verification, macOS arm64 / Go 1.26.4:

  • Complete lockop package: 134 named passes in normal mode and 134 under race.
  • Seven affected/control test roots repeated separately under race, using measured 30-second budgets: 58 / 100 / 100 / 81 / 100 / 100 / 100 iterations; all passed.
  • All 11 public SQL scenarios passed normal, race and the adaptive focused race repeat, using the existing 3-CN fixture and real SQL connections to two CNs. Includes binary prepared reuse, session limit, shared lock, holder rollback, remote owner, RR settings and UPDATE after waiting.
  • Three reviewer-only boundary cases passed: conflict after an already buffered prefix, pending retry followed by a clean batch, and LIMIT stopping before a later unrelated conflict. Reverting production to base also fails the operator LIMIT regression while its uncontended control passes.
  • Exact BVT case ran twice in normal comparison mode on the same clean, exact-head service: 31/31 each, zero ignored/abnormal cases; database absence verified between and after runs. SQL and ISCP readiness checked; service exited cleanly.
  • Native/service build, gofmt/diff checks and configured incremental golangci-lint 2.6.2 over both affected packages passed; incremental SCA reported 0 issues.

Test additions reuse existing fixtures, minimal rows and a real waiter barrier, with distinct operator/protocol/cleanup oracles. Implementation delta is +22/-18, tests +534/-3, documentation 0. No technical review threads are currently outstanding.

Performance qualification: the uncontended path remains one-pull streaming, without new batch copies, retained buffers or RPCs. After a conflict, a LIMIT query can scan/lock additional remaining input to preserve the existing lock-before-retry policy. This is an explicit cost; I have not measured TP throughput or claimed zero cost in every workload. The separate lock-range efficiency issue #30253 is outside this fix.

The initial local SQL attempt failed before executing scenarios because another local test occupied the port range; rerunning with the shared port/admission namespace passed. That environment failure and intentional base negative controls were not counted as passing evidence. GitHub's full UT/SCA/BVT jobs are still running at review submission; this approval does not claim those merge gates are green.

This branch was previously deployed

1 inactive deployment
ci — ca034357 Deployed Oct 16, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants