Skip to content

fix(lockservice): batch multi-table remote unlocks - #27653

Merged
XuPeng-SH merged 3 commits into
mainfrom
fix/batch-remote-unlock-27628
Aug 26, 2026
Merged

XuPeng-SH merged 3 commits into
mainfrom
fix/batch-remote-unlock-27628

Conversation

@XuPeng-SH

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 #27628

What this PR does / why we need it:

The table-scoped remote-unlock correctness work after #26706 made every table on the same physical lock owner repeat the full transaction-closure lifecycle: one RPC, closure admission, active-generation lock, async-operation drain, bind validation, unlock, and ledger update. Under concurrent multi-table transactions this amplifies RPC queueing and owner CPU, matching the TPCC regression mechanism reported in #27628.

This PR adds a version-gated, bounded BatchUnlock protocol for ordinary direct remote tables:

  • group tables by physical owner and send at most 64 tables per RPC;
  • perform one owner-side closure admission, generation lock, and async drain per batch;
  • validate every table generation and resolve the complete release plan before the first irreversible unlock;
  • retain table-scoped Unlock for a single table, proxy handoff mutations, old owners, unknown capabilities, and any rejected/failed batch;
  • keep origin ledgers attached until batch acknowledgement, so a lost response safely falls back to idempotent table-scoped cleanup;
  • advertise support only through a successful Lock response under MORPC v30, preserving rolling-upgrade behavior.

The result is stronger than merely restoring the pre-#26706 behavior: a transaction touching eight tables on one owner now sends one physical cleanup RPC instead of one effective release plus seven no-op RPCs.

Correctness and failure-path validation

  • invalid sizes, duplicate tables, and mixed owners are rejected before closure admission;
  • a stale later bind rejects the whole batch before the valid prefix is released or the transaction is sealed;
  • a repeated batch after a lost response is an idempotent success;
  • a batch rejection leaves all origin ledgers intact and exercises the existing per-table fallback;
  • proxy/mutation semantics remain table-scoped;
  • the capability map is bounded by touched tables and cleared with the transaction;
  • service close remains the terminal cancellation owner, matching ordinary remote Unlock.

Validation

  • focused BatchUnlock and adjacent remote/proxy/unknown-commit regressions: pass
  • full pkg/lockservice suite: pass (97.0s)
  • full pkg/lockservice race suite: pass (100.8s)
  • BatchUnlock race stress, count=20: pass
  • compile checks for pkg/lockservice, pkg/pb/lock, and pkg/defines: pass
  • coverage: origin/main 87.5%, this PR 87.5%; no coverage decrease
  • new key-function coverage: 80.6%-100%

Eight-table remote-unlock A/B on the same binary and workload (100 iterations, 5 samples):

protocol median ns/op allocs/op
legacy v29 table-scoped 243,629 352
v30 bounded batch 54,218 95

That is about 4.5x faster with about 73% fewer allocations for the regression shape. The end-to-end test also asserts one real MORPC BatchUnlock and zero table-scoped Unlock calls.

TPCH reproduction note

On the requested 10.222.1.55 NVMe environment, stabilized 10 GB TPCH runs did not reproduce the reported +109% regression: the suspected commit averaged 23.784s versus 23.125s at the last-good commit (+2.85%), and q18 was effectively unchanged. A much larger slowdown immediately after data load was transient state/timing contamination rather than commit-specific. Therefore this PR claims and verifies the lockservice/TPCC root-cause fix; it should also help TPCH executions that hit the same concurrent multi-table remote-commit path, but it does not over-attribute the unreproduced +109% TPCH observation to this change.

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

@aptend aptend 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 exact head 8c483d7. Deep-reviewed the v30 capability handshake, bounded per-owner partitioning, owner-side generation validation and closure admission, partial/retry fallback, bind-ref/ledger finalization, protobuf/RPC routing, and the complete diff.

Validation: all five changed/new focused tests passed under race 100x each; the full pkg/lockservice suite passed both normally and under -race; go vet passed for pkg/lockservice and pkg/pb/lock; the fixed-count multi-table benchmark and protobuf package build passed.

@mergify

mergify Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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

  • Queue this pull request

@XuPeng-SH
XuPeng-SH merged commit 4fea829 into main Aug 26, 2026
18 of 23 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/batch-remote-unlock-27628 branch August 26, 2026 13:18
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27628

## What this PR does / why we need it:

The table-scoped remote-unlock correctness work after matrixorigin#26706 made every
table on the same physical lock owner repeat the full
transaction-closure lifecycle: one RPC, closure admission,
active-generation lock, async-operation drain, bind validation, unlock,
and ledger update. Under concurrent multi-table transactions this
amplifies RPC queueing and owner CPU, matching the TPCC regression
mechanism reported in matrixorigin#27628.

This PR adds a version-gated, bounded BatchUnlock protocol for ordinary
direct remote tables:

- group tables by physical owner and send at most 64 tables per RPC;
- perform one owner-side closure admission, generation lock, and async
drain per batch;
- validate every table generation and resolve the complete release plan
before the first irreversible unlock;
- retain table-scoped Unlock for a single table, proxy handoff
mutations, old owners, unknown capabilities, and any rejected/failed
batch;
- keep origin ledgers attached until batch acknowledgement, so a lost
response safely falls back to idempotent table-scoped cleanup;
- advertise support only through a successful Lock response under MORPC
v30, preserving rolling-upgrade behavior.

The result is stronger than merely restoring the pre-matrixorigin#26706 behavior: a
transaction touching eight tables on one owner now sends one physical
cleanup RPC instead of one effective release plus seven no-op RPCs.

## Correctness and failure-path validation

- invalid sizes, duplicate tables, and mixed owners are rejected before
closure admission;
- a stale later bind rejects the whole batch before the valid prefix is
released or the transaction is sealed;
- a repeated batch after a lost response is an idempotent success;
- a batch rejection leaves all origin ledgers intact and exercises the
existing per-table fallback;
- proxy/mutation semantics remain table-scoped;
- the capability map is bounded by touched tables and cleared with the
transaction;
- service close remains the terminal cancellation owner, matching
ordinary remote Unlock.

## Validation

- focused BatchUnlock and adjacent remote/proxy/unknown-commit
regressions: pass
- full pkg/lockservice suite: pass (97.0s)
- full pkg/lockservice race suite: pass (100.8s)
- BatchUnlock race stress, count=20: pass
- compile checks for pkg/lockservice, pkg/pb/lock, and pkg/defines: pass
- coverage: origin/main 87.5%, this PR 87.5%; no coverage decrease
- new key-function coverage: 80.6%-100%

Eight-table remote-unlock A/B on the same binary and workload (100
iterations, 5 samples):

| protocol | median ns/op | allocs/op |
| --- | ---: | ---: |
| legacy v29 table-scoped | 243,629 | 352 |
| v30 bounded batch | 54,218 | 95 |

That is about 4.5x faster with about 73% fewer allocations for the
regression shape. The end-to-end test also asserts one real MORPC
BatchUnlock and zero table-scoped Unlock calls.

## TPCH reproduction note

On the requested 10.222.1.55 NVMe environment, stabilized 10 GB TPCH
runs did not reproduce the reported +109% regression: the suspected
commit averaged 23.784s versus 23.125s at the last-good commit (+2.85%),
and q18 was effectively unchanged. A much larger slowdown immediately
after data load was transient state/timing contamination rather than
commit-specific. Therefore this PR claims and verifies the
lockservice/TPCC root-cause fix; it should also help TPCH executions
that hit the same concurrent multi-table remote-commit path, but it does
not over-attribute the unreproduced +109% TPCH observation to this
change.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27628

## What this PR does / why we need it:

The table-scoped remote-unlock correctness work after matrixorigin#26706 made every
table on the same physical lock owner repeat the full
transaction-closure lifecycle: one RPC, closure admission,
active-generation lock, async-operation drain, bind validation, unlock,
and ledger update. Under concurrent multi-table transactions this
amplifies RPC queueing and owner CPU, matching the TPCC regression
mechanism reported in matrixorigin#27628.

This PR adds a version-gated, bounded BatchUnlock protocol for ordinary
direct remote tables:

- group tables by physical owner and send at most 64 tables per RPC;
- perform one owner-side closure admission, generation lock, and async
drain per batch;
- validate every table generation and resolve the complete release plan
before the first irreversible unlock;
- retain table-scoped Unlock for a single table, proxy handoff
mutations, old owners, unknown capabilities, and any rejected/failed
batch;
- keep origin ledgers attached until batch acknowledgement, so a lost
response safely falls back to idempotent table-scoped cleanup;
- advertise support only through a successful Lock response under MORPC
v30, preserving rolling-upgrade behavior.

The result is stronger than merely restoring the pre-matrixorigin#26706 behavior: a
transaction touching eight tables on one owner now sends one physical
cleanup RPC instead of one effective release plus seven no-op RPCs.

## Correctness and failure-path validation

- invalid sizes, duplicate tables, and mixed owners are rejected before
closure admission;
- a stale later bind rejects the whole batch before the valid prefix is
released or the transaction is sealed;
- a repeated batch after a lost response is an idempotent success;
- a batch rejection leaves all origin ledgers intact and exercises the
existing per-table fallback;
- proxy/mutation semantics remain table-scoped;
- the capability map is bounded by touched tables and cleared with the
transaction;
- service close remains the terminal cancellation owner, matching
ordinary remote Unlock.

## Validation

- focused BatchUnlock and adjacent remote/proxy/unknown-commit
regressions: pass
- full pkg/lockservice suite: pass (97.0s)
- full pkg/lockservice race suite: pass (100.8s)
- BatchUnlock race stress, count=20: pass
- compile checks for pkg/lockservice, pkg/pb/lock, and pkg/defines: pass
- coverage: origin/main 87.5%, this PR 87.5%; no coverage decrease
- new key-function coverage: 80.6%-100%

Eight-table remote-unlock A/B on the same binary and workload (100
iterations, 5 samples):

| protocol | median ns/op | allocs/op |
| --- | ---: | ---: |
| legacy v29 table-scoped | 243,629 | 352 |
| v30 bounded batch | 54,218 | 95 |

That is about 4.5x faster with about 73% fewer allocations for the
regression shape. The end-to-end test also asserts one real MORPC
BatchUnlock and zero table-scoped Unlock calls.

## TPCH reproduction note

On the requested 10.222.1.55 NVMe environment, stabilized 10 GB TPCH
runs did not reproduce the reported +109% regression: the suspected
commit averaged 23.784s versus 23.125s at the last-good commit (+2.85%),
and q18 was effectively unchanged. A much larger slowdown immediately
after data load was transient state/timing contamination rather than
commit-specific. Therefore this PR claims and verifies the
lockservice/TPCC root-cause fix; it should also help TPCH executions
that hit the same concurrent multi-table remote-commit path, but it does
not over-attribute the unreproduced +109% TPCH observation to this
change.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27628

## What this PR does / why we need it:

The table-scoped remote-unlock correctness work after matrixorigin#26706 made every
table on the same physical lock owner repeat the full
transaction-closure lifecycle: one RPC, closure admission,
active-generation lock, async-operation drain, bind validation, unlock,
and ledger update. Under concurrent multi-table transactions this
amplifies RPC queueing and owner CPU, matching the TPCC regression
mechanism reported in matrixorigin#27628.

This PR adds a version-gated, bounded BatchUnlock protocol for ordinary
direct remote tables:

- group tables by physical owner and send at most 64 tables per RPC;
- perform one owner-side closure admission, generation lock, and async
drain per batch;
- validate every table generation and resolve the complete release plan
before the first irreversible unlock;
- retain table-scoped Unlock for a single table, proxy handoff
mutations, old owners, unknown capabilities, and any rejected/failed
batch;
- keep origin ledgers attached until batch acknowledgement, so a lost
response safely falls back to idempotent table-scoped cleanup;
- advertise support only through a successful Lock response under MORPC
v30, preserving rolling-upgrade behavior.

The result is stronger than merely restoring the pre-matrixorigin#26706 behavior: a
transaction touching eight tables on one owner now sends one physical
cleanup RPC instead of one effective release plus seven no-op RPCs.

## Correctness and failure-path validation

- invalid sizes, duplicate tables, and mixed owners are rejected before
closure admission;
- a stale later bind rejects the whole batch before the valid prefix is
released or the transaction is sealed;
- a repeated batch after a lost response is an idempotent success;
- a batch rejection leaves all origin ledgers intact and exercises the
existing per-table fallback;
- proxy/mutation semantics remain table-scoped;
- the capability map is bounded by touched tables and cleared with the
transaction;
- service close remains the terminal cancellation owner, matching
ordinary remote Unlock.

## Validation

- focused BatchUnlock and adjacent remote/proxy/unknown-commit
regressions: pass
- full pkg/lockservice suite: pass (97.0s)
- full pkg/lockservice race suite: pass (100.8s)
- BatchUnlock race stress, count=20: pass
- compile checks for pkg/lockservice, pkg/pb/lock, and pkg/defines: pass
- coverage: origin/main 87.5%, this PR 87.5%; no coverage decrease
- new key-function coverage: 80.6%-100%

Eight-table remote-unlock A/B on the same binary and workload (100
iterations, 5 samples):

| protocol | median ns/op | allocs/op |
| --- | ---: | ---: |
| legacy v29 table-scoped | 243,629 | 352 |
| v30 bounded batch | 54,218 | 95 |

That is about 4.5x faster with about 73% fewer allocations for the
regression shape. The end-to-end test also asserts one real MORPC
BatchUnlock and zero table-scoped Unlock calls.

## TPCH reproduction note

On the requested 10.222.1.55 NVMe environment, stabilized 10 GB TPCH
runs did not reproduce the reported +109% regression: the suspected
commit averaged 23.784s versus 23.125s at the last-good commit (+2.85%),
and q18 was effectively unchanged. A much larger slowdown immediately
after data load was transient state/timing contamination rather than
commit-specific. Therefore this PR claims and verifies the
lockservice/TPCC root-cause fix; it should also help TPCH executions
that hit the same concurrent multi-table remote-commit path, but it does
not over-attribute the unreproduced +109% TPCH observation to this
change.

This branch was previously deployed

1 inactive deployment
ci — 4649ed8d Deployed Aug 26, 2026 by XuPeng-SH via Matrixone Utils CI / Coverage #48472
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 kind/enhancement kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(S1): TPCH 10G 查询耗时翻倍 (+109%),二分定位到 #26706 (fix(lock): preserve bounded ranges for large DML batches)

4 participants