Skip to content

[Bug]: TN OOM restart loop during large catalog recovery after relation churn #33072

Done

Description

@XuPeng-SH

Problem

A TN in a 25 GiB container repeatedly OOMs after a period of heavy catalog churn. During a later startup attempt, a live goroutine snapshot shows the TN still reading system tables during checkpoint/catalog replay. The deployed implementation accumulates each entire system table in a single batch and only applies deletes after reading all blocks; table and column batches are then sorted and kept alive for asynchronous replay.

This is a TN recovery issue, distinct from the CN-side replay/retained-metadata work in #32963. The source and metrics indicate a plausible memory-amplification mechanism, but the exact off-heap allocation stacks and the first OOM's trigger have not yet been proven.

Observed evidence

All times below are UTC+8 on 2026-11-22/23. Deployment revision: c66030006f (4.2.8 hotfix); TN container request/limit: 25 GiB; GOMEMLIMIT=18000MiB.

  • From approximately 23:18 on Nov 22 through 10:14 on Nov 23, the TN restarted about 79 times. Recent recorded attempts were terminated OOMKilled; not every historical restart reason was individually verified.
  • In the two hours before the restart loop, TN INFO logs recorded 116,760 tn.handle.create.relation entries and 20,410 tn.handle.drop.relation entries. In the final hour the counts were 78,407 and 15,364, respectively. These are handler log entries, not confirmed committed user-table counts: they can include retries, rollbacks, and internal relations.
  • Before the first dense restart period, the container working set rose from about 22.68 GiB at 21:18 to 24.97 GiB at 23:13; the Go allocated heap was approximately 17.88 GiB at 21:18 and 18.87 GiB at 23:12. This is different from the off-heap pattern on later restart attempts.
  • During a later attempt on Nov 23, the mpool off-heap in-use metric rose from 6.74 GiB at 09:58 to 12.98 GiB at 10:00. Memory-cache off-heap was approximately 2 GiB throughout; RSS reached approximately 15.49 GiB at 10:00 and the cgroup later reached its 25 GiB limit. These categories are included in RSS and must not be summed with it.
  • A 10:05:36 goroutine snapshot from a subsequent process generation showed db.Open -> Controller.AssembleDB -> replayFromCheckpoints -> ReplayCatalog -> ReadSysTableBatch -> FillBlockTombstones -> Bitmap.TryExpandWithSize. That snapshot identifies the active recovery path, not the allocation stacks of the previous OOM. The Go heap profile from that generation cannot explain the much larger mpool off-heap growth.
  • TN tae_* mpool gauges were zero in sampled startup windows while the global and off-heap mpool counters grew; do not interpret these zero values as proof that TAE allocated nothing. The individual TAE gauges are updated by a background task, and the snapshot showed startup still inside AssembleDB.

We have not established that all observed create/drop handlers committed, that DDL churn caused the original OOM, or exactly which replay allocation path consumed the off-heap memory.

Relevant implementation

  • ReadSysTableBatch at deployed revision appends all visible blocks to one batch with CheckpointAllocator and calls Compact() only after reading them. There is already a TODO about limiting batch size.
  • HybridScanByBlock reads the block and collects persisted and workspace deletes. Filtering must preserve transaction visibility and correct per-block delete offsets.
  • RelayFromSysTableObjects materializes and sorts table and column batches. ReplayCatalog retains their close callbacks until queued work completes. Async replay closures depend on those inputs, so simply freeing the batches earlier would be unsafe.
  • TAE vector construction uses off-heap vectors. The bitmap's []uint64 itself is Go heap; do not infer that its stack accounts for the mpool growth.
  • The whole-table accumulation and sort path also exists on main at 4cadd4f2f6; the incident was observed only on the 4.2.8 hotfix.

Direction and acceptance

  • Investigate the actual off-heap owners and distinguish startup input buffers, cache, sorting, catalog state, and asynchronous replay. Capture generation-matched malloc/mpool profiles when practical; do not infer allocation origin from one goroutine snapshot.
  • Consider filtering visible rows and applying complete tombstones per block before accumulating, releasing temporary block data promptly. Verify actual backing-buffer reclamation: shortening a vector alone may not reduce its allocated capacity.
  • Address the larger design: reconstruct catalog with bounded transient input rather than materializing and sorting entire system tables where practical. Existing object order is not necessarily globally sorted; preserve cross-block table/column association, schema/version order, snapshot visibility, and any required ordering. An incremental first step must not be presented as a hard memory bound if the remaining live catalog can still grow without bound.
  • Keep ownership explicit across queued replay work; release each input only after its last consumer. Avoid new persistent state or SQL reads merely for the fix.
  • Add realistic large-catalog tests including high create/drop churn, many live tables and columns, tombstones across blocks, empty/all-deleted blocks, schema versions, cancellation/error paths, and concurrent replay ownership. Validate recovered schema, indexes, and data, and measure peak RSS, Go heap, mpool, startup time and I/O before/after under a fixed memory budget.
  • Reproduce or otherwise establish the original failure before declaring this incident fixed; the initial pre-restart heap growth may need a separate investigation.

Activity

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

    @slyunnn

    Stage verification update — #33072 (2026-11-23)

    Status: partial validation. The merged recovery mitigation passed the checks below; the original OOM incident is not established as fixed.

    Verified commits, independently:

    • 4.2-dev: f811a8673b44f592e5f60db10843de119d662e89, #33078, fix(tae): bound catalog replay input memory.
    • main: e17d5541537d30252009a9a2d4c70ab5480d3bc3, #33090, fix(tae): bound catalog recovery memory on main.

    Environment: native macOS/arm64, independently built binaries; Go 1.26.5 for 4.2-dev and Go 1.27.1 with GOEXPERIMENT=simd for main. The external deployment used 2 CN / 1 TN / 1 Log service / Proxy. MySQL text SQL actually executed through Proxy 6001, CN1 16001 and CN2 16002; these were not connection-only checks.

    Verified in this stage

    • Both branches passed actual system-table checkpoint/restart tests with 80 tables, 128 columns per table and 16 drops. Coverage includes cross-block columns, persisted/workspace deletes, snapshot visibility, cancellation, read errors, recovered schema and saved row lookup.
    • Catalog/pool/tombstone tests passed cross-block ownership, malformed metadata, checked-out borrowers and concurrent close/borrow/return under -race. Main additionally passed accepted-replay-task cancellation/drain tests under -race.
    • Separate full SQL launcher restarts passed on both branches after checkpointing wide tables, row/table deletion, secondary indexes and multiple schema changes. At each external endpoint, all 64 live user schemas and 128 remaining rows matched the pre-restart hashes; forced-index results matched scans.

    Remaining verification

    The original 25 GiB OOM loop and preceding heap growth were not reproduced. This stage did not obtain incident-scale, fixed-budget before/after peak RSS, Go heap, mpool, startup time or I/O measurements. PR-author measurements are not counted as this run's evidence. Streaming temporary inputs does not bound total live-catalog memory.

    Next step: obtain an anonymized reproducible incident checkpoint/churn fixture and generation-matched allocation evidence, then run matched recovery comparisons under the original memory budget. Keep this issue 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