feat(ctl): add GCCatalogCache command for on-demand CN catalog cache GC#24264
feat(ctl): add GCCatalogCache command for on-demand CN catalog cache GC#24264aptend wants to merge 2 commits intomatrixorigin:mainfrom
Conversation
Add mo_ctl('cn', 'GCCatalogCache', '<minutes>') to trigger immediate
garbage collection of the CN in-memory catalog cache. Default cleans
entries older than 20 minutes; minimum is 1 minute.
Fixes matrixorigin#24263
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
There was a problem hiding this comment.
Pull request overview
Adds a new mo_ctl command to trigger on-demand garbage collection of the CN in-memory catalog cache, complementing the existing periodic GC ticker in disttae.
Changes:
- Introduces an optional engine interface (
CatalogCacheGCer) for manual catalog cache GC. - Implements
GCCatalogCacheondisttae.Engineto GC by “entries older than X duration”. - Registers
GCCatalogCacheinmo_ctland adds a dedicated handler + unit tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/vm/engine/types.go | Adds CatalogCacheGCer optional interface for engines supporting on-demand catalog cache GC. |
| pkg/vm/engine/disttae/engine.go | Implements GCCatalogCache on disttae engine by computing a cutoff timestamp and calling catalog.GC(). |
| pkg/sql/plan/function/ctl/types.go | Registers the new GCCatalogCache ctl method name and handler. |
| pkg/sql/plan/function/ctl/cmd_gc_catalog.go | Implements the ctl handler: parses minutes parameter, clamps minimum, invokes engine GC. |
| pkg/sql/plan/function/ctl/cmd_gc_catalog_test.go | Adds unit tests for service restriction, default/custom minutes, clamp, invalid param, and unsupported engine. |
|
/auto-test-pr |
PR #24264 测试覆盖分析变更摘要本 PR 新增
6 类测试覆盖情况
图例: ✅ 已覆盖 建议BVT 补充建议新增 SQL 层 BVT case,覆盖以下场景:
示例 SQL: -- 默认 GC
select mo_ctl('cn', 'GCCatalogCache', '');
-- 自定义分钟
select mo_ctl('cn', 'GCCatalogCache', '5');
-- 错误参数
select mo_ctl('cn', 'GCCatalogCache', 'abc');
-- 非 CN 调用
select mo_ctl('tn', 'GCCatalogCache', '');大数据测试建议建议在大数据测试场景(如大规模 DDL 后)插入 GC 命令,验证 catalog cache 能及时释放内存。例如:
示例 SQL: -- 大数据场景下 bulk DDL 后
CREATE TABLE t1(id INT);
-- ...批量 DDL/数据加载...
select mo_ctl('cn', 'GCCatalogCache', '1');🤖 自动生成的测试 PR➖ BVT:已有重复或高度相似测试,跳过新增。生成文件 由 AI Test Analyzer 自动生成 · workflow run |
aunjgr
left a comment
There was a problem hiding this comment.
Review
Blocking
-
Data race on
CatalogCache.GC()—tidwall/btreeis not goroutine-safe. The background GC ticker runs from a single goroutine, but this new ctl command can be invoked from any user session concurrently. Two simultaneous calls (or manual + background ticker) will race on btree Scan/Delete. Either add a mutex inCatalogCache.GC(), serialize via channel to the existing GC goroutine, or add a lock inEngine.GCCatalogCache. -
Integer overflow on large parameter —
time.Duration(minutes) * time.Minuteoverflowsint64whenminutes > ~153,722,867. Overflow flips the duration negative, making the timestamptime.Now() - (negative)= future timestamp, which causesGC()to delete all catalog cache entries. Need an upper bound clamp (e.g.,if minutes > 525600 { minutes = 525600 }).
Advisory
- Default 20min is more aggressive than the background GC's 1-hour cutoff (
gcPartitionStateTimer). Worth documenting so operators understand implications. GCReportreturn value frome.catalog.Load().GC()is discarded — returning stats ("GC'd N table entries, M database entries") in the response would make this command useful for debugging.CatalogCacheGCerinterface method should returnerrorfor forward-compatibility (context cancellation, etc).- No test for concurrent invocation or negative input values.
|
@aunjgr Addressed the review in 3f56c5b. Blocking:
Advisory:
I kept the existing 20min default behavior unchanged and did not surface CGO_CFLAGS="-I/home/mo/matrixone/thirdparties/install/include" \
CGO_LDFLAGS="-L/home/mo/matrixone/thirdparties/install/lib -Wl,-rpath,/home/mo/matrixone/thirdparties/install/lib" \
go test ./pkg/sql/plan/function/ctl ./pkg/vm/engine/disttae/cache |
What type of PR is this?
Which issue(s) this PR fixes:
issue #24263
What this PR does / why we need it:
Adds
mo_ctl('cn', 'GCCatalogCache', '<minutes>')to trigger immediate GC of the CN catalog cache. Currently GC only runs on a 20-min ticker with no manual trigger. This helps during debugging, after bulk DDL, or memory pressure investigation.Default cleans entries older than 20 minutes; parameter sets custom minutes (minimum 1).
Changes:
pkg/vm/engine/types.go: newCatalogCacheGCerinterfacepkg/vm/engine/disttae/engine.go: implementGCCatalogCachepkg/sql/plan/function/ctl/types.go: register methodpkg/sql/plan/function/ctl/cmd_gc_catalog.go: handlerpkg/sql/plan/function/ctl/cmd_gc_catalog_test.go: unit tests