Skip to content

fix(logservice): preserve HAKeeper ID batch boundaries - #25911

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-25887-hakeeper-id-batch
Jul 21, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-25887-hakeeper-id-batch

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25887

What this PR does / why we need it:

HAKeeper returns an allocated batch as the inclusive range
[firstID, firstID+batchSize-1], and the managed client stores lastID
with that same inclusive meaning. The cache-consumption check previously treated
nextID == lastID as exhausted.

That boundary mismatch had three concrete effects:

  • batches larger than one skipped the final allocated ID;
  • a batch of one left nextID > lastID, so the client generated IDs locally
    without another HAKeeper allocation and could collide with another client;
  • AllocateIDByKeyWithBatch(..., 0) reached HAKeeper, where batch-1
    underflowed.

This change uses one inclusive cache invariant for shared and keyed allocation:
a cached ID is available only when nextID != 0 && nextID <= lastID. It also
rejects a zero keyed batch before preparing or calling the HAKeeper client.

No wire format, persisted HAKeeper state, allocation key, default batch size, or
public API signature changes. Regression tests cover complete batch consumption,
batch-one uniqueness across independent clients, and zero-batch rejection before
RPC.

Test

.agents/skills/mo-dev/scripts/mo-cgo-test -count=100 -timeout=5m -run '^(TestAllocateIDConsumesEntireBatch|TestAllocateBatchOneIDsRemainUniqueAcrossClients|TestAllocateIDByKeyRejectsZeroBatchBeforeRPC)$' ./pkg/logservice

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=20 -timeout=5m -run '^(TestAllocateIDConsumesEntireBatch|TestAllocateBatchOneIDsRemainUniqueAcrossClients|TestAllocateIDByKeyRejectsZeroBatchBeforeRPC)$' ./pkg/logservice

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/logservice

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=15m ./pkg/logservice

.agents/skills/mo-dev/scripts/mo-cgo-test -run '^$' -count=1 -timeout=5m ./pkg/cnservice

go build -mod=readonly ./pkg/logservice

go vet -mod=readonly ./pkg/logservice

git diff --check

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

@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels Jul 20, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 20, 2026
mergify Bot pushed a commit that referenced this pull request Jul 20, 2026
### Root cause

`TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows` measures the complete 8192-row JSON merge path with `testing.AllocsPerRun(3)`, even though its asserted invariant is wrapper allocation behavior. Under `-race`, that path also executes instrumented and race-build-only vector operations, so process-wide allocation deltas outside the intended invariant can be charged to the test.

The same package source passed the Ubuntu/x86 race UT in #25728, then failed an unrelated PR in #25911 with `one=1, many=45`. #25911 only changes the HAKeeper client and its tests, which run in a separate package test binary.

### Fix

Move the allocation-statistics-only test unchanged into a `!race` test file.

This keeps:

- the 1-row versus 8192-row allocation regression assertion in non-race builds;
- all JSON merge functional tests in both race and non-race builds;
- production code and JSON merge behavior unchanged.

### Validation

```text
.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=100 -timeout=10m \
-run '^TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows$' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$|PatchWrapperAllocationsDoNotScaleWithRows$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=30m \
./pkg/sql/plan/function
```

The race-built test list was also checked to confirm that only the allocation-statistics test is excluded.

Approved by: @XuPeng-SH

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

Codex automated review

The inclusive cache invariant matches HAKeeper’s allocation semantics for shared and keyed IDs, preserves batch-one uniqueness, and rejects keyed zero-sized batches before RPC. No correctness, compatibility, concurrency, resource, performance, or test-coverage regressions found. CI unit tests passed; local focused tests were blocked by missing prebuilt CGo artifacts.

@mergify

mergify Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-21 04:01 UTC · Rule: main · triggered by @LeftHandCold with the merge queue checkbox
  • 🚫 Left the queue — 2026-07-21 06:50 UTC · at da6d6095eda4ed4dfc4996c11a0aecb25d6522f2

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

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/iceberg-connector.yml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@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 allocator boundary fix and its full functional closure. The inclusive cache invariant is correct for shared and keyed allocations, zero-sized keyed batches are rejected before RPC, and focused/race/full-package verification passed. No merge-blocking findings.

@mergify mergify Bot added the queued label Jul 21, 2026
@mergify

mergify Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-21 16:24 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-07-21 18:05 UTC · at 14797881b3e2b9fb5a2471cfc15dd9eed2fbe47e · squash

This pull request spent 1 hour 41 minutes 30 seconds in the queue, including 1 hour 5 minutes 42 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection] (documentation)
  • github-review-decision = APPROVED [🛡 GitHub branch protection] (documentation)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64

@mergify mergify Bot removed the dequeued label Jul 21, 2026
@mergify
mergify Bot merged commit 647cbe6 into matrixorigin:main Jul 21, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label Jul 21, 2026
iamlinjunhong pushed a commit to iamlinjunhong/matrixone that referenced this pull request Jul 23, 2026
…n#25915)

### Root cause

`TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows` measures the complete 8192-row JSON merge path with `testing.AllocsPerRun(3)`, even though its asserted invariant is wrapper allocation behavior. Under `-race`, that path also executes instrumented and race-build-only vector operations, so process-wide allocation deltas outside the intended invariant can be charged to the test.

The same package source passed the Ubuntu/x86 race UT in matrixorigin#25728, then failed an unrelated PR in matrixorigin#25911 with `one=1, many=45`. matrixorigin#25911 only changes the HAKeeper client and its tests, which run in a separate package test binary.

### Fix

Move the allocation-statistics-only test unchanged into a `!race` test file.

This keeps:

- the 1-row versus 8192-row allocation regression assertion in non-race builds;
- all JSON merge functional tests in both race and non-race builds;
- production code and JSON merge behavior unchanged.

### Validation

```text
.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=100 -timeout=10m \
-run '^TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows$' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$|PatchWrapperAllocationsDoNotScaleWithRows$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=30m \
./pkg/sql/plan/function
```

The race-built test list was also checked to confirm that only the allocation-statistics test is excluded.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#25915)

### Root cause

`TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows` measures the complete 8192-row JSON merge path with `testing.AllocsPerRun(3)`, even though its asserted invariant is wrapper allocation behavior. Under `-race`, that path also executes instrumented and race-build-only vector operations, so process-wide allocation deltas outside the intended invariant can be charged to the test.

The same package source passed the Ubuntu/x86 race UT in matrixorigin#25728, then failed an unrelated PR in matrixorigin#25911 with `one=1, many=45`. matrixorigin#25911 only changes the HAKeeper client and its tests, which run in a separate package test binary.

### Fix

Move the allocation-statistics-only test unchanged into a `!race` test file.

This keeps:

- the 1-row versus 8192-row allocation regression assertion in non-race builds;
- all JSON merge functional tests in both race and non-race builds;
- production code and JSON merge behavior unchanged.

### Validation

```text
.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=100 -timeout=10m \
-run '^TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows$' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$|PatchWrapperAllocationsDoNotScaleWithRows$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=30m \
./pkg/sql/plan/function
```

The race-built test list was also checked to confirm that only the allocation-statistics test is excluded.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…25911)

HAKeeper returns an allocated batch as the inclusive range
`[firstID, firstID+batchSize-1]`, and the managed client stores `lastID`
with that same inclusive meaning. The cache-consumption check previously treated
`nextID == lastID` as exhausted.

That boundary mismatch had three concrete effects:

- batches larger than one skipped the final allocated ID;
- a batch of one left `nextID > lastID`, so the client generated IDs locally
without another HAKeeper allocation and could collide with another client;
- `AllocateIDByKeyWithBatch(..., 0)` reached HAKeeper, where `batch-1`
underflowed.

This change uses one inclusive cache invariant for shared and keyed allocation:
a cached ID is available only when `nextID != 0 && nextID <= lastID`. It also
rejects a zero keyed batch before preparing or calling the HAKeeper client.

No wire format, persisted HAKeeper state, allocation key, default batch size, or
public API signature changes. Regression tests cover complete batch consumption,
batch-one uniqueness across independent clients, and zero-batch rejection before
RPC.

Approved by: @gouhongshen, @volgariver6, @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#25915)

### Root cause

`TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows` measures the complete 8192-row JSON merge path with `testing.AllocsPerRun(3)`, even though its asserted invariant is wrapper allocation behavior. Under `-race`, that path also executes instrumented and race-build-only vector operations, so process-wide allocation deltas outside the intended invariant can be charged to the test.

The same package source passed the Ubuntu/x86 race UT in matrixorigin#25728, then failed an unrelated PR in matrixorigin#25911 with `one=1, many=45`. matrixorigin#25911 only changes the HAKeeper client and its tests, which run in a separate package test binary.

### Fix

Move the allocation-statistics-only test unchanged into a `!race` test file.

This keeps:

- the 1-row versus 8192-row allocation regression assertion in non-race builds;
- all JSON merge functional tests in both race and non-race builds;
- production code and JSON merge behavior unchanged.

### Validation

```text
.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=100 -timeout=10m \
-run '^TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows$' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$|PatchWrapperAllocationsDoNotScaleWithRows$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=30m \
./pkg/sql/plan/function
```

The race-built test list was also checked to confirm that only the allocation-statistics test is excluded.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…25911)

HAKeeper returns an allocated batch as the inclusive range
`[firstID, firstID+batchSize-1]`, and the managed client stores `lastID`
with that same inclusive meaning. The cache-consumption check previously treated
`nextID == lastID` as exhausted.

That boundary mismatch had three concrete effects:

- batches larger than one skipped the final allocated ID;
- a batch of one left `nextID > lastID`, so the client generated IDs locally
without another HAKeeper allocation and could collide with another client;
- `AllocateIDByKeyWithBatch(..., 0)` reached HAKeeper, where `batch-1`
underflowed.

This change uses one inclusive cache invariant for shared and keyed allocation:
a cached ID is available only when `nextID != 0 && nextID <= lastID`. It also
rejects a zero keyed batch before preparing or calling the HAKeeper client.

No wire format, persisted HAKeeper state, allocation key, default batch size, or
public API signature changes. Regression tests cover complete batch consumption,
batch-one uniqueness across independent clients, and zero-batch rejection before
RPC.

Approved by: @gouhongshen, @volgariver6, @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#25915)

### Root cause

`TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows` measures the complete 8192-row JSON merge path with `testing.AllocsPerRun(3)`, even though its asserted invariant is wrapper allocation behavior. Under `-race`, that path also executes instrumented and race-build-only vector operations, so process-wide allocation deltas outside the intended invariant can be charged to the test.

The same package source passed the Ubuntu/x86 race UT in matrixorigin#25728, then failed an unrelated PR in matrixorigin#25911 with `one=1, many=45`. matrixorigin#25911 only changes the HAKeeper client and its tests, which run in a separate package test binary.

### Fix

Move the allocation-statistics-only test unchanged into a `!race` test file.

This keeps:

- the 1-row versus 8192-row allocation regression assertion in non-race builds;
- all JSON merge functional tests in both race and non-race builds;
- production code and JSON merge behavior unchanged.

### Validation

```text
.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=100 -timeout=10m \
-run '^TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows$' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=20 -timeout=10m \
-run '^TestJsonMerge($|DepthValidation$|PatchWrapperAllocationsDoNotScaleWithRows$)' \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=20m \
./pkg/sql/plan/function

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=30m \
./pkg/sql/plan/function
```

The race-built test list was also checked to confirm that only the allocation-statistics test is excluded.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…25911)

HAKeeper returns an allocated batch as the inclusive range
`[firstID, firstID+batchSize-1]`, and the managed client stores `lastID`
with that same inclusive meaning. The cache-consumption check previously treated
`nextID == lastID` as exhausted.

That boundary mismatch had three concrete effects:

- batches larger than one skipped the final allocated ID;
- a batch of one left `nextID > lastID`, so the client generated IDs locally
without another HAKeeper allocation and could collide with another client;
- `AllocateIDByKeyWithBatch(..., 0)` reached HAKeeper, where `batch-1`
underflowed.

This change uses one inclusive cache invariant for shared and keyed allocation:
a cached ID is available only when `nextID != 0 && nextID <= lastID`. It also
rejects a zero keyed batch before preparing or calling the HAKeeper client.

No wire format, persisted HAKeeper state, allocation key, default batch size, or
public API signature changes. Regression tests cover complete batch consumption,
batch-one uniqueness across independent clients, and zero-batch rejection before
RPC.

Approved by: @gouhongshen, @volgariver6, @XuPeng-SH

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

kind/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants