Repository navigation
fix(merge): backport aggregate TN-memory admission to 4.2-dev - #33249
mergify[bot] merged 24 commits into
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? |
|
Queue requested — the merge queue status continues in this comment ↓. |
## 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)
(cherry picked from commit 6fbee0f)
5b1f110 to
aa7e011
Compare
|
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: aa7e01118d3c35d6b72a3d2cbcea0d9ab27b4358
Assessment: request_changes
The aggregate Merge limit reuses the existing throttler and moves reservation ahead of dispatch, but a denied one-shot request is silently discarded. The scheduler needs to preserve or report that work while maintaining the new memory bound.
Model: gpt-6.1-terra / max
Session: 01a21136-dc54-7ba1-aace-4039c02570be · slot 2 · generation 3
- P2
pkg/vm/engine/tae/db/merge/scheduler.go:1268: An operator requests a one-shot merge of specified objects while other tables hold enough Merge reservations that the raw headroom passes gathering, but the new aggregate reservation budget cannot admit this task.
Impact: The command has already returned success after queuing the trigger, but the requested merge is dropped and is not retried after the other reservations are released. This can permanently lose the requested work while automatic merging is paused.
Evidence: doSched removes a zero-expiry trigger at lines 1231-1237 before this new denial branch, and the branch simply continues. The objects command creates a user trigger and returns SendTrigger at pkg/vm/engine/tae/rpc/inspectMerge.go:522-592; user triggers are specifically allowed while a table is paused at scheduler.go:1248-1252. This is reachable without failing the existing gather check: with 6 GiB limit-minus-RSS headroom and 3 GiB already reserved, Available reports 3 GiB so resourceAvailable permits a 1.5 GiB estimate, while the new two-thirds aggregate budget has only 1 GiB left. Preserve denied one-shot work for a bounded retry when capacity returns, or report its rejection to the caller, without bypassing the reservation.
Validation:
-
The isolated /tmp and loopback preflight passed, and the frozen-head audit confirmed a clean checkout, the complete patch, discussion-key coverage and 170 matching native source inputs (preflight.stdout.log, review-audit.stdout.log and checks receipts).
-
All six selected throttler and Merge scheduler tests passed, including aggregate admission, concurrent admission, rounding, denial, submission failure and inline completion (focused.stdout.log and its check receipt).
-
The targeted concurrent aggregate-admission test passed with the Go race detector (race-retry.stdout.log; check receipt 1795612338372571191-2.json).
Limitations:
- A supplementary one-shot scheduler overlay timed out twice before producing a test result (oneshot-probe.stderr.log and oneshot-retry.stderr.log); the finding is based on the traced source paths and arithmetic, not those probes. The initial race build lacked a native include and timed out; the corrected retry passed.
Keep only denied candidates from a one-shot user trigger in the existing scheduler queue. Preserve their estimates and require the same aggregate reservation before every submission. Integrate the latest 4.2-dev and retain the original backport commits.
|
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: e116010ddc40c5e29ab6d39c5a95dcd9c697834b
Assessment: request_changes
The aggregate admission design appropriately reuses the throttler and scheduler. The current head addresses the earlier pause, fairness, restart, cross-table wake, and metadata-retention cases, but a final retry can still be lost, the metadata refresh introduces a data race, and named-object merges bypass the new reservation safeguard.
Model: gpt-6.1-terra / max
Session: 01a21bb5-0ae7-79b2-af8b-b67631bec29a · slot 0 · generation 22
-
P2
pkg/vm/engine/tae/db/merge/scheduler.go:1510: An operator uses the existingmerge trigger --kind objectscommand while aggregate Merge capacity is exhausted.
Impact: The selected objects are submitted without a memory reservation, so this entry point can run a large merge outside the new aggregate safeguard and leave its consumption unaccounted for when admitting other merges.
Evidence: The command parser creates object statistics containing only names (pkg/vm/engine/tae/rpc/inspectMerge.go:598), soEstimateMergeSizeskips every object because its row count is zero (pkg/vm/engine/tae/mergesort/task.go:547).Acquire(0)then succeeds unconditionally, while the executor resolves the names to real objects. The retainedpublic-object-probe.logreproduces a zero-byte request for objects whose populated statistics estimate approximately 1.73 GB. The name-only input predates this PR, but it leaves the newly introduced per-task safeguard ineffective for this supported path. Obtain the real object statistics before estimating and admitting the task. -
P2
pkg/vm/engine/tae/db/merge/scheduler.go:1328: An ALTER commit refreshes an existing table supporter while a delayed vacuum-check callback for that table runs.
Impact: The scheduler writes the table interface concurrently with the callback reading it, introducing a data race in the vacuum scheduling path.
Evidence:fallbackSchedVacuumCheckreadssupp.todo.tablefrom anAfterFunccallback at line 933, while this new assignment runs on the scheduler loop.vacuum-race-v2-probe.logrecords the race detector reporting those accesses using the same concrete catalog table type. Capture the table reference before scheduling the callback or otherwise synchronize the access. -
P2
pkg/vm/engine/tae/db/merge/scheduler.go:1112: A retained manual retry is denied at its last pre-deadline check, capacity recovers without a Merge-completion notification, and the timer scheduled for the deadline is handled slightly late.
Impact: The acknowledged request expires without the promised final admission opportunity, even though sufficient headroom returned during its retry window. A paused table will not recover that work through automatic merging.
Evidence:nextManualRetryDueschedules the next check exactly atretryUntil, butdoSchedTriggerdiscards the request when its current time is after that instant at line 1474. The running-scheduler probe indeadline-live-probe.logreproduces the loss with the memory guard open and a production-like two-thirds budget. Arrange a final admission opportunity that does not depend on a timer being handled at the exact deadline while keeping retry retention bounded.
Validation:
-
Private-runtime preflight passed; 170 native inputs were verified against the frozen source and diagnostic build tree.
-
Twenty-three selected throttler and scheduler tests passed across both owning packages:
focused-tests.log, receiptchecks/1795764517092702396-2.json. -
Three diagnostic probes reproduced the named-object zero reservation, vacuum data race, and late-deadline retry loss. Their logs and matching receipts are recorded in
review-audit.log. -
All 13 discussion keys were accounted for, and the source checkout remained clean at the assigned head.
Limitations:
-
The diagnostic probes use scheduler fixtures, a fake clock, and resource or executor doubles; they are not deployed TN tests.
-
The complete package suite and a live TN deployment were not independently run in this review. The related OOM incident's root cause remains unconfirmed.
|
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: 81d3b5a713bfdeea0d73a7bc331eeed82037dc6a
Assessment: request_changes
The aggregate reservation and retry design addresses the earlier review concerns, but resolving named-object statistics introduces a regression: an explicitly requested merge can silently lose inputs before admission.
Model: gpt-6.1-terra / max
Session: 01a22868-9ecc-7250-9120-16606b40e9e2 · slot 0 · generation 44
- P2
pkg/vm/engine/tae/db/merge/scheduler.go:1776: A user requests a merge of two or more named objects when their combined estimate exceeds two-thirds of available headroom but a subset fits.
Impact: The scheduler can submit only a subset of the requested objects and discard the rest without a retry. With two inputs, it can rewrite one object instead of merging the pair the user specified.
Evidence: The newly resolved statistics enter controlTaskMemInPlace, which halves the object list before the admission code can retain denied work. A read-only overlay probe used 1.5 GiB of raw headroom: the two-object estimate was 1,730,641,920 bytes, the single-object estimate was 865,320,960 bytes, and the aggregate budget was 1,073,741,824 bytes. It observed one submitted object and no queued retry. At the merge base, the name-only statistics had a zero estimate and were not trimmed. Preserve the complete named request for admission and retry, or explicitly reject it rather than silently dropping inputs.
Validation:
-
Private /tmp and loopback preflight passed.
-
Both owning packages, pkg/common/rscthrottler and pkg/vm/engine/tae/db/merge, passed with -race -count=1 using the supplied test executor; see owning-packages-race.log and receipt 1796009739223687766-3.json.
-
Six individually selected concurrency and timing tests passed with -race -count=100 each; their logs and command receipts are retained in the diagnostic directory.
-
The independent named-object overlay probe failed its complete-input assertion as described; see named-object-probe.log and receipt 1796009547651325900-3.json.
Limitations:
-
The named-object reproduction exercised the scheduler with controlled fixtures; the public RPC construction was traced in source but not exercised through a running service.
-
The linked OOM incident does not establish Merge as its root cause.
|
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: a236a0b33c25e5b943d0446868c787638936beef
Assessment: request_changes
Aggregate admission reuses the existing throttler and scheduler, and the earlier initial-gather trimming defect is addressed. Deferred named merges can still run with missing inputs, a completion wake can discard queued work before dispatcher scopes are released, and a new retry test has an intermittent synchronization failure.
Model: gpt-6.1-terra / max
Session: 01a22b07-00b6-7e32-b0a1-3099d0b867c7 · slot 1 · generation 39
-
P2
pkg/vm/engine/tae/db/merge/scheduler.go:1513: A named merge of objects A and B is denied and retained. Before it is retried, another admitted merge replaces A, and enough memory becomes available for the retained request.
Impact: The retry can rewrite B alone instead of merging the complete requested set. The original command has already returned success, and the scheduler treats the retry as admitted.
Evidence: The retry reuses trigger.assigns without checking current visibility. The executor skips IDs it cannot find at pkg/vm/engine/tae/db/merge/executor.go:63, and pkg/vm/engine/tae/tables/jobs/mergeobjects.go:93 filters objects with a drop intent while allowing one remaining object. The scheduler-fixture probe observed the stale input reaching execution, with an unchanged-input control: review-probes.stdout.log, receipt checks/1796020138048524746-3.json. Validate the complete named input set through execution and reject the whole request if an input has disappeared. -
P2
pkg/vm/engine/tae/db/merge/scheduler.go:1543: A user queues a merge of A and B while another merge involving A is running. The running merge rolls back, leaving both requested objects valid, and its completion wakes the queued request before the dispatcher has released A's scope.
Impact: The executor rejects the queued request with a scope conflict. This branch releases its reservation but does not retain or retry the request, so the acknowledged manual merge is lost even though its inputs remain available.
Evidence: The scheduler completion observer sends the wake at scheduler.go:239-242. It is registered before the dispatcher observer in pkg/vm/engine/tae/db/scheduler.go:108 and pkg/vm/engine/tae/db/dispatcher.go:66; pkg/vm/engine/tae/tasks/ops/ops.go:57 invokes them in order. The scheduler can therefore reach TryDispatch before dispatcher.OnExecDone removes the old scope. A controlled scheduler probe observed the request being dropped on the modeled conflict, while its released-scope control admitted it: review-probes.stdout.log, receipt checks/1796020138048524746-3.json. Wake after scope release or retain bounded retryable work on this rejection. -
P2
pkg/vm/engine/tae/db/merge/reservation_accounting_probe_test.go:930: The test receives a task from delayedCompletionExecutor before the scheduler returns from ExecuteFor and calls task.doneCB.Admit.
Impact: OnExecDone can return before the deferred reservation release occurs, causing the immediate zero-reservation assertion to fail nondeterministically and making the test suite flaky.
Evidence: A race run failed this assertion with 83,886,080 bytes still reserved: race-measure.jsonl, receipt checks/1796020329980558086-3.json. A barrier-controlled probe confirmed that early completion retains the reservation until Admit and then releases it: observer-probe.stdout.log, receipt checks/1796020436959335595-3.json. The original test subsequently passed 100 isolated repetitions. Synchronize with the scheduler after admission before asserting the final reservation value.
Validation:
-
Private-runtime preflight passed, and the native build used 170 verified frozen-source inputs. The final audit confirmed a clean checkout and coverage of all 17 discussion keys: review-audit.stdout.log, receipt checks/1796020602763384887-3.json.
-
Nine selected admission and scheduler tests passed, and both owning packages passed under the race detector: focused-retry.stdout.log and owning-race.stdout.log; receipts checks/1796020055766958338-3.json and checks/1796020243044597118-3.json.
-
Fifteen individually selected tests each passed 100 race repetitions, including the test that failed once in the earlier measurement: focused-race-stress.stdout.log and recovered-headroom-stress.stdout.log; receipts checks/1796020514359953988-3.json and checks/1796020371854115818-3.json.
-
The initial focused run timed out during module downloads; the retry with the official Go proxy succeeded using the same task caches. The timeout receipt is checks/1796019909517254634-3.json.
Limitations:
-
The diagnostic probes use scheduler fixtures and a dispatcher double. The real executor's partial-input behavior and the observer ordering were established by source tracing rather than a deployed TN test.
-
The linked incident confirms an OOM but does not establish Merge as its cause.
|
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: 62dfcd6a916e6beb7f468ade7f84aa4480907ef6
Assessment: request_changes
The change reuses the existing throttler, scheduler, and completion observer, and addresses the earlier retry fairness, restart, and partial-input concerns. Two resource-lifecycle gaps remain: expired named retries can retain catalog entries, and the post-dispatch input check can miss a newer drop version. A new test also has an unsynchronized completion assertion.
Model: gpt-6.1-terra / max
Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45
-
P2
pkg/vm/engine/tae/db/merge/scheduler.go:1161: A named-object merge is denied, then its retry expires while low memory or PauseAll prevents another gather.
Impact: Clearing the retry does not release all of its object references. The shared launch-pad result buffer still holds the resolved stats, which are pointers into catalog ObjectEntry values. Removed objects and their associated memory can therefore remain reachable beyond the retry window during the same pressure the safeguard is intended to relieve.
Evidence: The new resolver replaces name-only stats with catalog stats at scheduler.go:1858, while the cloned retry and launch-pad buffer both retain the task at line 1567. Reset at line 1643 also does not clear the buffer's backing slots. expired-catalog-probe.log reproduces the retained references after queue expiry and catalog removal using the TN catalog iterator. Clear or recycle the launch-pad's pointer-bearing results after transferring ownership to independently retained retry work. -
P2
pkg/vm/engine/tae/tables/jobs/mergeobjects.go:119: An object is dropped after the executor resolves the named inputs but before the transaction task factory runs, for example when a concurrent CN merge commits.
Impact: The constructor checks the older captured ObjectEntry, so it can accept a task whose current catalog version has a drop intent. The task can perform substantial merge reads and writes before the later object-deletion check fails and rolls the transaction back, wasting the reserved capacity and I/O. This does not demonstrate a partial commit.
Evidence: catalog/object.go:178 creates a cloned drop version instead of updating the captured entry. stale-object-probe.log shows the unchanged-input control passing and the constructor returning a task after the catalog installs the drop version. Re-resolve each captured ID, or inspect its current catalog version, before accepting the exact task. -
P2
pkg/vm/engine/tae/db/merge/reservation_accounting_probe_test.go:1412: The test receives the second task from delayedCompletionExecutor and calls OnExecDone before ExecuteFor returns and the scheduler calls Admit.
Impact: OnExecDone correctly defers the reservation release until admission, but the immediate zero-reservation assertion can run first and fail intermittently, making the test unreliable under a valid goroutine schedule.
Evidence: The executor publishes the task before returning, and taskObserver waits for both completion and admission. queued-original-probe.log forces that interleaving and fails the original assertion; queued-observer-probe.log confirms the reservation is released after admission. Synchronize with the scheduler after the second completion, as the corrected recovered-headroom test does.
Validation:
-
Private-runtime preflight passed, and 170 native inputs matched the retained build tree. Receipts: checks/1796029717786663360-3.json and checks/1796029809090227010-4.json.
-
Focused admission, retry, and named-object tests passed on the assigned head after retrying dependency setup with the Go proxy. See focused-retry.log and checks/1796030060464480811-3.json.
-
Both owning packages passed with the race detector; five simulator or diagnostic tests were skipped. See owning-race.log and checks/1796030690531511773-3.json.
-
The queued-one-shot test passed 100 and 500 race repetitions without forced scheduling. The separate barrier-controlled probe demonstrated the completion-before-admission interleaving.
-
Diagnostic probes reproduced the stale object-version check and retained launch-pad references, with logs and matching exit receipts in the diagnostic directory.
Limitations:
-
The targeted probes use catalog fixtures, a fake transaction or scheduler timing controls; they are not live TN deployment tests.
-
The related incident establishes an OOM but does not establish Merge as its root cause.
|
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: fc61605d7f4381d2edab500406b5a20aff6b2a47
Assessment: approve
The aggregate admission safeguard reuses the existing throttler and scheduler, with bounded retries to retain denied manual work. The prior review concerns about retry lifecycle, named inputs, retained references, and callback ordering are resolved in the current source. No actionable defects remain in the reviewed scope.
Model: gpt-6.1-terra / max
Session: 01a22af4-cf2a-7f70-88e4-931bbf57d739 · slot 2 · generation 14
Validation:
-
Preflight passed. Native provenance matched 170 source inputs and six retained build artifacts.
-
The resource-throttler and merge-scheduler packages passed with the race detector; receipt 1796099950528376957-3.json and owning-race.stdout.log.
-
The three latest regression tests each passed 25 race-enabled repetitions; receipt 1796100101011294133-3.json and latest-stress.stdout.log.
-
git diff --check passed; receipt 1796100175997019856-3.json. The discussion assessment covers all 21 indexed items.
Limitations:
-
Five optional experiment or helper tests were skipped by the merge package.
-
No live-cluster OOM reproduction was performed. The related incident does not establish merge as the cause, and this change provides estimate-based admission rather than a strict process-memory cap.
✅ Merged into
|
What type of PR is this?
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 tighterAcquirepolicy would not stop the task from running.Adapt the safeguard to
4.2-dev'sdefaultAcquirePolicy: 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-devatd497cc1584: focused admission and named-object regressions passed; three affected timing and ownership regressions passed 25 race repetitions; the fullrscthrottlerand Merge scheduler packages passed with-race, and the Merge job package compiled. Scopedgo vetwith the repository CGo include paths,gofmt, andgit diff --checkpassed. 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.