Repository navigation
fix(tae): bound catalog replay input memory - #33078
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? |
|
This pull request is merged. |
|
mo-bot review · Commit: linked issue or PR description changed before publication |
|
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: bc4cbe883488a55de9e5357edc46d9a3fba4d798
Assessment: request_changes
Block-by-block replay removes whole-system-table buffers and reuses the existing visibility scan, schema finalizer, and replay workers. Cancellation still fails to reach the storage read for persisted appendable tombstone timestamps.
Model: gpt-6.2-sol / xhigh
Session: 01a20682-9189-75a0-839a-f36d8b2372a5 · slot 1 · generation 3
- P2
pkg/vm/engine/tae/tables/table_scan.go:190: The caller cancels catalog replay while the scanner is reading commit timestamps for a persisted appendable tombstone.
Impact: The storage read can continue past the caller’s deadline. Replay and block cleanup wait for it to return.
Evidence: The scan passes its context to tombstone filtering. In tables/pnode.go:406, LoadPersistedCommitTS replaces it with context.Background() in tables/base.go:164. A diagnostic probe canceled at the exact timestamp read and confirmed that the storage context stayed active. Pass the caller’s context to the existing loadPersistedCommitTS helper and cover in-flight cancellation.
Validation:
-
Isolation preflight, native prerequisite build, and diff whitespace check passed. Matching logs and receipts are listed in review-plan.md.
-
Full race suites passed for catalog, tables, checkpoint, and db. Focused TAE integration tests passed under the race detector, including checkpoint restart, tombstone visibility, compatibility, and rename. The catalog ownership test passed 100 repetitions.
-
The diagnostic cancellation probe reproduced the finding. Its log is catalog-cancel-probe.log and its terminal receipt is checks/1795406748215980174-2.json.
Limitations:
-
The cancellation probe used an injected file service and a real persisted system-table scan. It did not reproduce a production TN startup stall.
-
The V12 compatibility fixture was synthetic. The author’s large-catalog performance and multi-database correctness comparisons were reported in the PR description and were not independently rerun.
|
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: 9c1eafea08ed450835f0c6e20363ef7e2df74bcf
Assessment: request_changes
Block-by-block replay removes whole-table buffers and reuses the existing visibility scan and replay workers. The new pool cleanup releases idle buffers while preserving active borrowers. The prior finding remains open because cancellation still fails to reach persisted appendable tombstone timestamp reads.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
- P2
pkg/vm/engine/tae/tables/table_scan.go:190: Cancel TN startup while catalog replay reads commit timestamps for a persisted appendable tombstone.
Impact: The storage read can continue past the caller’s deadline. Replay and block cleanup must wait for it to return.
Evidence: The scanner forwards its context, but pkg/vm/engine/tae/tables/pnode.go:406 calls a wrapper that substitutes context.Background() at pkg/vm/engine/tae/tables/base.go:164. The current-head probe canceled at the exact read and observed a live storage context. The same probe passed when the call used loadPersistedCommitTS with the caller’s context. Forward that context and retain the in-flight cancellation regression.
Validation:
-
Isolation preflight, frozen diff and policy verification, and retained native input checks passed. Matching receipts and logs are recorded in validation-assessment.md.
-
The containers, catalog, tables, checkpoint, and DB packages passed under the race detector. Focused checkpoint, restart, and repeated failed-open tests passed, as did 100 concurrent pool close, borrow, and return repetitions.
-
Restoring the previous DB cleanup code left 21,104 bytes allocated in the transient pool after a failed open. The candidate passed the same cleanup assertion.
-
The cancellation defect reproduced on the assigned head and the context-forwarding control passed. See catalog-cancel-race.jsonl and catalog-cancel-control-race.jsonl with receipts 1795408948926216700-2 and 1795408997135711883-2.
Limitations:
-
Cancellation was verified with an injected file service in a real persisted system-table scan. A production TN startup stall was not reproduced.
-
The V12 fixture was synthetic. The released-binary shutdown upgrade and the author’s large-catalog performance comparison were not independently rerun.
|
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: 3b82a8848bb451421aefc6dcbced07c7695954a3
Assessment: approve
Catalog replay replaces whole-table buffers with one-block scans and owned schemas, while retaining snapshot visibility and the existing sharded workers. Pool shutdown releases idle buffers and preserves active borrowers. The persisted tombstone timestamp read now honors the caller’s cancellation, closing the prior finding.
Model: gpt-6.2-sol / xhigh
Session: 01a1ee80-0d82-7030-a965-b51f496c3054 · slot 2 · generation 1
Validation:
-
Isolation preflight, frozen diff and policy verification, and native input verification passed. Receipts and logs are indexed in validation-assessment.md.
-
The full tables package and 100 repetitions of the exact tombstone cancellation test passed under the race detector. See tables-race.jsonl and cancel-stress-race.jsonl.
-
Five focused race checks passed for checkpoint restart, legacy checkpoint decoding, failed-open pool cleanup, and cancellation during a persisted system-table scan. See recovery-race.jsonl and checks/1795410799802954254-2.json.
Limitations:
-
Compatibility evidence covers a synthetic V12 checkpoint and inspection of the v4.2.8 and deployed hotfix writers. A released-binary shutdown upgrade was outside local execution.
-
The large-catalog performance figures come from the author’s warm-filesystem synthetic workload. The original production OOM cause remains open.
## What type of PR is this? - [x] BUG - [x] Improvement ## Which issue(s) this PR fixes: Refs #33072. Backports #33078 from `4.2-dev` to `main`. ## What this PR does / why we need it: TAE recovery accumulated each entire system table in off-heap batches before replaying the catalog. A large catalog therefore needed substantial transient memory in addition to its recovered schemas. Scan visible catalog rows one block at a time using the existing snapshot and tombstone machinery, copy retained values into owned schemas, and submit validated tables to the existing database-sharded executor. Allow a blocked submission to withdraw on cancellation and wait for already-admitted tasks before returning. Release DB-owned vector pool buffers on failed open and normal close without invalidating checked-out vectors. The main-branch port keeps its existing catalog type encoding, rename/object replay and persisted tombstone read paths. It also preserves the released `NextColSeqnum == 0` ordinal fallback, including for evolved schemas, while rejecting non-ordinal sequence data that cannot safely be recovered without its high-water mark. The persisted format is unchanged. The original production OOM trigger is not established. This PR reduces a demonstrated recovery amplification; it does not establish that the original incident's full cause is fixed. ## Validation - Complete owner-package tests under `-race` for catalog, containers, tables, checkpoint and DB; selected checkpoint/restart, snapshot, ALTER, rename, persisted-delete and transaction consumers under `-race`. Focused lifecycle and concurrent cases were each timed and repeated in one process according to the repository's adaptive race protocol. They cover block ownership, legacy missing/NULL sequence numbers, persisted tombstone cancellation, canceled queue admission, draining accepted work, pool close/borrow concurrency and failure cleanup followed by reopen. A no-wait mutation made the `ReplayCatalog` drain test fail. That test injects accepted work before the method call; it does not reproduce admission during the same scan. - Incremental `go vet`, `molint`, `golangci-lint`, formatting, `git diff --check` and `make err-check` passed on the changed package closure. - Fresh official 4.2.8 deployment: create 10,000 tables with a primary-key column and 16 distinct default-valued columns each, drop 1,000, exercise ALTER/drop-and-add, rename, indexes, ENUM, generated columns, defaults, ON UPDATE, inserts, updates and deletes, force a global checkpoint, then cleanly stop log/TN/CN. Independently restart copies with `main` base and this change. Each of six runs checks all 9,000 expected live tables, the complete 162,000-row column set, column names/ordinals/sequence values, and the expected default literals. Serialized type/default metadata is identical between base and candidate across all runs. Data and writes match; queries of both a pre-upgrade row and a post-upgrade row use the secondary index, as confirmed by EXPLAIN. - Same 4.2.8 checkpoint, three fresh-process runs per version in A-B-B-A-A-B order, local warm filesystem and shared Docker Desktop arm64 host. Median measurements below are local observations, not a production forecast: | Measurement | main base | candidate | | --- | ---: | ---: | | Catalog replay | 1.438 s | 0.396 s | | TN RSS high-water mark | 1,114,448 KiB | 851,844 KiB | | Global mpool high-water mark | 138,294,271 B | 53,520,472 B | | Sampled Go-heap peak | 622,579,816 B | 677,719,392 B | | TN start to SQL ready | 20.50 s | 19.60 s | RSS and mpool are process-lifetime high-water marks captured before verification queries; the mpool metric refreshes every five seconds. Heap was sampled approximately every 100 ms and increased in this small sample. The end-to-end ready metric includes the local CN/log services. These results do not establish production throughput, tail latency or mixed-version rollout behavior. - A four-worker vector-pool borrow/return microbenchmark, six alternating runs per version, measured medians of 104.7 vs 96.4 ns/op, with overlapping ranges and one allocation per operation on both versions. This small local microbenchmark does not establish DML/DQL performance. The 4.2.8 and main SQL metadata displays differ for collation; the main base and candidate outputs match. Cross-version collation semantics beyond the tested queries have not been established by this backport.
What type of PR is this?
Which issue(s) this PR fixes:
Refs #33072 (the catalog-replay memory amplification)
What this PR does / why we need it:
TN recovery previously read every block of each catalog system table into a single off-heap batch, compacted and sorted it, then retained the table and column batches while replay jobs consumed them. A large catalog therefore required substantial temporary memory in addition to the recovered catalog.
Scan snapshot-visible system-table rows one block at a time, apply the existing persisted and workspace tombstones, and release each block after decoding it. Build owned schemas for live tables, associate their columns across blocks, and submit validated schemas in the existing database-sharded replay order. Propagate the open context through persisted appendable-tombstone commit-timestamp reads and drain already-submitted jobs on failure. Remove the old whole-table accumulation and sorting path. This adds no SQL or persistent state; the live catalog itself and the underlying cache still consume memory proportional to their contents.
Malformed or incomplete schema metadata is rejected before table replay, including missing parent databases and physical row IDs, inconsistent column sequence numbers, and corrupt types. Valid legacy default values are preserved where they can be recovered safely.
DB-owned vector pools now release idle buffers on failed open and normal close. A checked-out vector remains valid until its borrower returns it; pools do not close the shared allocator. Previously, repeated failed opens or open/close cycles retained one transient pool's off-heap buffers per attempt.
Validation
make err-check.db.Openduration was 2,035 -> 1,566 ms; mpool high water 533,700,544 -> 87,158,784 bytes; sampled RSS peak 2,303,541,248 -> 1,116,733,440 bytes; cumulative mpool allocations 2,760,551,912 -> 699,901,592 bytes; sampled Go-heap peak 930,177,816 -> 915,383,904 bytes. RSS and heap were sampled every 10 ms. These synthetic measurements use a warm local filesystem and a shared host; they are not a production forecast or a cold object-store benchmark.The original production OOM trigger and exact off-heap allocation owners have not been established; the earlier pre-restart Go-heap growth remains a separate investigation. This PR reduces a demonstrated recovery amplification and does not by itself establish that the entire incident is resolved.