Skip to content

fix(lockservice): balance row waiter and range ownership lifetimes - #30321

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/85fb92b036d31cc1e4db94af91471a957d47f888314ee4f9f05921905b9048f7
Oct 16, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/85fb92b036d31cc1e4db94af91471a957d47f888314ee4f9f05921905b9048f7

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 15, 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:

What this PR does / why we need it:

A notified multi-row request could restart its already acquired prefix, replace its waiter at the same offset, and strand the previous caller reference. Row requests joining a Shared range also recorded only one physical endpoint, so unlock could retain a finished transaction as a holder or leave an endpoint referencing released state.

Preserve the conflict offset and retire replaced waiters by identity before handling admission errors. Record the complete physical range pair before publishing a row request as a new holder, and clear the unlock pairing marker after processing each range. Normalize proxy handoff mutations from logical rows to physical lock groups so every selected replacement retains complete ownership, including when several cached rows have merged into one range. Existing queue admission, fairness, and notification rules are preserved. Ordinary row admission gains no additional lookup; joining a range resolves its paired endpoint once per new holder. Range grouping and replacement ledger staging apply only where a physical range or ownership handoff requires them. Conditional singleton-row cleanup avoids grouping and key copies, and completes under one table lock.

Validation on macOS arm64, Go 1.27.1, using the repository CGo wrapper:

  • Deterministic regressions cover repeated waits, cancellation, async continuation, a later deadlock rejection, endpoint boundaries, both unlock orders, mutation unlock, remote holders, proxy handoff across merged ranges, multiple replacements, and atomic bookkeeping failure/retry.
  • The original issue workload passes, including 100 runs under the race detector. Each new regression also passes 100 focused race runs.
  • Full pkg/lockservice tests pass in normal mode (68.534s) and race mode (71.176s).
  • Changed-package go vet, incremental golangci-lint (0 issues), formatting, and diff checks pass.

CI results are pending. The issue remains open for reporter verification after merge.

Review follow-up in 906ac10f45fabc7924038b77e552a52cd93d5f2c: keep ordinary conditional proxy row cleanup lightweight while preserving range normalization, first-mutation precedence, Skip, lost-response replay, and the commit timestamp frontier. Rebased onto official main a85d90efc996dfa2621211ec592be4721fd3cb61.

Current repair validation (Darwin/arm64, Go 1.27.1, repository CGo wrapper): full pkg/lockservice normal tests with -vet=all pass (67.532s), full race tests pass (72.376s), and each of five affected regressions passes 100 focused race runs. Incremental lint reports 0 issues; formatting and diff checks pass. Independent gpt-6-astra medium design and overall review, including rebase reconciliation, completed without unresolved material findings. Focused race100 evidence is reused across the rebase because its production and test inputs are unchanged; full package checks and benchmarks were refreshed.

The committed proxy benchmarks use two real services and time only Unlock after 64 separate Shared singleton acquisitions. Original PR unlock implementation and repaired implementation use identical benchmark inputs and rebased dependencies, one warm-up followed by five measured rounds of 200 operations per case:

Workload Median before → after Median allocations before → after Median bytes before → after
Singleton proxy rows 83.790 → 73.734 µs 736 → 274 79,104 → 50,113
Ordinary mutation-free unlock 1.364 → 1.439 µs 6 → 6 291 → 291
Merged-range cleanup 55.461 → 57.291 µs 352 → 353 56,874 → 53,844
Merged-range handoff 57.711 → 60.142 µs 385 → 385 60,680 → 57,626

Run .agents/skills/mo-dev/scripts/mo-cgo-test -run '^$' -bench '^(BenchmarkProxySingletonRowsUnlock|BenchmarkProxyMergedRangeUnlock|BenchmarkUnlockWithoutConflict)$' -benchtime=200x -count=1 for warm-up, then repeat with -count=5 for measured samples. These are local service/RPC measurements, not production SQL throughput. New-head CI remains pending after publication.

@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 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: d664560b22948860dfdbff26b0bea85c714f5fe6

Review completed. Read the assessment.

@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.

mo-bot review · mo-bot-local · review

Commit: d664560b22948860dfdbff26b0bea85c714f5fe6

Assessment: request_changes

Reviewed the complete delta and ownership lifecycle. The waiter and range-ledger fixes are coherent and pass functional and race validation, but mutation normalization introduces a confirmed performance regression in ordinary proxy row unlocks.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P2 pkg/lockservice/lock_table_local.go:481: With EnableRemoteLocalProxy enabled, a transaction accumulates 64 singleton Shared row locks and releases its last proxy memberships. The proxy sends conditional mutations with nil ReplaceTo even though there are no ranges or replacement holders.
    Impact: Every row now incurs grouping, key copying and additional table-lock work. The real two-service benchmark measured median Unlock latency increasing from 97.948 to 124.322 microseconds (+26.9%), allocations from 272 to 735, and bytes from 49,805 to 78,753 per operation. Preserve lightweight conditional row cleanup and reserve range grouping and replacement staging for cases that require them.
    Evidence: lock_table_proxy.go:456-482 establishes the production trigger. Identical base/head benchmarks used five samples of 200 operations, excluding acquisition from timing. Artifacts under /home/xupeng/.local/state/mo-bot/jobs/7832f4aba2391cc5dca14c5e/attempt-1: review_proxy_benchmark_test.go, proxy-benchmark-{base,head}.log, proxy-benchmark-summary.json; receipts checks/1792090519224317676-129.json and checks/1792090513540377864-4.json. Frozen-base overlay inputs and receipt/log hashes are reconciled in validation-audit.json.

Validation:

  • Isolation preflight passed. Verified 192 native inputs and 62 artifact hashes, repository build-owner execution, and unchanged source.

  • Full pkg/lockservice passed normally (67.088s) and under the race detector (70.393s).

  • Each of the six new regressions passed 100 independently selected race runs; go vet passed.

  • Frozen-base controls reproduced leaked waiter references and incomplete range bookkeeping; the candidate passed those regressions.

  • Ordinary mutation-free benchmark controls retained identical allocation counts and median latency changes between -4.1% and +1.6%.

  • Command/source/exit receipts, test selections and retained logs independently reconciled in attempt-1/validation-audit.json; detailed review recorded in attempt-1/review-analysis.md.

Limitations:

  • Benchmarks measure host service/RPC behavior, not production cluster throughput or SQL workload latency.

  • The linked issue body and original workload artifacts were not supplied. Author-only claims were not treated as executed evidence; supplied CI success metadata was not independently audited against raw CI logs.

@iamlinjunhong
iamlinjunhong force-pushed the codex/loom/develop/85fb92b036d31cc1e4db94af91471a957d47f888314ee4f9f05921905b9048f7 branch from d664560 to 906ac10 Compare October 16, 2026 01:05
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Oct 16, 2026
@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 906ac10f45fabc7924038b77e552a52cd93d5f2c

Review completed. Read the assessment.

@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.

mo-bot review · mo-bot-local · review

Commit: 906ac10f45fabc7924038b77e552a52cd93d5f2c

Assessment: approve

Reviewed the complete five-file delta, callers, lifecycle ownership, tests and supplied review concerns. Waiter retirement now follows resource identity, range holders receive complete cleanup ledgers, and proxy handoffs stage bookkeeping before publishing ownership. The design preserves existing responsibility owners and removes obsolete retry state. The previous allocation regression is resolved; the remaining measured proxy lookup cost is justified by correct range handling. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Verified the frozen head and unchanged source. Isolation preflight passed. Recovered native prerequisites through the current repository build owner and verified 192 inputs and 62 artifacts; earlier setup diagnostics were not counted as product-test results.

  • The complete pkg/lockservice suite passed normally with -vet=all in 67.147 seconds and under -race in 70.995 seconds: 662 root tests passed in each run. All seven new regression tests also passed 100 individually selected race repetitions each.

  • Frozen-base production-file overlays reproduced waiter-reference leaks and incomplete range bookkeeping with the candidate tests; the candidate passed both controls. Coverage includes cancellation, admission errors, bookkeeping failure, multiple replacements, retry and two-service proxy behavior.

  • Controlled component benchmarks closed the prior singleton allocation concern: 736 to 273 allocations and approximately 124 to 103 microseconds. Larger candidate/base comparisons measured singleton proxy unlock at 103.5 versus 95.6 microseconds (+8.2%), with equal allocation counts. Mutation-free unlock measured 3.024 versus 2.976 microseconds, with identical bytes and allocations. Range cleanup/handoff remained approximately unchanged against the prior implementation.

  • Reconciled 25 command/source/exit receipts with retained logs and overlay inputs in /home/xupeng/.local/state/mo-bot/jobs/4c67c638d0e7073c5a578216/attempt-1/validation-audit.json. The final audit also passed, receipt checks/1792117432298949464-2.json. Detailed design and coverage assessment is retained in review-record.json.

  • The supplied frozen-head CI snapshot reports successful substantive build, unit, static-analysis, coverage and multi-CN BVT checks; these status records supplement the independently executed local checks.

Limitations:

  • The linked issue's original body/workload artifacts and raw CI logs were not supplied; review used the supplied PR contract, comments, frozen sources and independently retained execution evidence.

  • Performance measurements are service/component benchmarks using controlled production-file overlays, not production SQL throughput measurements. Shared-row admission samples varied and showed a roughly 6% median increase without additional allocations.

  • No historical mixed-version deployment was executed; compatibility assessment covered unchanged protocol structures and existing version/binding guards.

@mergify mergify Bot added the queued label Oct 16, 2026
@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 02:28 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-10-16 04:48 UTC · at 4f4ae26313d5e018a463c01b039be1843208fb66

This pull request spent 2 hours 20 minutes 33 seconds in the queue, with no time running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • Mergify Merge Protections
  • CI Required

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@mergify mergify Bot added dequeued and removed queued labels Oct 16, 2026
@XuPeng-SH
XuPeng-SH merged commit ac55588 into matrixorigin:main Oct 16, 2026

This branch was previously deployed

1 inactive deployment
ci — 4f4ae263 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

dequeued kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants