Repository navigation
fix(merge): reserve memory before scheduling tasks - #32911
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
This pull request is merged. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 1ba2fb8a773405a8c823f805ae20d4131d87d97b
Assessment: approve
The scheduler now reserves memory before submitting each merge. Denied candidates leave room for smaller candidates, rejected submissions return their reservation, and the existing completion observer releases accepted reservations exactly once, including when completion arrives before admission.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
Validation:
-
The full merge package passed all 47 tests under the race detector. Five focused reservation and lifecycle tests passed 100 repetitions each using the retained race binary.
-
With the merge-base scheduler overlaid, the regression failed in the tight-budget and executor-rejection cases for both assigned and Ln overlap tasks. The sufficient-budget controls passed.
-
Isolation preflight, the native build, the native input audit, and git diff --check passed. Receipts and logs are reconciled in validation-reconciliation.json, and all three discussion entries are accounted for.
Limitations:
- The tests verify reservation accounting with deterministic budgets. Production RSS under live memory pressure remains unmeasured, and the frozen CI snapshot still had tests in progress.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: ed2953a4ab295a5cf045148a9c6be25a562f08a4
Assessment: approve
The TN merge scheduler now reserves memory before dispatch. It skips denied candidates, returns the reservation when dispatch rejects a task, and uses the existing observer to release accepted reservations exactly once, even when completion arrives before admission.
Model: gpt-6.2-sol / xhigh
Session: 01a1ee80-0d82-7030-a965-b51f496c3054 · slot 2 · generation 1
Validation:
-
The frozen diff and git diff --check passed. Reconciled commands, source fingerprints, exits, and retained logs are recorded in validation-reconciliation.json.
-
Reused race results from revision 1ba2fb8 after verifying that the only intervening change was a license header in the test file. All 47 merge-package tests passed, and five focused tests passed 100 repetitions each.
-
With the merge-base scheduler overlaid, tight-budget and simulated executor-rejection assertions failed for both assigned and Ln overlap tasks. The sufficient-budget controls passed.
Limitations:
-
The deterministic tests verify reservation accounting. Production RSS under live memory pressure remains unmeasured.
-
Unit, SCA, and BVT checks were still in progress in the frozen CI snapshot.
…32914) ## What type of PR is this? - [x] BUG - [x] Improvement ## Which issue(s) this PR fixes: Related to #32278 (C04 and C05; the umbrella issue remains open). ## What this PR does / why we need it: - Include the table's configured block capacity in merge memory admission and the merge-start estimate. Existing input objects can contain default-sized blocks even when the current schema specifies fewer rows, so the estimate retains the 8,192-row floor; configurations above that floor increase the input-block estimate. - Read a small number of ordered, buffered sparse S3 misses individually when the existing range-amplification threshold is exceeded. Keep the envelope for dense, unordered, streaming, or more than four misses, and retain full-file cache-fill behavior. A later object-store 416 after a successful first range remains an unexpected EOF. Failed reads do not publish partially completed cache entries, and cache-update failures keep their existing non-fatal behavior. - Reuse the resolved bounds to bypass sparse-range classification on short ranges and single-entry reads. For other candidates, stop at the fifth miss or at the first unordered or streaming miss. Compute the bounds using two scalar values, so a read no longer copies entries to keep their offsets alive. In a local ten-sample cacheless public-read benchmark with a generated reader, two 4 KiB ranges 16 MiB apart consumed 8,192 bytes in two GETs versus 16,781,312 bytes in one GET; allocation bytes fell by more than 99%. Single and adjacent controls retained their request and allocation counts. This is a bounded request-count/bytes tradeoff; it does not establish the cause of the original production heap peak. ## Validation - Rebased the five original commits onto main at `7f6729277e`. Migrated the reservation probes added by #32911 to the schema-aware estimate. The inline completion probe now uses 16,384-row blocks and asserts the amounts reserved and released, including executor rejection. - On Linux/x86-64, all four affected packages passed the short-mode race suite. The downstream data merge, tombstone merge and partial-read cleanup checks also passed under race. Formatting, err-check, vet, golangci-lint and molint passed. - In six same-core, alternating generated-storage samples per revision, the public read of 64 adjacent 32-byte ranges had median time of 49.27 µs before and 38.60 µs after. It kept one GET and the same payload while allocations fell from 276 to 147 per read and bytes allocated fell from 34,812 to 19,963. The sparse control kept two GETs and 8,192 payload bytes. These local measurements isolate client-side work. - Owning fileservice, mergesort, merge scheduler and catalog packages: normal and race runs; new sparse-range, cache-failure and admission tests, including the non-default 16,384-row case. - `TestMergeBlocks`, `TestTombstoneMergeKeepsTargetDroppedAfterSnapshot`, and `TestReadOneBlockWithMetaReleasesPartialReadOnError`. - Changed-package `go vet` and `golangci-lint`. The C03 reservation ownership fix is separate in #32911. This change does not close the umbrella issue; end-to-end heap/RSS and object-store measurements remain future work. --------- Signed-off-by: XuPeng-SH <[email protected]> Co-authored-by: Peng Xu <[email protected]>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#32428 ## What this PR does / why we need it: When multiple merge candidates compete for memory, a denied candidate could run and release a reservation owned by another task. Acquire each reservation before submitting the task. Skip denied candidates, return the reservation if submission fails, and let the completion observer release accepted work exactly once. The scheduler regression covers overlapping and assigned tasks, tight and sufficient budgets, executor refusal, a smaller candidate after denial, and completion before admission. The test uses object metadata and a deterministic memory budget. Validation on Go 1.27.1, darwin/arm64: the reachable-budget regression fails on the original revision and passes with the fix; the full merge package passes with the race detector; scoped go vet and golangci-lint pass. (cherry picked from commit 397ce07)
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #33203 ## What this PR does / why we need it: Backport the aggregate Merge memory-admission safeguard from #33244 to `4.2-dev`. The branch does not yet contain #32911, so this PR also cherry-picks its prerequisite: reserve memory before submitting each Merge task, skip denied work, and release a reservation if submission fails. Without that prerequisite, a tighter `Acquire` policy would not stop the task from running. Adapt the safeguard to `4.2-dev`'s `defaultAcquirePolicy`: the sum of Merge reservations must fit within two thirds of the currently sampled TN memory headroom. This accounts for memory already used by other TN work; non-Merge throttlers retain their existing policy. Keep memory-denied one-shot manual Merge tasks in a bounded retry queue. When the active task completes, wake the scheduler to retry the denied work within the retry window, including when the table is paused and the normal scan interval is longer than the window. Completion notifications target the active scheduler generation and validate the table supporter before waking its queue. Retained manual retries are rearmed on restart. Denied retries rotate so an expensive request cannot hide a smaller one, and pausing a table preserves the next manual retry check. The latest review gaps are closed: an ALTER commit refreshes the existing table supporter without losing its retry queue or in-flight accounting; expired retries release their object metadata even under low memory or PauseAll; and the scheduler checks recovered capacity before the retry deadline, with a final admission opportunity at the deadline. The next review found three further edges. Named-object inspect commands carry only object names, so the scheduler now resolves visible catalog statistics before estimating and admitting those tasks; missing objects cannot receive a zero-byte reservation. A delayed vacuum callback captures the table reference when scheduled, avoiding a race with an ALTER refresh. The final retry permits one admission attempt when its deadline timer fires slightly late, then expires retained candidates after a bounded five-second grace period. The latest review found that pre-admission memory trimming could silently remove an object from a named manual Merge request. Named-object tasks now retain their complete input set through estimation; admission rejects and retries the whole request when capacity is insufficient. The regression test makes the two-object estimate exceed the gathering threshold while one object fits, and verifies the full request reaches admission and remains queued after denial. The latest review's three remaining edges are addressed. A deferred named merge checks every requested object at executor lookup and again when its transaction task is created; if any input disappeared, the whole task is rejected. A transient executor rejection, including a dispatcher scope conflict before the old scope is released, keeps the complete request in the existing bounded retry queue. The retry test waits for scheduler admission to finish before asserting that the completion released its reservation. The newest review's remaining issues are also addressed: the launch pad clears its reusable pointer-bearing slices after gathered tasks have been admitted or transferred to retries, so an expired retry does not leave catalog objects reachable there. The exact merge task constructor re-reads each object's current catalog version before accepting the task, catching a drop intent installed after executor lookup. The queued completion regression now waits for scheduler admission before asserting reservation release. Validation on `4.2-dev` at `d497cc1584`: focused admission and named-object regressions passed; three affected timing and ownership regressions passed 25 race repetitions; the full `rscthrottler` and Merge scheduler packages passed with `-race`, and the Merge job package compiled. Scoped `go vet` with the repository CGo include paths, `gofmt`, and `git diff --check` passed. The previous PR head passed all 34 checks; CI for this head is pending. The PR diff covers the Merge scheduler, executor, merge job constructor, resource throttler, and their regression tests. This is an estimate-based admission safeguard, not a strict process-memory cap. The separate block-row estimate improvement from #32914 is not part of this backport. Approved-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #32428
What this PR does / why we need it:
When multiple merge candidates compete for memory, a denied candidate could run and release a reservation owned by another task. Acquire each reservation before submitting the task. Skip denied candidates, return the reservation if submission fails, and let the completion observer release accepted work exactly once.
The scheduler regression covers overlapping and assigned tasks, tight and sufficient budgets, executor refusal, a smaller candidate after denial, and completion before admission. The test uses object metadata and a deterministic memory budget.
Validation on Go 1.27.1, darwin/arm64: the reachable-budget regression fails on the original revision and passes with the fix; the full merge package passes with the race detector; scoped go vet and golangci-lint pass.