Skip to content

[4.2.1-hotfix] fix(backup): preserve GC retention and restore history - #31886

Merged
LeftHandCold merged 2 commits into
matrixorigin:release/v4.2.1-hotfix-20261026from
LeftHandCold:backport/hotfix-20261026-backup-29504-30744
Oct 30, 2026
Merged

LeftHandCold merged 2 commits into
matrixorigin:release/v4.2.1-hotfix-20261026from
LeftHandCold:backport/hotfix-20261026-backup-29504-30744

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:

Related to #28473 and #30738 on release/v4.2.1-hotfix-20261026.

Backports #29504 and #30744. This PR does not claim to recover previously missing source objects or repair already incomplete backup archives.

What this PR does / why we need it:

Cherry-pick the two final, merged 4.2-dev fixes onto the hotfix base 3391c6844e95d1bb27a647b18f48f7c3a5ba1695, preserving them as separate commits:

Upstream PR Upstream commit Hotfix commit Purpose
#29504 6d4569bce66acb67e6d0fe746ee537da7955bffd 2bf7df8892748f7ff8fe160641b52a7acaa70d9e Safely omit reclaimed historical objects without dropping required snapshot/shared-owner data
#30744 b7d2cc7b5644641da580dd5650a02211167a781d 969680122fdebccfacdb21b7c84f40b5204878b3 Preserve real table-ID history across physical backup/restore so an immediate GCKP can validate its required history

Both cherry-picks are conflict-free and their stable patch IDs match upstream. No unrelated 4.2-dev commits, hotfix-specific production changes, retention-policy changes or weakened GCKP checks are included.

Backup object selection

  • Resolve object lifecycles before physical-file deduplication; retain other live owners, compacted references and restore-boundary objects.
  • Require an actual persisted GC scan interval before using absence from remaining objects to omit a deleted lifecycle. A GC filename is only a recovery watermark and can be advanced without scanning by CopyGCDir.
  • Keep the existing block-zero format and add an optional scan-proof block. Unknown legacy coverage stays conservative; incomplete reads and malformed proof fail rather than publishing a partial backup.

Restore history

  • Copy and checksum the exact predecessor's real table-ID index before bulk data copying. Reuse matching destination bytes; reject mismatches without overwriting.
  • Merge retained history through the rewritten backup checkpoint, persist the index location, and include its files, sizes and checksums in the archive manifest.
  • Preserve the distinct global/incremental successor-boundary conventions.
  • On pre-publication failure, clean only newly generated, unambiguously unpublished destination index files. Do not delete source data or potentially published history files.

Validation

Performed on the combined hotfix head, Darwin/arm64 CPU, Go 1.26.4, with freshly built branch-matched native artifacts and the repository CGo wrapper:

  • Focused combined backup/GC/history regressions: PASS.
  • Full normal suites with -vet=all: pkg/backup, pkg/vm/engine/tae/logtail, pkg/vm/engine/tae/db/gc/v3, pkg/vm/engine/tae/db/checkpoint, pkg/vm/engine/tae/db, pkg/objectio, and pkg/datasync: PASS.
  • Full race suites: backup, logtail, GC v3, checkpoint, and DB: PASS.
  • TestBackupRestoreGlobalCheckpointWithFreshWAL: normal/race PASS, plus 19 consecutive race repetitions PASS. This exercises a separate restored WAL, immediate GCKP, durable 24-hour history coverage, archived checksums, LSN 4 -> 0 -> 1, post-restore writes and complete row/value checks after another restart.
  • TestGlobalCheckpointTableIDHistoryFallbackAndFailClosed: normal/race PASS, plus 36 consecutive race repetitions PASS. Missing history still rejects GCKP, and repeated rejected attempts do not accumulate unreachable objects.
  • Historical snapshot retention, repeated backups with inherited GC watermarks, legacy metadata, scan gaps, owner/type/epoch boundaries, partial reads, cancellation, checksum mismatch and cleanup-failure cases: PASS in the owning suites.
  • Go-toolchain-matched gofmt and git diff --check: PASS.

These are real engine/file-service integration and component tests, not an external mo-backup image, production-scale performance or production restore acceptance. No production environment was changed.

Rollout boundaries

  • [4.2-dev] fix(backup): preserve historical objects across repeated backups #29504 includes both CN backup selection and TN scan-proof production. Updating only the external backup tool cannot substitute for updating the relevant MO components.
  • Legacy metadata without trustworthy scan proof may still cause conservative backup failure. Upgrading cannot retroactively certify old scans or guarantee that one new GC cycle covers every old object.
  • [4.2] fix(backup): preserve table-ID history across physical restore #30744 preserves history in newly generated archives; an existing archive that already lacks that history is not repaired retroactively.
  • Source GC deletion/retention policy is unchanged. Extra metadata reads and backup-time history work exist; zero overhead or universal production recovery is not claimed.

LeftHandCold and others added 2 commits October 30, 2026 17:18
…ckups (matrixorigin#29504)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#28473 on `4.2-dev`. Backports matrixorigin#28525 and corrects
historical-object
selection, retained references, and the incomplete GC census assumption
found
in this PR's reviews. This does not close the corresponding main-branch
work or
claim that previously missing files can be recovered.

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

Backup can see separate creation and deletion records for one physical
object.
Filtering only the deletion record still tries to copy an object already
reclaimed
by GC. Conversely, filtering every old deletion can omit snapshot/PITR
data and
publish a successful but incomplete backup.

The final correction resolves lifecycle identity before physical
deduplication,
retains compacted checkpoint references, and requires a committed GC
census before
using absence to omit an old object. Shared live owners, creation
epochs, object
types, restore timestamp boundaries, required-copy OR, and incremental
destination
reuse remain part of that selection contract.

A GC filename is only a recovery watermark: `CopyGCDir` can advance it
without
scanning the new interval. `GCWindow` now persists one bounded actual
scan interval
in an optional second metadata block, committed with its
remaining-object set.
Only complete incremental scans grant proof. Merge preserves real
contiguous
coverage and keeps a proven suffix across gaps; rename, replay and GC
filtering
cannot manufacture coverage. Backup reads candidate metadata and streams
one
selected remaining set. Existing block zero and restore-watermark
behavior remain
unchanged; old readers consume block zero, and legacy metadata provides
no absence
proof. Malformed proof and incomplete checkpoint/GC reads fail closed.

The obsolete `softDeletes` loader argument and collection path are
removed.
Checkpoint row-read errors now propagate through the loader and GC
collector,
preventing partial input from reaching successful publication.

Design: [trusted GC scan
evidence](https://github.com/LeftHandCold/matrixone/blob/578ff48a76f897dec56aecd97662b01b2efe1b30/docs/design/20261003-backup-gc-scan-proof.md),
produced with gpt-6.1-sol / xhigh. Final overall review: gpt-6-astra /
xhigh, PASS with no material blockers,
bound to commit `578ff48a76f897dec56aecd97662b01b2efe1b30`.

### Validation

macOS arm64, Go 1.26.4, branch-matched thirdparty artifacts and freshly
built CGo:

```sh
LC_ALL=C LANG=C GOMAXPROCS=4 .agents/skills/mo-dev/scripts/mo-cgo-test \
  -p 2 -vet=all -count=1 -v -timeout=10m \
  ./pkg/backup ./pkg/vm/engine/tae/logtail \
  ./pkg/vm/engine/tae/db/gc/v3 ./pkg/datasync
```

All four packages and vet passed (15.280 / 1.009 / 0.823 / 16.822
seconds).
Focused checks additionally cover:

- Two actual backups, inherited GC metadata, historical checkpoint
selection,
and cache-disabled physical read returning `42`, for legacy and new
metadata.
- Real incremental and compacted producers, retained and genuinely
reclaimed
objects, owner/type/epoch sharing, timestamp boundaries and required
missing files.
- Real GC scan publication; row-read, metadata-write and cancellation
failures;
empty/nonempty metadata, gap merging, filtered checkpoint types, logical
adjacency,
  invalid order and malformed proof.
- Old block-zero reader behavior and partial checkpoint reads failing
before
`tae_list`/`tae_sum` publication. Small fixtures are shared; no service
or large
  dataset is added.

Historical exact-base/head evidence established the repeated-backup
regression;
current local checks establish the corrected behavior. Updated-head CI
is pending.

### Cost and remaining limits

Each GC window adds two timestamps; a trusted metadata rewrite adds one
tiny block.
Backup inspects candidate metadata and retains the existing selected-set
and
lifecycle maps. There is no new worker, cache, scheduler or snapshot
policy, and no
measured throughput claim.

Legacy or gapped evidence remains conservative: an already missing old
object can
still cause backup failure when no trustworthy scan covers it. The
change does not
repair an incomplete backup already published. An old-version rewrite
may discard
the proof, making re-upgrade conservative; rolling back does not fix
that old
binary's unsafe selector. Customer-cluster full backup/restore and
current/historical
read acceptance have not been run.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>
(cherry picked from commit 6d4569b)
…atrixorigin#30744)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#30738

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

Backport the physical-backup table-ID history repair to `4.2-dev`.

The special backup checkpoint currently loses its predecessor's history
index, and copying the checkpoint directory does not copy the root-level
index objects. Consequently, a fresh physical restore can fail an
immediate GCKP's normal 24-hour history check despite a complete source
history.

- Copy and checksum the exact predecessor's real index before bulk data
copying; reuse identical destination bytes and reject mismatches without
overwriting.
- Merge through the rewritten special checkpoint, persist its index
locations, and include index bytes, sizes and checksums in the archive
manifest.
- Correct GCKP versus ICKP successor-boundary handling. Preserve partial
legacy empty-index behavior and repeated backup archives, without
claiming coverage across indexed gaps.
- Clean only newly generated, unambiguously unpublished index objects on
pre-publication failure.
- Assert ignored GCKP errors and add the separate-WAL
backup/restore/GCKP/write/restart regression, durable 24-hour history
and archive-file-list checks, plus failure/legacy cases.

The `4.2-dev`-specific object-retention/GC-history implementation and
its existing repeated-archive backup test are preserved, not replaced by
the main implementation. The new component tests use
`backup_table_id_history_test.go` to avoid replacing the branch's
existing `backup_history_test.go`.

No new disk-format column, shorter retention, fake coverage marker or
relaxed GCKP guard. The backup checkpoint response stays five fields.
Existing archives that already lack the required historical objects
cannot be retroactively repaired by this patch and may still need actual
history accumulation.

Tested with (CPU, Darwin/arm64, Go 1.26.4; repository CGo wrapper):

- Complete `pkg/backup` normal and race suites, including the unchanged
`TestExecBackupPreservesHistoryAcrossInheritedGCWindow` and its
second-archive backup.
- Complete checkpoint/logtail normal and race suites.
- Existing `TestGlobalCheckpointTableIDHistoryFallbackAndFailClosed`,
normal/race and 36 consecutive exact race repetitions.
- Separate-WAL restore regression verifies immediate GCKP, actual
archived index/checksum entries, real history coverage, LSN `4 -> 0 ->
1`, post-restore writes and a second restart's complete row/value
checks.
- `gofmt` and `git diff --check`.

These are engine/backup-library tests, not an external mo-backup-image
or production-cluster validation. No production configuration, objects
or cluster lifecycle was changed.

(cherry picked from commit b7d2cc7)
@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 →

@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels Oct 30, 2026
@mergify

mergify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 969680122fdebccfacdb21b7c84f40b5204878b3

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

@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.

独立 deep review:969680122fdebccfacdb21b7c84f40b5204878b3,base/merge-base 3391c6844e95d1bb27a647b18f48f7c3a5ba1695。未使用 subagent。结论:APPROVE,本轮未发现合并阻断问题。

设计与范围:完整审查 17 个文件及真实备份入口、GC scan→持久化→replay→对象选择、历史索引复制→checkpoint 发布→独立 WAL 恢复→GCKP→再次写入和重启。两次 cherry-pick 的 stable patch ID 与 #29504/#30744 上游一致。修复复用 GCWindow 和 TableIDLocation,没有新增 snapshot/PITR 状态机或放宽历史完整性校验;已删除无消费者的 softDeletes 参数及收集分支。

历史评论:#29504 三条阻断意见均已实质闭环:non-appendable 创建/删除重复记录、snapshot/PITR 保留对象、GC 文件名水位不能充当扫描证明。三个线程均 resolved;#30744 和当前 PR 没有行级待解决线程。旧元数据缺乏证明时继续保守保留,源文件确实缺失仍失败。

失败路径审计 结果
资源与发布 新增 window/reader/batch 有清理归属;新索引仅在明确未发布时删除,发布结果不确定时保留。
错误与取消 checkpoint/GC 读取、校验和、Stat/Read/Delete 错误向上传播;失败不发布完成清单,无新增锁、等待队列或重试层。
增长与性能 临时集合随备份输入增长并随调用释放;额外成本在备份及 GC 元数据路径,普通 SQL/TP 路径无新增逐行工作。

本轮本地验证:Darwin/arm64,Go 1.26.4,当前分支重新构建 native artifacts,仓库 CGo wrapper,非缓存执行:

  • backup、logtail、GC v3、checkpoint、db、objectio、datasync 全包 normal + -vet=all 通过;前五包全包 race 通过。
  • 独立 WAL 恢复→立即 GCKP→写入/删除→再重启回归额外 17 次 race 通过;GC 扫描证明发布/读错/写错/取消回归额外 100 次 race 通过。
  • 独立 review-only overlay:72 小时历史窗口 + ICKP 备份边界的完整恢复链路,以及真实 incremental scan→window merge→GC 过滤→证明落盘/重读→备份选择→禁用缓存读取存活数据,两项 race 均通过。
  • TestGlobalCheckpointTableIDHistoryFallbackAndFailClosed race 通过:真实历史缺口仍拒绝,失败重试不积累未引用对象。
  • 7 个变更所属包的增量 golangci-lint:0 issues;匹配 Go 版本的 gofmt、diff 检查通过。原始日志和临时挑战保留在本地 /tmp/pr31886-review-evidence,没有加入提交。

分别审视增量:实现 +552/-80、测试 +1648/-2、设计文档 +71。测试覆盖持久化与真实恢复、历史引用和小型故障注入,复杂度有明确正确性收益;没有通过大数据或 sleep 制造覆盖。

边界:不修复旧归档中已经缺失的文件/历史,不保证 legacy 扫描证据缺失时备份一定成功。未跑外部 mo-backup 镜像、客户规模恢复或大规模性能基准,不能据此承诺零开销。本次本地验证不替代远端发布门禁。

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 969680122fdebccfacdb21b7c84f40b5204878b3

Review belongs to an older commit; it is not a review of the current head.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Hotfix 复审结论:代码审查 PASS,未发现本次 backport 新增的阻断项。 审查绑定 HEAD 969680122fdebccfacdb21b7c84f40b5204878b3,base/merge-base 3391c6844e95d1bb27a647b18f48f7c3a5ba1695。当前登录账号是 PR 作者,不能自我提交正式 APPROVE,因此以评论记录结论;没有执行合并、发布或生产操作。

范围、设计与正确性

完整阅读 17 个变更文件,并追踪备份入口、checkpoint loader/重写、GC scan/merge/replay、历史索引生成、元数据发布与恢复端消费者。

审计 结果与边界
Q1 资源/发布 新增 reader/batch/window 有明确释放路径;新增索引在确定未发布时精确清理,发布结果不确定时不误删引用文件。
Q2 等待/失败 新增 I/O 使用现有 context/有限重试与清理超时机制;没有新增锁、后台任务或等待队列。本次新增校验失败向上传播,不伪装完成。
Q3 增长/性能 GC 证明为常量大小;备份临时集合随对象/生命周期数量增长并随调用释放,无常驻缓存。会增加 GC 清单读取、历史索引读写和 checksum 成本,不能宣称零开销;未向普通 SQL 逐行路径加入工作。

验证

复核并复用同一 clean HEAD、同一原生构建工作树的已有终态日志:7 个相关包 normal/vet 通过,5 个包 race 通过;独立 WAL restore 回归 19 次 race、历史缺口 fail-closed 回归 36 次 race 均通过。没有把 MongoDB CI 或待完成的机器人 review 当作 backup 验收。

本轮另在相同 HEAD 独立补跑下列 3 个顶层测试(含子场景),全部通过,包执行 1.882s:

LC_ALL=C LANG=C GOMAXPROCS=2 GOGC=50 GOMEMLIMIT=2GiB \
  .agents/skills/mo-dev/scripts/mo-cgo-test -p 1 -vet=all -count=1 \
  -json -timeout=120s \
  -run '^(TestCopyBackupTableIDHistory|TestExecBackupPreservesHistoryAcrossInheritedGCWindow|TestBackupRestoreGlobalCheckpointWithFreshWAL)$' \
  ./pkg/backup

环境:Darwin/arm64、Go 1.26.4、分支匹配的 native artifacts;完整日志 /private/tmp/pr31886-review-focused.jsonl。diff-check 通过,工作树未修改。验证覆盖重复备份、禁用缓存读取真实对象、精确前驱/legacy/缺口/checksum、独立 WAL 恢复后立即 GCKP、写入与再次重启;未执行外部 mo-backup 镜像、生产规模性能或客户集群恢复验收。

发布必须明确的边界

  1. 不能沿用“只升级 CN 即完整生效”的方案。 TN 要产生可信 GC scan proof,并修正 GCKP 备份边界。旧 TN 在以带索引 GCKP 为前驱时仍可能返回旧的 next-tick 边界,新 CN 会拒绝非精确前驱;建议 CN/TN 配套升级完成后再验收备份,混版本过渡期间不要把备份成功作为保证。
  2. 升级不会补回旧文件,也不会给旧 GC 元数据补造证明。 老对象生命周期不在可信区间内时仍可能保守地返回 20405;“新跑一次 GC”并不必然覆盖旧对象。不能据此承诺客户目前那一个 missing object 一定消失。
  3. 仅新生成归档受历史索引修复保护。 已经缺历史的旧归档不会自动修复。上线验收应包含完整备份、隔离恢复、当前/历史读取、立即 GCKP,以及恢复后写入和重启,而不只看备份命令成功。

Incidental bug findings(非本 PR 新增)

@LeftHandCold
LeftHandCold merged commit e0e2308 into matrixorigin:release/v4.2.1-hotfix-20261026 Oct 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants