Skip to content

[Bug]: DATA BRANCH MERGE times out scanning unrelated catalog history after checkpoint recovery #32708

Done

Description

@gouhongshen

Note

SEND by Agent | Codex | GPT-6

Is there an existing issue for the same bug?

  • I checked existing issues for the FDB incident, historical mo_tables PK filtering and the related fix PR. Related catalog-recovery reports have different mechanisms; no matching issue was found.

Branch Name

Observed in production on v4.2.8-hotfix (MatrixOne 4.2.8). The fixes are also being ported to 4.2-dev and main.

Commit ID

Production: 10d204b8763f19b2b37ba2147d1d4c1a7828d6d4.

Port bases tested: 4.2-dev@1d90e5197c639ddc26afb447dc6ad7b28c36f56b and main@1064837ae2648aa20e5e1abb7edd0564493e6b4d.

Other Environment Information

The incident occurred in production MOI/FDB on 2026-11-13. Both the main business table and preview branch contained six rows; only one row differed. The ordinary CLI request deadline was 30 seconds. Production investigation was read-only; the failed business operation was not blindly replayed.

Actual Behavior

DATA BRANCH MERGE preview INTO customers WHEN CONFLICT SKIP reached the client deadline even though only one row needed updating. Production SQL failed with context canceled after 29.941863061 seconds.

The dominant phase was resolving the branch ancestor table's creation commit timestamp from historical mo_catalog.mo_tables changes:

  • DataBranch-TableCTS-CollectChanges-Done took 29.859157836 seconds, or 99.72% of SQL duration.
  • The caller logged has-pk-filter=true, but the checkpoint recovery constructor did not receive that context filter.
  • Range selection admitted 4,749 data objects and 7,116 tombstone objects. Their physical candidate-row total was 13,170,690; this is not the business table's logical size or proof that all candidate rows were read.
  • Before cancellation, the reader delivered 824,182 data versions and 1,036,957 tombstone versions, totaling 1,861,139 catalog-history rows.
  • MO logged a transaction rollback. The application's earlier committing flag remained stale; it is separate from MO's transaction state and application-state recovery is outside this engine fix.

Expected Behavior

Historical recovery must preserve the exact-table PK predicate already constructed by the frontend and avoid reading provably unrelated catalog payloads. It must retain conservative behavior for unknown zonemaps, non-PK sort keys and tombstones, and preserve metadata required to resolve replacement chains. Missing required metadata/files must remain errors.

Steps to Reproduce

The reproducible regression fixtures are included in the related PRs:

  1. Create a database with a target table plus unrelated catalog insertions and deletions. Persist their catalog objects and force a checkpoint.
  2. GC/truncate the CN mo_tables partition history so the requested interval starts before its in-memory coverage.
  3. Call CollectChanges with the target's account/database/table composite-PK predicate under checkpoint replay and visible-state range policies.
  4. On the original implementation, checkpoint replay drops the predicate and returns unrelated table history. The release branch's visible-state constructor also loses it. The source regression fails on the production/base implementation and passes after the fix while preserving the target's original creation commit timestamp.
  5. The SQL regression creates a six-row table and a preview branch with a single rename, forces historical catalog recovery, performs MERGE, and checks every resulting row. It also covers repeated merge, conflict SKIP, insertion and deletion.

Relevant tests:

  • TestCatalogChangesPKFilterAfterPartitionGC
  • TestDataBranchMergeWithCheckpointCatalog
  • TestHistoricalChangesPKBlockPruning and TestHistoricalChangesObjectPKPruning
  • TestHistoricalChangesPKFilterReplacementChain

The replacement-chain test reproduces the review counterexample using the public range constructor and real object files: an unknown/broad predecessor remains eligible while a disjoint replacement is prematurely removed from the lineage index. Its controls retain ErrFileNotFound for genuinely missing successors and matching files.

Additional information

Fix PRs:

Targeted tests and existing MERGE/PICK suites passed locally on each branch. A local matched workload on the original fix commit measured 8,192 unrelated tables with a six-row business table: MERGE median 136.75 → 33.84 ms and cumulative catalog lookup 110.05 → 5.09 ms. The long-common-prefix control showed no speedup because existing fixed-size zonemaps could not distinguish the keys. These measurements are not a production-latency guarantee; the detailed limits and the baseline post-measurement cleanup failure are retained in #32704.

Priority: pending repository triage.

Activity

  1. added
    kind/bug
    on Nov 13, 2026
  2. added a commit that references this issue on Nov 13, 2026
    b572b5c
  3. added a commit that references this issue on Nov 13, 2026
    1a3e7fb
  4. added 2 commits that reference this issue on Nov 20, 2026
    c33ce3f
    6faa4f2
  5. Ariznawlll commented on Nov 29, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过。本次补齐两条目标分支的目录历史规模与性能验证:保留 PK 条件后,能够跳过无关历史对象;实际 checkpoint/目录 GC 后仍能正确找到目标表创建版本,六行表 MERGE、重复合并和冲突处理均正确。回归分别加入现有 MOTR main #404、4.2-dev #399,没有向 MatrixOne 主库提交 PR。

    关键证据

    版本与环境

    • 2026-12-02 本轮开始时冻结官方分支:main f9d52a3a39edb57f33723ed8979084d0f60eda43,4.2-dev 6a905c7e660a71597ff1eb9fc61907145584377b。对应修复为 fix(branch): prune historical catalog replay and prefer snapshot reads #32707 与 [4.2-dev] fix(branch): preserve PK pruning in historical catalog reads #32705;没有用 main 的结果替代 4.2-dev。
    • 在 Linux 128 的独立目录运行,保留其他实例与数据;未访问 129。Go 集成测试使用上述精确源码,新增内容仅为 QA 测试文件,不改产品实现。真实服务构建注入完整版本;本项内部 checkpoint/GC 检验由同 SHA 的嵌入式集成测试执行。
    • 以下组件对照为同一版本、同一数据的过滤开/关对照,解释 PK 剪枝的工作量和耗时;不是两个发行版本的性能承诺。共享宿主机也不作为绝对独占性能基准。

    一、原生修复与错误边界

    两条分支分别执行以下五个原生测试,每项重复三次,全部通过,无跳过:

    TestCatalogChangesPKFilterAfterPartitionGC
    TestDataBranchMergeWithCheckpointCatalog
    TestHistoricalChangesPKBlockPruning
    TestHistoricalChangesObjectPKPruning
    TestHistoricalChangesPKFilterReplacementChain
    

    覆盖原调用链、checkpoint replay/visible state、块与对象剪枝、未知 zonemap 的保守保留、replacement lineage,以及确实缺失文件时仍报错。main 额外四个取消/缺文件/中止窗口资源测试各三次通过;4.2-dev 没有这四个同名测试,不把 main 结果计入 4.2-dev。合计 main 27 次、4.2-dev 15 次顶层测试执行。

    二、补齐原始物理候选规模

    单独构造落盘对象,使用实际对象读取器与公开历史范围构造入口:

    data_objects = 4,749
    tombstone_objects = 7,116
    data_versions = 5,271,930
    tombstone_versions = 7,898,760
    total_physical_candidate_versions = 13,170,690
    

    这与原 Issue 的对象数、总候选版本数一致;数据为合成目录键分布,不是客户生产目录副本。它也不是把六行业务表扩成 1,317 万行业务数据。关闭 MO 文件缓存,保留 OS 缓存状态;按“无过滤、有过滤、有过滤、无过滤、无过滤、有过滤”顺序执行。每轮完整消费结果:无过滤必须返回全部候选版本;有过滤必须只返回目标键 1 行、无无关 tombstone。所有计数和目标键断言通过。

    分支 无过滤三轮耗时 ms 有过滤三轮耗时 ms 结果
    main 7515.547 / 9435.825 / 9476.136 112.698 / 105.138 / 116.419 全部精确断言通过
    4.2-dev 5184.426 / 5869.875 / 5643.662 98.071 / 94.327 / 93.471 全部精确断言通过

    这里证明本场景中无关历史读取被有效剪枝;不将跨分支的绝对耗时差当作分支优劣,也不把本机数字外推为生产 SLA。过程最大 RSS 约 1.8 GiB,记录未见 swap;没有以缓存命中替代目标行正确性校验。

    三、真实系统目录的 8,192 表 checkpoint/GC

    额外创建 8,192 张无关表,分组提交并 flush 真实目录,强制 checkpoint,裁剪 CN 的 mo_tables 分区历史。先断言历史边界确实越过请求起点,再调用 CollectChanges,分别走 checkpoint replay 与 visible-state 策略。

    分支 无过滤:16,386 数据版本 + 1 删除版本 checkpoint replay:仅目标 2 个版本 visible state:仅目标 1 个版本
    main 113.588 ms 1.833 ms 0.529 ms
    4.2-dev 50.666 ms 1.720 ms 0.493 ms

    检查的是目标 table ID、创建/提交时间戳、完整目标版本与无关删除缺席,不仅检查行数。两条路径均通过。

    四、端到端六行 MERGE 与大目录组合

    在两条分支再次建立真实六行 customers/preview,修改一行名称,再创建 8,192 张无关表,强制 checkpoint 并裁剪历史;断言必须依靠历史恢复后,执行原始 SQL:

    DATA BRANCH MERGE preview INTO customers WHEN CONFLICT SKIP;
    • main 首次 MERGE:166.872 ms;4.2-dev 完整重跑:62.857 ms。该组用于验证真实 SQL 调用与结果,只有单次端到端计时,不冒充多轮性能基准。
    • 精确核对六行完整内容;重复 MERGE 不改变结果;另验证目标/分支冲突 SKIP、ALTER 后目录行替换、分支新增与删除,均通过。
    • main 整个集成测试正常结束。4.2-dev 第一轮上述业务断言已完成,但原小规模 helper 最后的 DROP DATABASE 一次删除 8,192 表,返回 20707: row level lock is too large that need upgrade to table level lock。保留该失败记录;改为每批 128 表清理本测试创建的表后,重新运行完整流程通过。未修改 MERGE 断言,也未将第一轮整体标成 PASS。批量 DROP DATABASE 锁上限不是本 Issue 的目录剪枝修复结论。

    五、MOTR 与托管 CI

    • MOTR main #404:main 原生门禁和独立 big-data 步骤。
    • MOTR 4.2-dev #399:4.2-dev 分支独立持有相同专项资产,不用 main 测试文件代替。
    • .github/qa/issue_32708_bigdata.sh 执行 1,317 万物理版本与真实 8,192 表 checkpoint 两项;原生 gate 每个根测试要求通过三次。端到端 8,192 表 MERGE 是本次额外本地验收,未将它表述为已每日执行。
    • main 定时入口与现有 4.2 薄调度分别选择对应分支;PR 合入前不称新增用例已经每日生效。
    • main CI 46812448780 与 4.2 CI 46812448747 均 success。分别下载并核对 1,446 / 1,451 字节的产物:完整 MO SHA 正确,每个原生根测试恰好三次通过;六轮物理版本计数及目标键断言正确,两个独立规模根测试和真实 catalog 两种恢复策略均通过。main CI 有过滤约 175–196 ms、无过滤约 7.13–7.56 s;4.2 CI 有过滤约 235–292 ms、无过滤约 5.45–6.02 s。
    • 对应 MOTR 被测提交为 main 389ea899c5fea18c9105405b175e5089c9fc7931、4.2 2600caf482baccc21ba7e99b3000a9f2177fbc9f。4.2 PR 后续 0cbe63a8d3cb0c193e234de161922eb058d4c198 只修改另一个 IVF 专项,已核对目录恢复代码没有变化。
    • 首轮新 CI 在 big-data 入口因 builder 缺少 python3 失败;补齐测试依赖后,上述两条线路从头完整重跑成功,没有把环境失败记作产品失败。
    • 此处 CI 结论仅指 [Bug]: DATA BRANCH MERGE times out scanning unrelated catalog history after checkpoint recovery #32708 专项 job,不等同于汇总 PR 中所有无关 job 均通过。

    待解决点

    本 Issue 在上述两个目标分支的修复验收项已完成。未获取原生产目录物理副本,因此不声称原生产现场逐字节重放,也不覆盖应用侧遗留 committing 标记修复。本次以原规模合成落盘历史、真实系统目录与端到端 SQL 三层证据验收引擎问题。

    最终结论:测试通过。main 与 4.2-dev 的 PK 过滤传递、历史恢复正确性、替换链/缺文件边界、原候选规模性能与真实大目录 MERGE 均通过,对应 MOTR 回归已提交并核验 CI。本次验收无剩余未通过项;回归 PR 尚待合入。

  6. XuPeng-SH commented on Nov 30, 2026

    @XuPeng-SH
    Contributor

    补充 #32992 合入版验证:在 main@51fe86e110738f097a102618773ee630c21d2fc8 上运行了真实 logtail replay 路径的 4 个定向用例,各 20 次通过:TestHistoricalChangesCancelPendingReadsOnMissingFile、TestHistoricalChangesAvoidUninterruptibleReadAhead、TestHistoricalChangesReturnMissingFileBeforeUninterruptibleReadAhead、TestHistoricalChangesReclaimAbortedWindows。另有 TestFileServiceReadCancellationCapability 通过。覆盖必要对象出错时取消并回收后续读取、保留缺对象错误及不可取消存储的边界。

    这不是原生产 DATA BRANCH MERGE 的重跑,未覆盖约 1,317 万候选的大目录及耗时对照,也不替代被取消的完整 CI。继续保留现有 QA 负责人,性能验收仍开放。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions