Repository navigation
[4.2-dev] Reduce CN catalog replay memory - #32964
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: {"message": "You\u2019ve hit your usage limit. Visit https://chatgpt.com/settings/usage to purchase more credits or try again at Nov 20th, 2026 9:12 PM.", "codexErrorInfo": "usageLimitExceeded", "additionalDetails": null, "misalignment": null} |
There was a problem hiding this comment.
Review update: I overstated the severity of the two findings below. They are non-blocking, and both were addressed in commit efe8fb12e41da43bbc81689f58a96c3ae917b2e2. I recommend approval. The backport's main design is sound. It preserves the catalog cache as the schema parser and reuses the existing logtail publication gate. The two fixes below are local.
- Remove the unreachable carry state. The copy at the end of the loop is reached only with
carry == nil. If an earlier carry consumes the whole input, thestart == rowspath continues. If it consumes a prefix, the precedingflusheither returns an error or setscarry = nil. The allocation guard is therefore always true, and the trailingelse if carry != nilcannot run. Delete both branches and keep the invariant visible at the allocation site. replay_columns.go:145 · replay_columns.go:205 - Unregister the pools used by the replay tests. Ten of the eleven new pool allocations omit
DeleteMPool.MustNewZeroregisters each pool and its allocation counter globally. Zero outstanding vector bytes confirms that buffers were released, but the pool entries remain registered across cases and repetitions. Registert.Cleanupwhen each test creates its pool, as the partial-insert retry case already does. replay_columns_test.go:85 · mpool.go:635
The two-CN race probe exercised the real reconnect and SQL catalog query on this head. I split the real executor result between two rows of the same table, producing two independently owned batches of 5,433 and 5,434 rows. After readiness returned, SQL read the first and last columns of all 30 tables and verified a rename and the new column's default. The fixture's natural executor result was a single batch. The separate nine-million-row component probe reduced observed process RSS from 2.50 GiB to 1.22 GiB with a narrow schema and counting callback. The test body took 2.05 s on the base and 5.53 s on the head in that pair. The probe covers neither SQL sort nor retained table definitions, so production startup latency and peak memory remain unverified.
All nine focused replay and delayed-queue race tests passed on the same head. There were no actionable review threads or code findings in the existing PR comments. The current PR body appropriately scopes the memory claim, and the diff adds no documentation files.
…ssue28931 index queries (#32977) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #32975 (fixes the `4.2-dev` side; the `main` branch needs the same fence and remains tracked by the issue). ## What this PR does / why we need it: `TestIssue28931StaleUpdatePlanCannotBypassNewIndex`'s `regular index includes the update` subtest ran `IGNORE INDEX(ix_payload)` and `FORCE INDEX(ix_payload)` on the writer CN immediately after `finishDDL()` returned. `finishDDL()` only joins the CREATE INDEX goroutine on the ddl CN, so it does not establish that the writer CN has applied and synchronized the index commit timestamp. The hinted queries could therefore fail with `Error 1176 (42000): Key 'ix_payload' doesn't exist in table 'regular_update'` (observed in the #32964 UT coverage run) instead of testing index/table result consistency. Move the existing `syncAuthenticatedClusterCommit(t, ctx, cluster)` call to immediately after `finishDDL()` succeeds, before any index-dependent statement, and delete the old post-assertion fence site, matching the fence ordering already used by `TestIssue32346AlterIndexIncludesCommittedWrites`. No sleep or retry is introduced; all assertions are unchanged. Validation on Linux/amd64: - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -v -run '^TestIssue28931StaleUpdatePlanCannotBypassNewIndex$' ./pkg/tests/issues/` passed on the final revision: the parent test and all six subtests PASS (13.34s; `ok github.com/matrixorigin/matrixone/pkg/tests/issues 13.412s`, exit 0, no error 1176), including `regular_index_includes_the_update`. - `gofmt` and `go vet -mod=readonly ./pkg/tests/issues/` clean.
CN startup and catalog-scale comparisonCompared base
At 400k tables, the two-run mean CN startup was about 7% shorter and peak CN RSS about 30% lower with the PR; TN RSS was similar within the observed variation. These are observations from two runs per version, not statistical bounds. Every base run entered the original Measurement details and limits
Separately, short real-service SQL checks covered point and prepared lookups, range and index queries, aggregation, JOIN, INSERT, UPDATE, DELETE transactions, and concurrent reads/writes with 1 or 8 clients. They did not show a consistent regression in the sampled scenarios. Standalone disk-write results were heavily affected by I/O variation, so they do not establish equal production write performance. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Review: no blocking findings; recommend approval
Reviewed 4.2-dev base 505977beb20ca120822ad0516ae7d85cd1cb7158 against head efe8fb12e41da43bbc81689f58a96c3ae917b2e2. GitHub does not permit the PR author to approve their own PR, so this is recorded as a review comment rather than an approval.
The replay keeps catalog parsing and logtail publication in their existing owners. Ordering by numeric identity makes each table contiguous; complete windows are consumed synchronously, only a split table is copied, and the source batches have cleanup owners on success, cancellation and allocation failure. The database/table result lifetimes and delayed callback reset/apply were also checked. The old full-result merge and its split detector are removed. The two previously reported review points, unreachable carry branches and test mpool registration cleanup, are fixed on this head. There are no other review threads with unresolved code comments.
The added component tests cover split and empty batches, ordering and name conflicts, retained parser data, cancellation, retry, and partially allocated failure paths. The current-head CI passed, including the UT job and the real-cluster TestDropDatabaseReconnectRollback cases; multi-CN BVT jobs passed. I also considered the earlier two-CN forced-split race probe from the preceding head; the relevant production difference on this head removes unreachable branches. I reused the author/CI validation rather than independently rerunning those runs.
The real-service comparison reports 4.83–5.07 GiB versus 7.04 GiB CN peak RSS at about 2.9 million columns, with alternating base/PR runs. The incident-scale approximately 9.05 million-column startup and OOM outcome remain unverified; this review supports the scoped reduction in replay overhead, not a claim that the production incident is fully reproduced and resolved.
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #32426 ## What this PR does / why we need it: After #32611 removed the full column-batch merge, each live catalog version still retained both the engine attribute graph and the planner definition. This change retains a canonical planner definition, the original constraint bytes and the engine fields that cannot be reconstructed from the planner. Relations borrow the published planner for reads and build private definitions for consumers that require ownership. Old readers retain their catalog version across DDL. Failed ALTER restores the previous schema and version. **Linux memory comparison.** The base was `e765c5fd44`. The measurements below used `b3139f9e09`, whose Git tree matches the original PR commit `3a3f034bdf`. With Go 1.27.4 on linux/amd64, each binary ran in three independent cgroup v2 services with a 16 GiB limit, swap disabled, the same CPU set, GOMAXPROCS=4 and GOMEMLIMIT=12GiB. Runs were interleaved. The deterministic fixture contained 630,124 tables and 4,410,868 columns (six varchar columns plus a hidden rowid per table). The harness prebuilt sorted input batches of up to 147,029 rows and invoked the production `consumeReplayColumns` and `CatalogCache.InsertColumns` paths across batch boundaries. | Median of three runs | Base | Candidate | Change | | --- | ---: | ---: | ---: | | Live Go heap above process baseline after input release and GC | 3.586 GiB | 2.793 GiB | −22.13% | | Cgroup peak through input preparation, replay, cleanup and GC | 6.138 GiB | 5.425 GiB | −11.62% | | Cgroup peak including the subsequent engine/planner readback of every table | 6.138 GiB | 6.297 GiB | **+2.59%** | | Whole-process maximum RSS including readback | 6.193 GiB | 6.354 GiB | +2.61% | | Column batch application | 5,019 ms | 4,813 ms | −4.10% | All six runs verified every table, planner and engine column metadata, zero remaining input-pool ownership and zero cgroup OOM events. The exhaustive readback builds private projections in the candidate and reads retained definitions in the base. A separate 40,000-table aligned control measured a 22.12% reduction in retained heap. First Relation open in a fresh transaction measured 1,801 → 1,856 ns/op (+3.05% median over three processes per revision, 1,000 opens per process), with nine allocations per open on both revisions. **SQL and ownership validation.** Both service binaries restarted successfully from byte-identical copies of one persisted snapshot. Both exposed 2,049 user tables and 14,339 columns and produced identical sampled rows, composite key, secondary index and decimal default. Both read 18,096 catalog column rows during SQL restart. Linux single-process cache tests, focused replay ownership/cancellation and ALTER rollback tests passed on the candidate. Multi-CN replay and durable restart tests passed on both revisions. The previous same-tree Darwin validation also passed cache, disttae and pb/plan normal and race tests. **Remaining QA coverage.** The scaled input is synthetic. The current and two earlier development records contained generated fixtures and heap profiles. The original QA data, workload and reconnect topology were unavailable for offline replay. The original 16 GiB incident remains open for verification. Costs for projecting many schemas concurrently and end-to-end logtail transport at incident scale remain unmeasured. After synchronizing with `main` at `d2e71035db`, Linux validation at `6734419e13` passed the build, the pb/plan, disttae/cache and disttae unit tests, multi-CN replay and durable restart tests, and the license-header check for all 35 changed Go files. At `e2d594e1ab`, catalog type reconstruction explicitly checks whether the planner ID fits the engine OID and whether that OID supports a default type. The original engine type remains available for unsupported types. Existing strict callers keep their panic contract. The Linux build, types/cache/disttae unit tests, multi-CN replay and durable restart tests passed. The pinned CI tools checked the six changed packages with molint and golangci-lint (zero issues), and license-eye accepted all 37 changed Go files. ## Review follow-up Statistics refresh and ANALYZE now read the published planner schema under an existing catalog publication guard. Collection releases the guard before object I/O. Primary-key lookup reconstructs only the selected attributes and their private expression metadata. Empty collection skips allocation of per-column statistics buffers. The catalog replay changes from #32964 release the delayed callbacks on reset or after ordered application, simplify the cross-batch carry path, and clean up the replay test pools. The ownership design records publication, borrowing, private copies, ALTER rollback, and reconstruction costs. [Catalog schema ownership design](https://github.com/matrixorigin/matrixone/blob/bd1fbb64e30c245fc358465a3ff4f90f7ddc69cd/docs/design/20261120-catalog-schema-ownership.md) | Allocation per component call on 256 user columns | Before | After | | --- | ---: | ---: | | Stats catalog lookup and schema access | 197,376 B | 352 B | | Single primary-key projection | 63,512 B | 216 B | The same synthetic schema served as both controls. The new paths allocated the same number of bytes on 16 and 256 user columns. These measurements cover the two component reads. Validation on Darwin/arm64 with Go 1.27.1 covered type, planner, and cache unit packages, configured incremental lint, and focused race tests for schema ownership, stats publication, ALTER rollback, replay failures, reconnect, multi-CN replay, and durable restart. The stats regression test compares borrowed and owned definitions on a persisted object with a sparse physical column sequence number. Relation-level tests cover zero, single, and hidden composite keys along with mutation isolation. The delayed-queue test fails both release assertions with the prior implementation and passes with this change. Incremental license-eye accepted all 40 changed Go files. Independent design and review gates completed on GPT-6.2-sol/xhigh and GPT-6.1-terra/max, respectively. ## Table-status metadata follow-up The table-status path uses the planner definition already obtained for relation admission. It reads the opened relation's schema version and scans its columns without rebuilding private engine definitions. The allocator lookup uses the same normalized name as CREATE. A view, a physical row ID, and a hidden synthetic primary key do not supply a user allocator. A visible column may use the fake primary-key name. The two tagged diagnostic files were removed. The normal candidate and ALTER-copy tests cover their ownership assertions. [Catalog schema ownership, revision 2](https://github.com/matrixorigin/matrixone/blob/daac1a097507af4aed26644c7347eae96b1ed2b5/docs/design/20261120-catalog-schema-ownership.md) The MySQL-protocol control checked return values through the function, SHOW TABLE STATUS, and information_schema.tables for ordinary tables, views, lowercase and mixed-case auto-increment columns, and a visible column named __mo_fake_pk_col. Both the merge base and the reviewed head returned 0 for the mixed-case columns after two inserts. The fixed revision returns 3 across all three entry points. | User columns | SQL median on merge base | SQL median on reviewed head | SQL median after fix | Built-in allocations on reviewed head → after fix | | ---: | ---: | ---: | ---: | ---: | | 6 | 5.65 ms | 17.37 ms | 5.62 ms | 6,616 → 864 B/op | | 256 | 20.45 ms | 256.22 ms | 10.30 ms | 170,344 → 864 B/op | The SQL runs each read 8,192 rows naming one ordinary table. Medians use four warm queries per width, in separate embedded-cluster processes on the same Darwin/arm64 host. The allocation control invokes the actual built-in with a catalog-built relation and fixed relation resolution. These local measurements cover metadata reads. Focused race tests passed for allocator column selection, relation-name ownership, candidate defaults, ALTER-copy and rollback, and index access admission. The saved BVT's statements, output column names and row values matched via MySQL protocol. The two-CN allocator lifecycle and indexed and temporary-table status tests also passed. Incremental golangci-lint, molint, and all 40 changed Go license headers passed. The independent design and code review gates completed. [Metadata performance finding](#32948 (comment)) · [Tagged probe finding](#32948 (comment)) ## Remove intermediate schema projections Catalog DROP and the deletion phase of ALTER use the existing planner columns to form catalog keys. ALTER still materializes the private schema it needs to recreate the catalog and restore the previous version on statement rollback. A published catalog item now holds its schema directly. At that revision, owned planner copies worked from the planner definition. Engine copies merge the ordered residual fields directly into the output attributes. This removes the intermediate prototype, dense scratch arrays, and the unused projection from catalog deletion. Column-only replay uses read-only attributes for equivalence and retains the existing validation. Constraint validation still runs before publication, and consumers of engine definitions still receive private decoded constraints. On Go 1.27.1 Darwin/arm64, three interleaved runs compared the same published catalog items against `daac1a097507`. Fixtures had 6 or 256 user columns plus the physical row ID. The complex fixture also had primary-key and index constraints, a default expression, and a stored generated expression. | Fixture | User columns | Projection | Median ns/op before → after | B/op before → after | Allocations/op before → after | | --- | ---: | --- | ---: | ---: | ---: | | plain | 6 | planner | 1,101.0 → 628.4 | 6,536 → 4,360 | 18 → 12 | | plain | 6 | engine | 943.7 → 395.1 | 4,936 → 1,768 | 24 → 11 | | plain | 256 | planner | 26,113.0 → 15,019.0 | 196,896 → 133,600 | 20 → 14 | | plain | 256 | engine | 25,336.0 → 12,388.0 | 162,680 → 62,376 | 524 → 261 | | constraint and expression | 6 | planner | 2,037.0 → 1,489.0 | 7,488 → 5,312 | 30 → 24 | | constraint and expression | 6 | engine | 1,904.0 → 1,301.0 | 6,183 → 2,964 | 47 → 33 | | constraint and expression | 256 | planner | 26,410.0 → 16,402.0 | 197,848 → 134,552 | 32 → 26 | | constraint and expression | 256 | engine | 26,680.0 → 13,246.0 | 163,924 → 63,572 | 547 → 283 | Focused race tests covered column-only replay, old-reader and ALTER rollback, invalid constraint rejection, decoded-wire isolation, and planner and attribute fidelity. MySQL-protocol regression checks passed for DROP failure and rollback, ALTER, and allocator lifecycle. Two-CN catalog replay, reconnect, and durable restart also passed. Configured incremental golangci-lint, molint, and the license header check passed. These measurements cover component projections. The final revision has no new incident-scale or end-to-end cgroup peak measurement. Race validation also passed for the full cache package, for 100 repetitions each of concurrent read-only encoding and column-only replay with readers and GC, and for multi-CN replay, reconnect, and durable restart. [Catalog schema ownership, revision 3](https://github.com/matrixorigin/matrixone/blob/e85380a54e9efeae9a1fef87cc0c3d1cfed914e5/docs/design/20261120-catalog-schema-ownership.md) ### CI follow-up for the arena timer The PR was rebased onto official `main` at `96bfaa437bd9d535f22b6bd981ad00e277a4a91e`. It includes the upstream arena fixture and shared mmap timer fixes for the runtime fatal shown by `TestArenaPoolCountCap`. The six PR patches are unchanged according to `git range-diff`. [Failed Ubuntu UT](https://github.com/matrixorigin/matrixone/actions/runs/44715065474/job/136216667093) · [Upstream fix and incident](#32951) Local validation on `1214f5a125e4070bfb95beb987ffaa71c46b6260` used Go 1.27.1 on Darwin/arm64 with `mo-cgo-test -race -tags matrixone_test -short`. The objectio and malloc packages passed, along with focused planner, catalog replay, schema ownership, and ALTER rollback tests. All 41 changed Go license headers and the Loom artifact check passed. The original Linux fatal did not reproduce in the local baseline tests. The rebased Linux CI result is pending. ## Catalog metadata reads for extrema and sequences `MO_TABLE_COL_MIN/MAX` uses the published planner column positions for canonical DistTAE relations. `NEXTVAL` validates the relation kind from the published catalog metadata. Other relations retain their existing metadata validation. The unused private planner projection and its copy helpers were removed. The previous planner projection benchmarks describe the earlier revision. The embedded MySQL-protocol tests covered 256-column empty and persisted tables, case-insensitive extrema and a missing column, 8,192 consecutive sequence values, and rejection of a non-sequence relation. Multi-CN catalog replay, reconnect, and durable restart passed. The local Linux/amd64 Go 1.27.1 checks passed across the seven affected Go packages with `-race`, and incremental static analysis passed. | Metadata operation | Before | After | | --- | ---: | ---: | | 256-column extrema lookup | 59,648 B/op, 258 allocs/op | 0 B/op, 0 allocs/op | | Six-column sequence kind validation | 2,508 B/op, 21 allocs/op | 0 B/op, 0 allocs/op | The benchmark measures the metadata operations. [Catalog schema ownership at this revision](https://github.com/matrixorigin/matrixone/blob/3c399308ea9520ec9aba6b34b7637e33a33b12c5/docs/design/20261120-catalog-schema-ownership.md) Approved-by: XuPeng-SH <[email protected]> Approved-by: gouhongshen <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Related to #32963 and #32426. Backports the replay mechanism from #32611 to
4.2-dev.What this PR does / why we need it:
When a table straddles a batch boundary, CN catalog replay on
4.2-devcopies the entire column result into one batch while keeping the source batches. On a catalog with about nine million column rows, CN startup ran out of memory after entering this merge path.Order replay rows by numeric account, database and table identity. Insert complete groups from borrowed batch windows, copy only a table that straddles a boundary, and release each source batch once consumed. Close database and table SQL results at the end of their respective phases. Keep cleanup bounded after replay cancellation and drop delayed logtail closures after apply or reset so they stop retaining entries and cache generations.
The SQL executor still materializes the result and the cache still builds the existing engine and planner definitions. The carry can grow to the width of one table. This PR targets the extra merge and parser working set, plus stale callback references. The production catalog and container peak have not been replayed locally.
Validation on Linux/amd64:
pkg/catalogandpkg/vm/engine/disttaepassed under-race. Focused replay and delayed-queue tests passed on the final revision, including split tables, early cleanup, parser ownership, retry, cancellation and partial allocation failure.TestDropDatabaseReconnectRollbackpassed under-racein a real embedded cluster.