Skip to content

Reduce CN catalog replay peak and retained metadata memory on main and 4.2-dev #32963

Done

Description

@XuPeng-SH

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, replayCatalogCache retains 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
  • main contains 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-dev at 7d1cacc6dd still 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.flist with [:0] after applying delayed logtail closures and on reset. The backing array retains the old closures, which capture *api.Entry and *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
  • TableItem retains 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

  1. self-assigned this
    on Nov 20, 2026
  2. slyunnn commented on Nov 23, 2026

    @slyunnn

    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 both TableDef and Defs; main's canonical-schema optimization is not claimed present there.

    Environment: macOS/arm64. Main component/race checks ran at f86cc46cfc5d5e4a0e2e52af6e4cbd58f9f9c449 with Go 1.27.1; 4.2-dev checks ran at f811a8673b44f592e5f60db10843de119d662e89 with Go 1.26.5. After the TN-only main port #33090 merged, separate SQL recovery also ran at e17d5541537d30252009a9a2d4c70ab5480d3bc3. External deployments used 2 CN / 1 TN / 1 Log service / Proxy, with actual MySQL text SQL through Proxy 6001, CN1 16001 and CN2 16002.

    Verified in this stage

    • Both branches passed selected carry/parser ownership, split-table, cancellation/deadline, partial allocation failure and retry tests with -race. TestDca separately verified callback references are released after reset and ordered application.
    • Main's complete cache package passed with -race (63 top-level tests), along with borrowed-schema/ALTER rollback checks.
    • Main's real multi-CN catalog replay, logtail reconnect and durable restart tests passed with -race. The existing 4.2-dev reconnect/rollback integration test also passed with -race.
    • Both branches passed full SQL checkpoint/restart checks: all 64 live wide-table schemas and 128 rows, 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 GiB CN 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 on 4.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-dev retained-schema counterpart after it merges. Keep the issue open, without close; no overall Fixed conclusion is claimed.

  3. slyunnn commented on Nov 23, 2026

    @slyunnn

    Partially fixed — representative-scale replay comparison completed; keep open (2026-11-23).

    Actual Actions run: 15/15 measurements passed, five staged revisions × three fresh-process rounds, exactly 1,248,931 tables / 9,050,305 column rows, 24 GiB container/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):

    Three-run medians, GiB:

    Branch Replay peak RSS, before → latest Post-GC live heap, before → latest
    main 21.758 → 10.490 7.936 → 6.270
    4.2-dev 20.794 → 12.628 7.223 → 7.223

    Current main and 4.2-dev release about 64 MiB after the independent callback apply/reset payload probes. Main's retained stage has a timing tradeoff versus its transient-only stage: replay including generation is 57.89 s versus 48.84 s (14.94 s versus 13.27 s excluding generation). These are staged-revision comparisons; no uniform latency improvement is claimed.

    The probe calls unchanged production PushClient.replayCatalogCache via 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: main 63+10+3, 4.2-dev 9+1, including real replay/reconnect and failure/cancellation controls.

    Earlier small SQL checkpoint controls used complete 2 CN / 1 TN / 1 Log service / Proxy deployments, actual text/binary execution on Proxy 6001, CN1 16001, CN2 16002 (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 without close.

  4. slyunnn commented on Nov 24, 2026

    @slyunnn

    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-dev 9ed1645371c63ad2c417022de9e4d56db8697ecc ([4.2-dev] test(morpc): stabilize blackholed timeout tests (#33122)). Both contain their corresponding merged #32963 fixes. Test PR #1963, revision 9ea93009cb9bc1509556998a41953ece08387849; dispatches used slyunnn.

    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.

    • Pilots passed: main45352212949 and 4.2-dev45356742202. Each created exactly 1,000 user tables / 40,000 column rows using 25-table transactions, then passed cold CN startup, complete metadata/schema/default/data readback, same-process receiver-fault replay, prepared-session refresh and the retained-heap bound. Source/image, cgroup and owner-checked cleanup artifacts were independently accepted. Main seeding took 18.60s and startup RSS high-water was 443.29MiB. These small-pilot results do not establish representative-scale memory acceptance or a measured full-scale speedup.
    • Preparation failure diagnosed: run45337821016 stopped after at least 682,500 completed tables when the unmeasured 24GiB TP hit physical-memory admission protection (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.
    • Preparation optimized: bounded 25-table transactions drain COMMIT responses and roll back on error. The full-run implementation compares autocommit and batching through four 4,000-table ABBA timing windows with 16 workers; those tables count toward the original fixture target. Batching is selected only for at least 10% observed throughput gain, with raw timings in 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.
    • Full acceptance remains incomplete: run45348409717 was cancelled at the user's request for optimization, with owner cleanup verified. The subsequent main full run45362483057 was also cancelled; zero of its planned three fresh-CN rounds were accepted, no final fixture manifest was produced, and owner cleanup was verified. The original full target was 1,248,931 user tables / 9,050,305 column rows. The serial follow-up stopped; no full 4.2 or before-fix measurement was obtained. A cancelled preparation run is neither a product failure nor an acceptance result.

    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 from 20.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 at 4.2-dev@bb197e5118507d830f5e50f99a2676bb88a8d62f still 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 close label; no overall Fixed conclusion is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions