Skip to content

fix(lockservice): cover float table-lock keyspace - #28165

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix-27947-float-lock-domain
Sep 4, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix-27947-float-lock-domain

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What

  • generate FLOAT and DOUBLE table-lock endpoints over the complete Packer key domain
  • use Packer-compatible total ordering when oversized float row-lock batches are coarsened
  • admit FLOAT and DOUBLE wherever the shared full-domain table-range capability is required
  • add planner, LOAD promotion, encoder, lock fetcher, and two-CN transaction regressions

Why

The previous table range used finite numeric endpoints. It excluded infinities and NaN representations whose encoded keys lie outside that interval. The generic row-range coarsener also used ordinary float comparisons, under which NaN is unordered and signed zero compares equal, so a large batch could omit physically distinct keys.

The new comparator applies the same sign-bit transformation as Packer. The selected raw endpoint patterns encode to an all-zero and all-one payload, covering every IEEE-754 bit representation without changing the key encoding or wire format.

Fixes #27947.

Behavioral impact

  • shared table-lock fallback now safely covers FLOAT and DOUBLE special values
  • unrestricted large UPDATE plans can use the existing table-lock fast path for float primary keys
  • runtime row-lock upgrade and direct table locking use the same complete range
  • LOAD unique-index promotion can safely admit float base or single-column hidden primary keys
  • the coarsening hot path remains allocation-free and table ranges still contain exactly two keys

Test plan

  • GOWORK=off go test -mod=readonly -count=1 -timeout=5m ./pkg/container/types
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/sql/colexec
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/sql/colexec/lockop
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/sql/plan
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/sql/compile
  • exact two-CN SQL regression for FLOAT and DOUBLE, local and remote lock owners, and -Inf, +Inf, and NaN keys
  • exact concurrency regression under -race -count=2
  • -vet=all compile checks for all changed packages
  • git diff --check and gofmt verification

QA notes

  1. Create FLOAT and DOUBLE primary-key tables with enough rows to cross max-row-lock-count.
  2. Include finite values, both infinities, signed zeroes, and multiple NaN representations where input tooling permits them.
  3. Hold SELECT ... FOR SHARE in an explicit transaction.
  4. From another session, verify updates of every special key block until the holder commits, then resume and affect exactly the intended rows.
  5. Repeat with the lock-table owner local to the holder CN and remote through another CN.

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

Use the physical tuple-key order when coarsening FLOAT and DOUBLE lock rows, and generate full-domain table range endpoints that include infinities, signed zeroes, and every NaN representation. Enable the shared planner capability for float keyspaces and add unit, planner, LOAD, and multi-CN transaction regressions for matrixorigin#27947.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deep review at exact HEAD 4d7e922: no blocking findings; APPROVE-equivalent.

The fix is first-principles correct: lock ranges compare Packer bytes, so FLOAT/DOUBLE coarsening must use the same total bit order rather than SQL float comparison. The new comparator matches Packer encoding, and the all-zero/all-ones payload endpoints cover every finite value, +/-Inf, signed zero, and every NaN sign/payload. Planner admission, runtime coarsening, LOAD unique-index promotion, local ownership, remote proxy ownership, wait, release, and resume are aligned.

Performance risk is low: the comparator is only used on the over-budget coarsening path; normal row-lock batches keep the existing fast path. Coarsening remains O(n) with constant extra state and table-lock requests still contain two endpoints.

Counterexamples covered by focused tests include first-element NaN, positive/negative NaNs, payload differences, +/-Inf, +/-0, filtered/null rows, local/remote CN ownership, blocked special-key UPDATEs, commit wakeup, and race repetition. Validation passed:

  • Packer/comparator and FLOAT/DOUBLE fetch/coarsening tests
  • planner and LOAD admission tests
  • TestIssue27947FloatTableLockCoversSpecialKeys (two CNs)
  • the same integration test with -race -count=2
  • git diff --check

Non-blocking maintainability note: the integration fixture hardcodes 10002 rows, implicitly matching the current MaxLockRowCount=10000; deriving rows from the runtime budget would make it resilient to future config changes.

No formal APPROVE event is possible because the PR author and reviewer account are both XuPeng-SH.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact HEAD 4d7e922. No blocking findings.

The implementation closes the full physical FLOAT/DOUBLE key domain consistently: the all-zero/all-one Packer payload endpoints cover finite values, infinities, signed zeroes, and all NaN payloads, while over-budget row coarsening now uses the same Packer total order. Planner admission, LOAD promotion, direct table locking, and runtime upgrade all converge on the same fetcher.

The two-CN regression genuinely exceeds the configured 10,000-row lock budget and covers local ownership, remote proxy ownership, special-key conflicts, wait, commit release, and waiter resumption. Normal row-lock behavior remains unchanged; the new comparison is only on the over-budget coarsening path and remains O(n) with constant extra state.

Q1 ownership/cleanup: unchanged and bounded. Q2 waits: context-bounded and commit/rollback releases are covered. Q3 growth: coarsening still emits at most two range endpoints.

Validation reviewed: focused comparator/fetch/planner/LOAD tests, two-CN issue regression and author-reported race repetition; exact-head shared build and PR validation are green. Remaining repository CI is still in progress.

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

Deep review completed at exact HEAD 4d7e922. No blocking findings.\n\nI verified the change against the physical lock-key invariant: FLOAT/DOUBLE range endpoints encode to the type prefix plus all-zero/all-one payloads, so they cover every IEEE-754 bit pattern (including both infinities, signed zeroes, and all NaN signs/payloads). The new total-order comparators exactly mirror Packer byte ordering, which also makes oversized-batch min/max coarsening conservative when NaNs are present. Planner admission, LOAD unique-index promotion, and runtime fetch support stay aligned through the shared capability predicate.\n\nUnhappy-path/lifecycle review found no new ownership, cancellation, waiter, or growth hazards: the change only affects key selection, keeps the existing bounded two-endpoint range representation, and leaves wait/release handling unchanged.\n\nIndependent validation passed: git diff --check; focused types, lockop, planner, and compile tests; plus a temporary deterministic 100,000-pair raw-bit check for each float width comparing the new comparator directly with Packer byte order. The temporary test was removed afterward.

@mergify

mergify Bot commented Sep 4, 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 425da14 into matrixorigin:main Sep 4, 2026
15 of 18 checks passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What

- generate FLOAT and DOUBLE table-lock endpoints over the complete
Packer key domain
- use Packer-compatible total ordering when oversized float row-lock
batches are coarsened
- admit FLOAT and DOUBLE wherever the shared full-domain table-range
capability is required
- add planner, LOAD promotion, encoder, lock fetcher, and two-CN
transaction regressions

## Why

The previous table range used finite numeric endpoints. It excluded
infinities and NaN representations whose encoded keys lie outside that
interval. The generic row-range coarsener also used ordinary float
comparisons, under which NaN is unordered and signed zero compares
equal, so a large batch could omit physically distinct keys.

The new comparator applies the same sign-bit transformation as Packer.
The selected raw endpoint patterns encode to an all-zero and all-one
payload, covering every IEEE-754 bit representation without changing the
key encoding or wire format.

Fixes matrixorigin#27947.

## Behavioral impact

- shared table-lock fallback now safely covers FLOAT and DOUBLE special
values
- unrestricted large UPDATE plans can use the existing table-lock fast
path for float primary keys
- runtime row-lock upgrade and direct table locking use the same
complete range
- LOAD unique-index promotion can safely admit float base or
single-column hidden primary keys
- the coarsening hot path remains allocation-free and table ranges still
contain exactly two keys

## Test plan

- `GOWORK=off go test -mod=readonly -count=1 -timeout=5m
./pkg/container/types`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/colexec`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/colexec/lockop`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/plan`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/compile`
- exact two-CN SQL regression for FLOAT and DOUBLE, local and remote
lock owners, and -Inf, +Inf, and NaN keys
- exact concurrency regression under `-race -count=2`
- `-vet=all` compile checks for all changed packages
- `git diff --check` and gofmt verification

## QA notes

1. Create FLOAT and DOUBLE primary-key tables with enough rows to cross
`max-row-lock-count`.
2. Include finite values, both infinities, signed zeroes, and multiple
NaN representations where input tooling permits them.
3. Hold `SELECT ... FOR SHARE` in an explicit transaction.
4. From another session, verify updates of every special key block until
the holder commits, then resume and affect exactly the intended rows.
5. Repeat with the lock-table owner local to the holder CN and remote
through another CN.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What

- generate FLOAT and DOUBLE table-lock endpoints over the complete
Packer key domain
- use Packer-compatible total ordering when oversized float row-lock
batches are coarsened
- admit FLOAT and DOUBLE wherever the shared full-domain table-range
capability is required
- add planner, LOAD promotion, encoder, lock fetcher, and two-CN
transaction regressions

## Why

The previous table range used finite numeric endpoints. It excluded
infinities and NaN representations whose encoded keys lie outside that
interval. The generic row-range coarsener also used ordinary float
comparisons, under which NaN is unordered and signed zero compares
equal, so a large batch could omit physically distinct keys.

The new comparator applies the same sign-bit transformation as Packer.
The selected raw endpoint patterns encode to an all-zero and all-one
payload, covering every IEEE-754 bit representation without changing the
key encoding or wire format.

Fixes matrixorigin#27947.

## Behavioral impact

- shared table-lock fallback now safely covers FLOAT and DOUBLE special
values
- unrestricted large UPDATE plans can use the existing table-lock fast
path for float primary keys
- runtime row-lock upgrade and direct table locking use the same
complete range
- LOAD unique-index promotion can safely admit float base or
single-column hidden primary keys
- the coarsening hot path remains allocation-free and table ranges still
contain exactly two keys

## Test plan

- `GOWORK=off go test -mod=readonly -count=1 -timeout=5m
./pkg/container/types`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/colexec`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/colexec/lockop`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/plan`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/compile`
- exact two-CN SQL regression for FLOAT and DOUBLE, local and remote
lock owners, and -Inf, +Inf, and NaN keys
- exact concurrency regression under `-race -count=2`
- `-vet=all` compile checks for all changed packages
- `git diff --check` and gofmt verification

## QA notes

1. Create FLOAT and DOUBLE primary-key tables with enough rows to cross
`max-row-lock-count`.
2. Include finite values, both infinities, signed zeroes, and multiple
NaN representations where input tooling permits them.
3. Hold `SELECT ... FOR SHARE` in an explicit transaction.
4. From another session, verify updates of every special key block until
the holder commits, then resume and affect exactly the intended rows.
5. Repeat with the lock-table owner local to the holder CN and remote
through another CN.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What

- generate FLOAT and DOUBLE table-lock endpoints over the complete
Packer key domain
- use Packer-compatible total ordering when oversized float row-lock
batches are coarsened
- admit FLOAT and DOUBLE wherever the shared full-domain table-range
capability is required
- add planner, LOAD promotion, encoder, lock fetcher, and two-CN
transaction regressions

## Why

The previous table range used finite numeric endpoints. It excluded
infinities and NaN representations whose encoded keys lie outside that
interval. The generic row-range coarsener also used ordinary float
comparisons, under which NaN is unordered and signed zero compares
equal, so a large batch could omit physically distinct keys.

The new comparator applies the same sign-bit transformation as Packer.
The selected raw endpoint patterns encode to an all-zero and all-one
payload, covering every IEEE-754 bit representation without changing the
key encoding or wire format.

Fixes matrixorigin#27947.

## Behavioral impact

- shared table-lock fallback now safely covers FLOAT and DOUBLE special
values
- unrestricted large UPDATE plans can use the existing table-lock fast
path for float primary keys
- runtime row-lock upgrade and direct table locking use the same
complete range
- LOAD unique-index promotion can safely admit float base or
single-column hidden primary keys
- the coarsening hot path remains allocation-free and table ranges still
contain exactly two keys

## Test plan

- `GOWORK=off go test -mod=readonly -count=1 -timeout=5m
./pkg/container/types`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/colexec`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/colexec/lockop`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/plan`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m
./pkg/sql/compile`
- exact two-CN SQL regression for FLOAT and DOUBLE, local and remote
lock owners, and -Inf, +Inf, and NaN keys
- exact concurrency regression under `-race -count=2`
- `-vet=all` compile checks for all changed packages
- `git diff --check` and gofmt verification

## QA notes

1. Create FLOAT and DOUBLE primary-key tables with enough rows to cross
`max-row-lock-count`.
2. Include finite values, both infinities, signed zeroes, and multiple
NaN representations where input tooling permits them.
3. Hold `SELECT ... FOR SHARE` in an explicit transaction.
4. From another session, verify updates of every special key block until
the holder commits, then resume and affect exactly the intended rows.
5. Repeat with the lock-table owner local to the holder CN and remote
through another CN.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: shared table-lock fallback does not cover FLOAT/DOUBLE Inf and NaN keys

4 participants