Skip to content

fix(catalog): prevent property amplification across ALTER rewrites - #32465

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/catalog-property-amplification-20261110
Nov 10, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/catalog-property-amplification-20261110

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #32463.

Related to #31888; this PR does not close the original distributed OOM incident.

What this PR does / why we need it:

Repeated in-place ALTER reads persisted StreamConfigsDef properties, appends
catalog kind/CreateSQL/comment again, and writes all of them back. Even an empty
table with an unchanged logical definition accumulates duplicate properties on
every rewrite.

This change restores the catalog-column ownership boundary at both existing
planner projection sites (cache.getTableDef and txnTable.GetTableDef). One
small catalog helper excludes only relkind, rel_createsql and rel_comment
from the persisted configuration import. Each reader continues to project its
current authoritative catalog values, including authoritative empty values.

Other properties retain their values, order and duplicate semantics. The helper
does not modify the input configuration, cached property objects, original
serialized constraint, or PK/FK/index definitions. Normal subsequent ALTER
compacts historical duplicate properties; no bulk rewrite or on-disk format
change is introduced. Deploy using the existing shutdown-upgrade procedure.

Tests cover both readers, fixed-size feedback through the actual planner and
engine conversion functions, legacy duplicate constraints, custom properties,
empty/current metadata and unaffected constraints. A small SQL BVT checks
repeated ALTER, bounded serialized metadata, SHOW CREATE/data, primary and
unique keys, and foreign-key enforcement.

Validation on host50

  • Base: Main 0c8bd5e5f3be4ce5582201513161181ddca37d6d; Linux/amd64,
    Go 1.27.1. Own matching native artifacts were built using make cgo.
  • Red before green: the final regression tests fail at runtime with the
    original reader source overlaid from that exact base; the fixed tests pass.
    Cases include fresh metadata, historical repeated configuration groups,
    authoritative empty values, custom duplicate keys and constraint preservation.
  • All owning packages passed with the repository CGo wrapper:
    ./pkg/catalog, ./pkg/vm/engine/disttae/cache, ./pkg/vm/engine/disttae
    (-p=2 -count=1 -timeout=360s).
  • go vet and repository-pinned golangci-lint 2.14.0 passed for the changed
    three-package closure, including newly added files; gofmt/diff checks clean.
    This is incremental local static validation, not a full CI claim.
  • Built the actual Main mo-service with the patch. Isolated local LOG/TN/CN,
    fresh data, internal-only network, 4 GiB / two CPU; no shared service touched.
    Binary SHA256:
    8f6bc3205e7f8cc9c049d2add48881d20ec2976d49d84a0fb3a46d82d64df380.
    It was built before commit, so VCS metadata is the base plus modified=true;
    saved source-file hashes bind it to the delivered production contents.
  • Reviewed the generated expected output independently, then ran the new BVT
    in normal comparison mode twice on the same instance: both 21/21,
    zero failed/ignored/abnormal, 0.220s and 0.222s. Database/table teardown counts
    are zero after each run.
  • Additional bounded public SQL: 100 identical MODIFY col2 VARCHAR(25) NOT NULL
    operations. Constraint bytes are 298 / 298 / 298 at rounds 1 / 10 / 100;
    row count remains zero and SHOW CREATE is correct. The initial INT definition
    is 157 bytes; the first conversion legitimately changes the definition size.
  • Restarted with a separate one-row persisted fixture: SHOW CREATE and row
    (1, '12') match before/after restart; another ALTER preserves the encoded
    size. Final test database/table counts are zero. The owned container and
    network were removed; service exit code 0, OOMKilled=false.

Local evidence (commands, raw logs, source/binary hashes and cleanup receipts):
/tmp/mo-catalog-property-fix-20261110.48eDEMbs/evidence.md on host50.

Scope limits

No changes to Catalog GC retention, GOMEMLIMIT, memory cache, resource admission,
background work or regression workflow. Existing raw metadata/history follows
normal replacement/GC; this is not an immediate global cache purge. The focused
local proof establishes property idempotence and SQL compatibility, not the
complete 55 GiB distributed OOM outcome or every Main/4.2 RSS difference.

Filter catalog-owned properties at both plan projection boundaries. Preserve custom properties and constraints, and add deterministic round-trip and SQL regression coverage for matrixorigin#32463.
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: de790f3df11203be6839af67964ce7169dcaad10

Review discussion changed before publication; a fresh contextual review is queued.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review 结论:PASS,建议 Approve。未发现需要阻断的正确性、性能或兼容性问题。当前登录账号与 PR 作者相同,GitHub 不允许 self-approval,因此用 COMMENT 留下结论,不冒充正式 APPROVED。

范围:0c8bd5e5f3be4ce5582201513161181ddca37d6d → de790f3df11203be6839af67964ce7169dcaad10,merge-base 为该 base;全部 8 个变更文件已读。这是聚焦的 bug fix,不需要增加设计框架或新状态机。按 mo-dev / mo-self-review / unhappy-path-audit 核对了以下闭环:

  • 设计和职责正确。两个现有 StreamConfigs→planner 属性导入入口统一使用 catalog helper;只排除由独立 catalog 列负责的 relkind / rel_comment / rel_createsql。保留既有写入和序列化职责,没有另建校验、存储或执行路径,也没有为了过滤属性把 catalog 依赖反向引入 engine。
  • 不改变其他属性语义。当前 catalog 值优先,包括空 comment/CreateSQL;未知配置的值、顺序和重复键保持。源码核对了 CREATE/外部表配置→PropertiesDef→catalog 列、缓存/事务读取、DeepCopy、PlanDefToCstrDef/PlanDefsToExeDefs 和 ALTER 重建。PK/FK/index/ref-child 独立约束及原始 constraint 字节不在读取时修改。
  • 新旧逻辑衔接合理。不改磁盘格式,旧重复配置可以读取;通过 planner 重建的后续 ALTER 不再继续携带历史重复的保留键。失败恢复继续使用原始定义/constraint,没有新增事务副作用或清理责任。
  • 成本可控。增加的是元数据导入时按 key 的线性过滤,不复制自定义属性对象、没有新增 RPC/锁/后台任务或逐行执行开销。固定逻辑定义下,保留键数量收敛为最多 3 项;不是通过降低 GC 保留时间或内存保护来掩盖问题。
审计 结论
Q1 所有权/清理 使用新结果 slice 和既有 plan/constraint 生命周期;不原地改共享 Configs、属性对象或原始序列化数据
Q2 等待 helper 只有同步遍历/append,没有新增等待、重试或异步依赖
Q3 增长 read→DeepCopy→真实 encoder→read 的保留键反馈被截断;自定义配置保持原语义

验证证据已实际核对并复用,未再次启动大型 UT 或数据库:

  • 只读检查 host50 的 /tmp/mo-catalog-property-fix-20261110.48eDEMbs/:保存的 8 个变更文件 SHA256 与 PR 全部一致;读取了旧代码失败、修复后三个定向测试及三个 owning package 通过的原始日志。旧代码失败点确实是属性数量/值重复,不是编译或环境失败。
  • 两次正常比较 BVT 均 21/21,零 failed/ignored/abnormal,明确选中本次 SQL;核对了两次数据库/表清理均为零,以及重启前后 SHOW CREATE/行数据一致。100 次 MODIFY 后的 metadata 大小稳定是该修复的有效验证,不拿它替代 OOM 压测。
  • 同 head 的 CI 已终态成功:UT、SCA、Coverage、Compose/多 CN BVT 和 CI Required 均通过;本地 diff check 也通过。

范围边界不是新增 blocker:已经膨胀的持久化 constraint/历史版本不会因一次读取就被全局清除;需要后续正常重建/原有 GC 消化。旧 CN 若继续执行旧逻辑,仍可能再写入重复属性,应遵守 PR 说明的既有停机升级方式。此 PR 可以闭合 #32463 的属性膨胀机制,不能据此宣布 #31888 的完整分布式 OOM 已解决。当前没有已有代码 review thread 需要确认关闭。

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: de790f3df11203be6839af67964ce7169dcaad10

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: de790f3df11203be6839af67964ce7169dcaad10

Assessment: approve

The shared catalog filter stops reserved-property feedback at both readers while preserving authoritative metadata, custom properties and independent constraints. It reuses existing persistence paths without adding state. No actionable findings.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed all eight changed files, both linked issues and all four discussion entries; traced projection through ALTER persistence.

  • Reused supplied exact-head CI successes and the same-head review’s source-matched package, repeated BVT and restart evidence.

  • Local preflight, gofmt, diff --check and evidence/discussion audit passed. Receipts and logs are retained.

Limitations:

  • No local Go or SQL/BVT rerun; native prerequisites and remote raw host50 artifacts were unavailable locally.

  • This establishes the property-amplification fix, not resolution of #31888’s distributed OOM or immediate reclamation of historical metadata.

@mergify mergify Bot added the queued label Nov 10, 2026
@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

2 h 9 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 10 Nov, 09:05 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 11:14 · 118beaf

Reason

Pull request #32465 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the dequeued label Nov 10, 2026
LeftHandCold added a commit that referenced this pull request Nov 11, 2026
…ewrites (#32496)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

4.2-dev backport for #32463. Main fix: #32465.

Related to #31888; this change does not close the entire distributed OOM
incident.

## What this PR does / why we need it:

Cherry-picks merged Main commit
`5318305e0269c254b8ea22be7ddc2c430f3e73f8`
onto 4.2-dev `a7bc2008e9236708fee0328376f2c2c6b6f0d3fc`. Production code
and
test SQL/assertions are unchanged. The only branch adaptation is adding
the
existing 4.2 `internal error:` prefix to two foreign-key error messages
in the
expected result. It does not import unrelated Main changes.

Repeated ALTER re-imported persisted catalog properties and appended the
current
catalog values again. The two existing table-definition readers now
exclude
historical `relkind`, `rel_createsql` and `rel_comment` copies before
projecting
the authoritative catalog columns. Rewriting an unchanged definition no
longer
accumulates these properties.

Custom properties retain their values, order and duplicate semantics. No
input
constraint bytes or shared property objects are modified. PK/FK/index
definitions
and the existing binary format remain unchanged. Historical duplicate
properties
are compacted by subsequent normal schema rewrites, not by a background
migration
or global cache purge. No GC, memory-budget, workflow or topology
changes.

### Branch-specific validation on host50

- Linux/amd64, Go 1.26.4, matching native artifacts built from this 4.2
tree.
- Original 4.2 reader source with the new regression tests fails on
duplicate/
  stale properties; the unchanged tests pass with the backport.
- All three owning packages pass: `./pkg/catalog`,
  `./pkg/vm/engine/disttae/cache`, `./pkg/vm/engine/disttae`.
- Package build, `go vet`, repository-pinned golangci-lint 2.6.2 and
format/diff
  checks pass.
- Built the actual 4.2 `mo-service`; ran it with fresh data in an
isolated local
  LOG/TN/CN fixture (4 GiB, two CPU, internal-only network).
- Initial SQL comparison exposed only the two branch-specific FK message
prefixes described above. After adapting those expected strings, the
final
BVT passed twice: **21/21** each, zero failed/ignored/abnormal,
0.148s/0.129s.
This checks metadata size, SHOW CREATE, data and PK/unique/FK
enforcement.
- 100 identical public ALTER operations: constraint size **271 bytes at
both
rounds 10 and 100**, with zero data rows. The initial INT definition and
first
conversion legitimately have different sizes; the invariant is no
continued
  growth after metadata warmup.
- One-row persisted fixture: schema and row `(1, '12')` match
before/after
restart; another ALTER retains the encoded size. All owned
databases/tables
  are absent afterward. The isolated container/network were removed;
  service exit code 0, OOMKilled=false.
- Binary SHA256:
  `2f40ae6a4031234938f90b63afb45210d8b25047cd9e897fa95861fa6db15d13`.
Built from cherry-pick `b36095852f`; final commit `5bddc6e6fc` changes
only
the two expected error strings. Production/test source hashes are
unchanged,
  and the final golden was exercised by both successful SQL runs.

Local source hashes, commands, raw logs and review:
`/tmp/mo-catalog-property-42-backport.YIYmmLMB` on host50.

The local checks establish the metadata invariant and branch
compatibility;
they do not substitute for the original full distributed OOM acceptance.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
ci — 118beafa Deployed Nov 10, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: repeated in-place ALTER persists duplicate catalog properties and amplifies metadata on Main and 4.2

3 participants