Repository navigation
Description
Problem
CN catalog replay can exceed its memory limit on large catalogs. Replay also retains delayed logtail closures after applying them, and the catalog keeps multiple representations of table and column definitions. Optimize both main and 4.2-dev, measuring startup peak and steady-state memory separately.
Related to #32426, which contains a synthetic reproduction of catalog representation and full-batch merge costs. #32611 landed on main and reduces transient replay memory, but does not cover all items below.
Observed incident
On 2026-11-20, IDC mo-new-moi CN moi-mo-2606-astra-cn-2jl5r ran image v4.2.8-hotfix-20261119-5c16f56639-2026-11-19 with a 24 GiB container limit. Its 10:59:09–11:00:37 CST attempt was OOMKilled during startup. Logs show approximately 1,248,931 table rows and 9,050,305 column rows. At 10:59:56 it entered FIND_TABLE merge mo_columns results; no replay-completion log was observed before termination.
At 11:00:30, the last available sample before OOM, RSS was 17.30 GiB and Go heap allocated was 15.16 GiB, with 15.15 GiB live at the last GC. The peak at the instant of OOM was not sampled. Historical in-use profiles show replayCatalogCache paths through internal executor batch cloning, Batch.Append, ParseColumnsBatchAnd, and table definition construction. The profile merges multiple snapshots, so its total is not a single-time heap size.
Code and branch differences
- In the incident revision,
replayCatalogCacheretains all three query results until return and, when any table crosses a column batch boundary, appends every column batch into the first while retaining the source batches. Parsing then constructs a map of all column metadata before constructing table definitions. Replay · Column parsing maincontains Reduce transient catalog replay memory #32611, which avoids the full merge and consumes column batches progressively. The executor still materializes all input, and the retained metadata representation remains. Verify remaining peak and steady-state costs at production-representative scale.4.2-devat7d1cacc6ddstill has the all-batches merge. Assess a safe backport or equivalent optimization, including upgrade and reconnect behavior.- Both branches at the checked revisions reset
dca.flistwith[:0]after applying delayed logtail closures and on reset. The backing array retains the old closures, which capture*api.Entryand*CatalogCache, potentially retaining payloads and an old cache generation until slots are overwritten or the backing array becomes unreachable. Clear the elements or release the backing array while preserving lock and retry semantics. Actual retained bytes in the incident have not been measured. Closure capture · Queue lifecycle TableItemretains both planner and engine table definitions, along with raw and parsed forms of some metadata. Assess which representations can be shared, compacted or built lazily without changing schema, snapshot, DDL, or planner semantics. TableItem
Expected outcome and validation
- Bound replay's additional working memory independently of the total column result where feasible, and reduce retained per-table and per-column overhead on both branches.
- Release references held by applied and reset delayed callbacks, including failure/reconnect paths.
- Use reproducible large-catalog measurements to report peak heap and RSS, post-replay live heap after GC, allocation volume and startup time before and after. Distinguish transient input, retained cache and delayed logtail memory.
- Cover multi-batch tables, wide tables, concurrent logtail updates, replay failures/cancellation and reconnect, schema correctness and older metadata compatibility. Validate concurrency with race testing where applicable.
- Verify with production-representative scale and container limits before claiming the incident is resolved.
Activity
[4.2-dev] Reduce CN catalog replay memory (#32964)
slyunnn commentedon Nov 23, 2026
Stage verification update — #32963 (2026-11-23)
Status: partial validation. Merged components passed the checks below; production-scale memory acceptance remains incomplete.
Verified repair scope:
main: transient replay #32611,a192fddbb312d7986f6da9b2d71fd60fb2033cb4, and retained-schema/delayed-callback work #32948,c278bb2645f0975cd15d173398999a6884620fa0.4.2-dev: #32964,0b4d77f44c1ed30c91ffcc240b72217f7bfbd4f4, covering the extra column merge, parser ownership and delayed callbacks. The tested branch still retained bothTableDefandDefs; main's canonical-schema optimization is not claimed present there.Environment: macOS/arm64. Main component/race checks ran at
f86cc46cfc5d5e4a0e2e52af6e4cbd58f9f9c449with Go1.27.1;4.2-devchecks ran atf811a8673b44f592e5f60db10843de119d662e89with Go1.26.5. After the TN-only main port #33090 merged, separate SQL recovery also ran ate17d5541537d30252009a9a2d4c70ab5480d3bc3. External deployments used2 CN / 1 TN / 1 Log service / Proxy, with actual MySQL text SQL through Proxy6001, CN116001and CN216002.Verified in this stage
-race.TestDcaseparately verified callback references are released after reset and ordered application.-race(63top-level tests), along with borrowed-schema/ALTER rollback checks.-race. The existing4.2-devreconnect/rollback integration test also passed with-race.64live wide-table schemas and128rows, forced indexes and deleted-object controls matched before/after at all three external endpoints.Remaining verification
The original
1248931-table-row /9050305-column-row,24 GiBCN incident was not replayed. No new incident-scale before/after peak RSS/heap, post-GC retained heap, allocation-volume or startup-time measurements were obtained. Small correctness tests and PR-author measurements do not establish that acceptance. Retained-schema scope also remains incomplete on4.2-dev.Next step: use reproducible production-representative catalog/reconnect input for fixed-budget comparisons, measuring startup peak and steady-state memory separately; verify the
4.2-devretained-schema counterpart after it merges. Keep the issue open, withoutclose; no overall Fixed conclusion is claimed.slyunnn commentedon Nov 23, 2026
Partially fixed — representative-scale replay comparison completed; keep open (2026-11-23).
Actual Actions run:
15/15measurements passed, five staged revisions × three fresh-process rounds, exactly1,248,931tables /9,050,305column rows,24 GiBcontainer/no swap,GOMEMLIMIT=18GiB,GOMAXPROCS=4. All schema digests agree and input pool ownership returns to zero. Original incident data was not a prerequisite. No baseline OOM occurred, so the historical OOM was not reproduced.Latest source targets (remote HEADs rechecked unchanged):
e17d5541537d30252009a9a2d4c70ab5480d3bc3,fix(tae): bound catalog recovery memory on main (#33090); contains Reduce transient catalog replay memory #32611 (a192fddbb312d7986f6da9b2d71fd60fb2033cb4,Reduce transient catalog replay memory) and Reduce retained catalog schema memory after replay #32948 (c278bb2645f0975cd15d173398999a6884620fa0,Reduce retained catalog schema memory after replay).6faa4f240f38c56e89866e7eb1845b0f4cf3ec0c,[4.2-dev] perf(branch): resolve creation timestamps before catalog replay (#32925); contains [4.2-dev] Reduce CN catalog replay memory #32964 (0b4d77f44c1ed30c91ffcc240b72217f7bfbd4f4,[4.2-dev] Reduce CN catalog replay memory).Three-run medians, GiB:
21.758 → 10.4907.936 → 6.27020.794 → 12.6287.223 → 7.223Current main and 4.2-dev release about
64 MiBafter the independent callback apply/reset payload probes. Main's retained stage has a timing tradeoff versus its transient-only stage: replay including generation is57.89 sversus48.84 s(14.94 sversus13.27 sexcluding generation). These are staged-revision comparisons; no uniform latency improvement is claimed.The probe calls unchanged production
PushClient.replayCatalogCachevia an external test overlay. Only the SQL result provider is synthetic. It excludes real scan/sort, object-store I/O and complete CN startup; these times are component times. This is not an incident-scale concurrent-logtail memory run. Latest-branch owning tests separately passed under-race: main63+10+3, 4.2-dev9+1, including real replay/reconnect and failure/cancellation controls.Earlier small SQL checkpoint controls used complete
2 CN / 1 TN / 1 Log service / Proxydeployments, actual text/binary execution on Proxy6001, CN116001, CN216002(main@e17d554,4.2-dev@f811a867); they are separate correctness evidence, not this memory measurement.The scale memory/allocation/ownership gap is now measured. Remaining work: 4.2-dev's retained-schema optimization has not merged and is not claimed; full CN startup scan/I/O timing also remains unmeasured. Port and measure the retained change when merged, and complete end-to-end startup acceptance before claiming the incident resolved.
Test PR #287, author
slyunnn, contains the probe and validated collector; the run artifact retains raw metrics, profiles and build identities. Containers and the exclusive lease were cleaned up. Keep #32963 open withoutclose.slyunnn commentedon Nov 24, 2026
Partially fixed — TKE stage verification consolidated (2026-11-24); keep open.
Targets: main
98d7e9ea90f068a2bcbbecef8796d67ec32ef263(perf(prepare): statement-owned storage for planner parameter values (#33076) (#33083)) and 4.2-dev9ed1645371c63ad2c417022de9e4d56db8697ecc([4.2-dev] test(morpc): stabilize blackholed timeout tests (#33122)). Both contain their corresponding merged #32963 fixes. Test PR #1963, revision9ea93009cb9bc1509556998a41953ece08387849; dispatches usedslyunnn.TKE topology: isolated fixture/writer TP CN, base AP CN and a fresh measured CN, one TN, three HA Log services and Proxy. Clients use public MySQL text SQL and SQL PREPARE/EXECUTE. The fixture TP uses 14 CPU / 55 GiB, GOMEMLIMIT=35GiB; base AP and measured CNs use 4 CPU / 24 GiB, measured GOMEMLIMIT=18GiB, no swap. Production service code and memory-admission protection are unchanged.
1064). Measured CN startup had not begun; all pods had zero restarts and owner cleanup passed. Only the fixture TP budget was raised to 55GiB; this was not a measured CN startup/OOM failure.seed-calibration.json. Original SQL errors and seeding progress are retained. The image-only prewarm selector creates no second fixture cluster. All 4.2-latest, main-before and 4.2-before image prewarms passed. Seven targeted local checks and three scheduler checks passed; workflow lint retained only four documented baseline findings. TKE Family Contract and Test Control Inventory CI passed.The previously published representative-scale component comparison remains valid, separate evidence; it excludes complete CN startup scan/sort and object-store I/O. Production-representative real-CN acceptance remains necessary before claiming the incident resolved; its absence does not prevent this Partially fixed stage report. The four-subject / three-round plan was a test-design choice, not an explicit issue requirement.
Remaining 4.2-dev requirement: the issue explicitly asks to reduce retained per-table and per-column overhead on both branches. In the completed component comparison, 4.2-dev post-GC live heap remained
7.223 → 7.223 GiB, although replay peak RSS fell from20.794 → 12.628 GiB. Thus the tested revisions demonstrate transient-memory improvement, but do not demonstrate the requested retained-schema reduction. A source-only recheck on 2026-11-25 at4.2-dev@bb197e5118507d830f5e50f99a2676bb88a8d62fstill shows both definitions being constructed and retained; this newer commit was not memory-benchmarked. An equivalent retained-memory optimization is acceptable: the issue does not require an identical backport of main PR #32948. Once an applicable change merges, verify its retained-memory reduction and schema/ownership correctness. This remains a repair/acceptance gap within #32963.Keep #32963 open, without a
closelabel; no overall Fixed conclusion is claimed.