Skip to content

fix(hakeeper): preserve CN load across batch scheduling - #26537

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-25833-hakeeper-batch-balance
Aug 1, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/issue-25833-hakeeper-batch-balance

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

What this PR does / why we need it:

HAKeeper rebuilt a filtered CN pool for every Created task, but that pool reset the Running-task frequencies. A successful allocation then updated only the temporary pool, so the next task in the same scheduling round saw the same stale load snapshot and could select the same CN repeatedly.

This PR:

  • preserves source frequencies when filtering a CN pool;
  • selects from the per-task eligible view but records a successful allocation in the shared round pool;
  • leaves failed allocations out of the load count;
  • adds regressions for existing load, batch scheduling, label/resource filtering, and allocation failure.

The change does not alter label/resource eligibility, expired-CN handling, task persistence, timeout behavior, or tie-breaking.

Tested with:

./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -run '<each focused regression>' ./pkg/hakeeper/task

./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 ./pkg/hakeeper/task

./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -run '^TestTaskSchedulerCan(ScheduleTasksToCNs|ReScheduleExpiredTasks)$' ./pkg/logservice

go build -mod=readonly ./pkg/hakeeper/task

go vet -mod=readonly ./pkg/hakeeper/task

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

Approved exact head 37bcb74 after full scheduling-closure review.

The fix preserves the running-task frequency in each eligible candidate view and records only successful allocations in the shared per-round pool, so later Created tasks observe earlier reservations. Label/resource/expiry filtering remains unchanged. The new selectCNs construction also replaces repeated heap insertion with a linear copy plus heap.Init.

Reviewed ordinary, filtered, existing-load, allocation-failure, expired-CN, and dependent logservice paths. No remaining correctness, lifecycle, unbounded-growth, or material performance blocker found.

Local validation on the exact head: four focused regressions each passed under race at count=100; the full pkg/hakeeper/task package passed under race; dependent task-scheduler logservice regressions passed under race; scoped go vet passed.

@XuPeng-SH
XuPeng-SH merged commit 3e9ad81 into matrixorigin:main Aug 1, 2026
23 checks passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26537)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25833

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

HAKeeper rebuilt a filtered CN pool for every Created task, but that
pool reset the Running-task frequencies. A successful allocation then
updated only the temporary pool, so the next task in the same scheduling
round saw the same stale load snapshot and could select the same CN
repeatedly.

This PR:

- preserves source frequencies when filtering a CN pool;
- selects from the per-task eligible view but records a successful
allocation in the shared round pool;
- leaves failed allocations out of the load count;
- adds regressions for existing load, batch scheduling, label/resource
filtering, and allocation failure.

The change does not alter label/resource eligibility, expired-CN
handling, task persistence, timeout behavior, or tie-breaking.

Tested with:

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -run
'<each focused regression>' ./pkg/hakeeper/task`

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1
./pkg/hakeeper/task`

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -run
'^TestTaskSchedulerCan(ScheduleTasksToCNs|ReScheduleExpiredTasks)$'
./pkg/logservice`

`go build -mod=readonly ./pkg/hakeeper/task`

`go vet -mod=readonly ./pkg/hakeeper/task`

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26537)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25833

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

HAKeeper rebuilt a filtered CN pool for every Created task, but that
pool reset the Running-task frequencies. A successful allocation then
updated only the temporary pool, so the next task in the same scheduling
round saw the same stale load snapshot and could select the same CN
repeatedly.

This PR:

- preserves source frequencies when filtering a CN pool;
- selects from the per-task eligible view but records a successful
allocation in the shared round pool;
- leaves failed allocations out of the load count;
- adds regressions for existing load, batch scheduling, label/resource
filtering, and allocation failure.

The change does not alter label/resource eligibility, expired-CN
handling, task persistence, timeout behavior, or tie-breaking.

Tested with:

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -run
'<each focused regression>' ./pkg/hakeeper/task`

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1
./pkg/hakeeper/task`

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -run
'^TestTaskSchedulerCan(ScheduleTasksToCNs|ReScheduleExpiredTasks)$'
./pkg/logservice`

`go build -mod=readonly ./pkg/hakeeper/task`

`go vet -mod=readonly ./pkg/hakeeper/task`

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26537)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25833

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

HAKeeper rebuilt a filtered CN pool for every Created task, but that
pool reset the Running-task frequencies. A successful allocation then
updated only the temporary pool, so the next task in the same scheduling
round saw the same stale load snapshot and could select the same CN
repeatedly.

This PR:

- preserves source frequencies when filtering a CN pool;
- selects from the per-task eligible view but records a successful
allocation in the shared round pool;
- leaves failed allocations out of the load count;
- adds regressions for existing load, batch scheduling, label/resource
filtering, and allocation failure.

The change does not alter label/resource eligibility, expired-CN
handling, task persistence, timeout behavior, or tie-breaking.

Tested with:

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -run
'<each focused regression>' ./pkg/hakeeper/task`

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1
./pkg/hakeeper/task`

`./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -run
'^TestTaskSchedulerCan(ScheduleTasksToCNs|ReScheduleExpiredTasks)$'
./pkg/logservice`

`go build -mod=readonly ./pkg/hakeeper/task`

`go vet -mod=readonly ./pkg/hakeeper/task`

Co-authored-by: XuPeng-SH <[email protected]>

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.

3 participants