Repository navigation
fix(objectio): age out idle write arenas instead of a global drain timer - #29303
Merged
Merged
Conversation
After a wide parallel LOAD the "write-arena" mpool kept ~1.6 GB of off-heap memory indefinitely. Each concurrent S3 writer takes a large-tier WriteArena, Reset grows it to the next power of two of its biggest cycle (up to 128 MB), and PutArena parks it: up to 2x GOMAXPROCS arenas. The only release was drainArenaPools, run 10 minutes after the last ScheduleArenaDrain; every checkpoint and every sinker Close called it, so on a live server the timer was pushed back forever. Measured on a 24-core single node: 1,598 MB parked after the load and still 1,598 MB 13 minutes later, invisible to Go profiles. Arenas now age out individually. The free list is a stack of parked arenas with the time each was parked: GetArena takes the most recent, so the arenas a steady workload cycles stay on top and warm, and the surplus of a burst sinks to the bottom. A one-shot timer, armed only while arenas are parked, frees those parked for longer than arenaIdleTTL (one minute) and re-arms for the oldest remaining one, so an idle server releases too. ScheduleArenaDrain and its two callers are removed. The count cap is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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 was referenced Sep 24, 2026
XuPeng-SH
requested changes
Sep 24, 2026
XuPeng-SH
left a comment
Contributor
There was a problem hiding this comment.
Reviewed head 06437c4. Static ownership/timer inspection found no demonstrated production double-free or use-after-free in Get/Put/reaper transitions. The exact-head CI run 35948805390 completed successfully. I did not run local tests; reported race-test logs could not be independently verified.
XuPeng-SH
pushed a commit
that referenced
this pull request
Sep 24, 2026
…#29316) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #29315 ## What this PR does / why we need it: `load_data/load_data_parquet.sql` fails intermittently in multi-CN CI at `pq_file_fanout_rollback`. It failed on #29303, whose change is unrelated. ``` [EXPECT RESULT]: invalid input: column name not found [ACTUAL RESULT]: internal error: convert go error to mo error reading magic footer of parquet file: context canceled (read: 0) ``` ### Root cause - When one shard of a parallel load fails, it cancels its siblings. - The scope scheduler reports the failing shard's error by recognising each sibling's error as that cancellation (`normalizeScopeRunError` / `preferPrimaryScopeResult`, via `errors.Is`). - `moerr.ConvertGoError` formatted every Go error into an internal error. So a context cancellation or deadline, often wrapped by a library, stopped matching `errors.Is(err, context.Canceled/DeadlineExceeded)`, and whichever shard's result was collected first won. It's not only the parquet reader: - The planner's parquet footer read (`compile.go`) flattens the same way. - The four RPC error encoders (`pkg/pb/{pipeline,shard,lock,query}`) go through `ConvertGoError` too, so a remote scope's cancellation reached the coordinator as an internal error. - About 88 call sites check `errors.Is` against the context sentinels, including the frontend, CDC and RPC clients. ### Fix, in `moerr` - **Conversion:** `ConvertGoError` converts a context error, wrapped or not, to one of two new codes. The message is the original text. - `ErrContextCanceled` (20109), sent to clients as MySQL `ER_QUERY_INTERRUPTED`. - `ErrDeadlineExceeded` (20110). A deadline joined with a cancellation keeps the deadline. - **`Error.Is`:** it matches only those two codes to `context.Canceled` / `context.DeadlineExceeded`. `errors.Is` then behaves after conversion as it did before, and also after an RPC round trip, because the code is what's serialized. - **Unaffected errors:** errors built directly, such as a killed query (`ErrQueryInterrupted`) or a statement timeout (`ErrQueryTimeout`), don't gain new `errors.Is` matches. - **RPC contract:** the result is still a `*moerr.Error`, as the RPC encoders require. Returning raw context errors panicked those paths. - **Mixed versions:** older nodes decode the new codes with their message and MySQL code intact, because unmarshalling doesn't validate codes. This replaces the parquet-only `convertReaderError` from the first commit of this PR. The parquet reader uses `moerr.ConvertGoError` again. ## Tests Each of these fails without the change: - **`TestConvertGoErrorKeepsContextIdentity`:** the mapping, MySQL codes, kept message, marshal/unmarshal round trip, deadline-over-cancellation for joined errors, and that directly built `ErrQueryInterrupted` / `ErrQueryTimeout` / internal errors are unaffected. - **`TestPreferPrimaryScopeResult`:** a sibling's parquet cancellation, both converted locally and decoded from `pipeline.EncodedMessageError`, resolves to the failing shard's error. - **`TestParquetOpenFileCanceledBySibling`:** opening a real parquet file with a context canceled by a sibling reports `ErrContextCanceled`, which matches `context.Canceled`. Other checks: - **`go test`:** `common/moerr`, `sql/compile`, `sql/colexec/external`, `pb/...`, `cdc`, `txn/service`, `util/export/etl`, `sql/plan/function/ctl`, `frontend`, `lockservice`, `shardservice` and `queryservice` all pass. - **BVT:** no expected result contains the old flattened cancellation text. - **`make static-check`:** 0 issues. The CI race itself doesn't reproduce locally (60/60 single-node runs gave the expected error), so the tests cover the mechanism deterministically. ### Not covered Code that flattens errors itself, e.g. `moerr.NewInternalErrorf("...%v", err)` or `err.Error()`, still loses the identity. Those sites need routing through `ConvertGoError` wherever a cancellation can reach them; that's a separate follow-up. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
The large write-arena pool parks at most max(4, 2*GOMAXPROCS) arenas, so at GOMAXPROCS <= 2 it has four slots. TestArenaFreedAfterIdleTTL returned five arenas and asserted all five parked; the fifth is freed on Put, so the assertion failed even though TTL expiry works. TestArenaBurstReleasedWhileStillActive had the same shape: it returned eight and derived per-arena memory from what stayed parked, which halves the estimate at four slots. Size both fixtures by min(n, maxCount). Overflow past the cap stays covered by TestArenaPoolCountCap. Passes with -race at GOMAXPROCS 1, 2, 3, 4 and 24. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
TestServerHeartbeatSendsImmediately only called cancel() when the first heartbeat arrived, so a t.Fatal on the timeout path left the context uncancelled. golangci-lint's govet/lostcancel now reports this in the SCA job (heartbeat_test.go:153 and :179), failing SCA for every PR against main. Defer cancel() right after creating the context; the explicit cancel() that stops the heartbeat loop is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
No tracked issue. This was found while investigating memory use of parallel multi-file
LOAD(the glob fan-out from #29242 / #29245).What this PR does / why we need it:
After a wide parallel
LOAD, about 1.6 GB of off-heap memory stayed resident indefinitely.select mo_memory_usage('')pins it to thewrite-arenampool: theWriteArenafree lists inpkg/objectio/arena_pool.go.Resetgrows it to the next power of two of its biggest cycle, up toarenaMaxSize(128 MB).PutArenaparks it: up to2 × GOMAXPROCSarenas.drainArenaPools, run 10 minutes after the lastScheduleArenaDrain(). Every TAE checkpoint and every sinkerClosecalled it, so on a live server the timer was pushed back indefinitely.The memory is off-heap, so Go heap profiles don't show it.
Fix
Arenas now age out individually.
{arena, parkedAt}.GetArenatakes the most recently parked arena, so the arenas a steady workload cycles stay on top and warm, while the surplus of a burst sinks to the bottom.arenaIdleTTL(one minute), and re-arms for the oldest remaining one. The excess is released while other work continues, and an idle server releases too, with no permanent goroutine.ScheduleArenaDrain/drainArenaPoolsand their two call sites (checkpoint runner, sinker) are gone.Trade-off: an arena left unused for more than a minute is reallocated on its next use. That's at most one allocation per object write cycle, which is negligible next to the write.
Verification
Same machine (24 cores, single node), one glob
LOADof 40 lz4 CSV files (300 M rows) withparallel 'true':write-arenaat load endwrite-arena60–80 s laterwrite-arena13 min laterTwo minutes after the load, TAE flush and merge of the new data use a few arenas again (~80 MB). Those are live work and age out the same way.
New
pkg/objectio/arena_pool_test.go:Passes with
-race(-count=3).go test:pkg/objectio,pkg/objectio/ioutil,pkg/vm/engine/tae/db/checkpointandpkg/vm/engine/tae/mergesortpass.make static-check: 0 issues.Also in this PR: an unrelated CI fix
Since about 19:00 UTC on 2026-09-24, the SCA job has failed on every PR against
mainwith a govetlostcancelwarning inpkg/proxy/heartbeat_test.go(lines 153 and 179).TestServerHeartbeatSendsImmediatelyskippedcancel()on itst.Fataltimeout path. Commitb6615ed3dbaddsdefer cancel()right after the context is created. It changes only the test, and it can be merged separately if preferred.🤖 Generated with Claude Code