Skip to content

[4.2-dev] fix(backup): preserve historical objects across repeated backups - #29504

Merged
XuPeng-SH merged 6 commits into
matrixorigin:4.2-devfrom
LeftHandCold:backport/4.2-backup-soft-deleted-28525
Oct 3, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:4.2-devfrom
LeftHandCold:backport/4.2-backup-soft-deleted-28525

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Sep 29, 2026 •

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 on 4.2-dev. Backports #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,
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:

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.

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#28473.

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

Backup selects checkpoint object files before rewriting the special
checkpoint to its `start` timestamp. A physical object may already be
absent because it was logically deleted before that restored snapshot
and then collected by normal GC. After matrixorigin#26290 correctly made missing
checkpoint objects fail, attempting to copy such a historical object
aborts the entire backup with error 20405.

A `DropTS` alone is not sufficient to omit an object. If `DropTS >=
special checkpoint start`, the checkpoint rewrite retains the object as
live at the restored timestamp, and the physical file must remain in the
copy set. This change selects from each `BackupObject` lifecycle
timestamp:

- omit only objects with `DropTS < restoreTS`;
- retain objects with `DropTS == restoreTS` or `DropTS > restoreTS`;
- retain the existing hard error for any required source file that is
missing;
- keep the prior conservative behavior when there is no special
checkpoint timestamp.

This does not modify GC, checkpoint selection, backup protection,
global-index de-duplication, checkpoint rewrite format, or restore
metadata.

## Design and validation

- Added `TestExecBackupKeepsObjectDeletedAfterRestoreTimestamp` using a
real special checkpoint with `create=5/start=15/drop=30`. It copies the
non-appendable object, runs checkpoint rewrite, and verifies both the
rewritten live metadata reference and the target physical object.
- Added
`TestSelectBackupObjectsOnlySkipsObjectsDeletedBeforeRestoreTimestamp`,
covering `DropTS <`, `==`, and `>` restore timestamp.
- Retained `TestParallelCopyDataReturnsMissingSourceObject` as the
negative control that a required missing source still returns 20405.
- Focused three-case regression, `pkg/backup` full package, and `go vet
./pkg/backup` passed at `c06bdd547b`.

A distributed BVT is not added because this changes the internal TN
checkpoint-object selection boundary. The owning package tests exercise
the checkpoint loader, copy set, rewrite, and missing-source behavior
deterministically.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 9475a9c)
@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 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 of dd0d27d1fefbeb312d1fc060a548f9daa51932ae against 4.2-dev@1a44f3db3056e32975fde86ca0ab69a094996a3f,独立完成,未使用 subagent。

结论:REQUEST_CHANGES — 1 个已复现的 P2 漏修,详见 inline comment。方向正确,但目前是“过滤部分历史记录”,还不是按对象生命周期闭合的 copy-set 选择。这里明确区分:它不是本 PR 新引入的 20405 回归,而是本 PR 要解决的历史对象问题仍在一个真实 producer 输入形态下发生。

设计、实现与历史意见

  • 逐 hunk 检查两个变更文件,并追踪 checkpoint producer → loader → copy-set → parallel copy → special-checkpoint rewrite → completion manifest;这是聚焦 backport,不需要另造状态机或设计文档。
  • 原 #28525 的 P1(不能跳过恢复点之后删除、会被 rewrite 重新保留的对象)已解决:只使用非空 DropTS < restoreTS,等于/晚于恢复点继续复制。没有重新引入“所有 soft-deleted 对象一概不复制”的错误。
  • 移除未使用的 softDeletes 收集、合并 loader 调用是合理清理;checkpoint/restore 格式、复制并发和错误传播未改变。必需源文件缺失仍失败,而不是吞掉 20405。
  • 当前 #29504 无其他 human review/inline comments 待闭环;原 P1 已闭环不等于新发现的生命周期重复记录问题已闭环。

独立 QA 与证据

macOS arm64 / Go 1.26.4,当前 head,重新构建本分支 thirdparties + CGo,-count=1:

  • 原新增 checkpoint-copy/rewrite 回归、时间戳边界回归、required-missing-source 负控:PASS。
  • 补测 live、empty restoreTS、相同 physical TS 下 logical before/equal/after、destination/global-index 去重:7/7 PASS。
  • 使用真实 catalog + IncrementalCheckpointDataFactory + Sync + loader + parallel copy 构造相同生命周期:
    • appendable 对照:旧对象未进入 copy-set,PASS;
    • non-appendable:创建记录仍进入 copy-set,源文件缺失时仍返回 20405,FAIL。
  • 复用作者当前 head 的 full-package/vet 证据,并刷新确认 CI Required、UT、SCA、PROXY/PESSIMISTIC BVT 为成功;这些不能覆盖上述新增反例。
  • 另一个探索性历史读检查在精确 base 和 head 上同样失败,已排除,不作为本 PR 引入的问题或阻断项。

工程质量与性能

生产改动集中,现有职责基本保留,没有新增锁、goroutine、持久状态或兼容分支;扫描仍为 O(N),节省的是被实际排除对象的复制 I/O,不是 checkpoint 加载,也没有吞吐 benchmark 支撑额外性能结论。新增 137 行测试分别验证边界与 rewrite 引用,职责不同,但缺少“同一对象多个生命周期记录”的正交维度;应补这个最小反例,而不是再堆重型 fixture。无新增文档需维护。修复建议是在现有 checkpoint 生命周期/引用归属中完成归并,再做物理文件去重;不要用全局 object-name soft-delete 黑名单替代,以免误伤仍存活的共享引用或恢复点边界。

Comment thread pkg/backup/tae.go Resolved
Resolve checkpoint creation and deletion rows by table, object type, object name, and creation timestamp before physical-file deduplication. Preserve shared live references and merge required copy flags. Add a real incremental-checkpoint regression and selector boundary controls.
@LeftHandCold LeftHandCold changed the title [4.2-dev] fix(backup): skip soft-deleted checkpoint objects (backport #28525) [4.2-dev] fix(backup): resolve historical object lifecycles before copying Sep 30, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Sep 30, 2026

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

对 09054065d6476e32f402bb3d28bf436733ba12b1 的完整 deep review;base/merge-base 为 4.2-dev@1a44f3db3056e32975fde86ca0ab69a094996a3f。独立完成。

结论:REQUEST_CHANGES:1 个 P1,备份成功但遗漏 snapshot/PITR 保留的历史对象文件。见 inline comment。本轮检查了全部 4 个文件的变更,覆盖 checkpoint producer/兼容 reader、生命周期归并、物理去重、copy、checkpoint/GC metadata、special rewrite、完成清单和历史 snapshot checkpoint 选择。

上次 P2 已解决:真实 incremental checkpoint 的 non-appendable 创建/删除重复记录现在正确归并,appendable 对照保留;旧 review thread 也已 resolved。原 #28525 的恢复点等于/晚于 DropTS 边界仍正确。当前出现的是另一个消费者契约:同一对象虽然不属于当前恢复点,仍可能被备份保留的历史 snapshot/PITR 引用。我的上次评审没有把这项保留契约验证到物理文件,本轮的判别测试补上了这个缺口。

设计与工程质量

  • 用 (TableID, ObjectType, ObjectNameShort, CreateTS) 区分拥有者和生命周期,再按物理文件去重是合理的;表 ID/对象类型由现有 checkpoint reader 提供,旧版 V12 转换路径也保留这些字段。字段仅在内存 descriptor 中传递,没有改变存储或协议格式。
  • 对 retained refs 合并 NeedCopy,并保留 destination/global-index 复用,避免 first-wins 的旧假设压掉必需复制,合理。
  • 问题在省略条件:DropTS < restoreTS 只证明对象在当前恢复点不可见,不能证明所有输出 checkpoint 的历史引用都不再需要它。GC 的保留规则、compacted checkpoint writer、snapshot reader 才是已有职责归属;修复应沿用这些信息,把“是否仍被任何保留引用需要”纳入同一选择规则。不要另建 snapshot/PITR 状态机,也不要通过忽略 20405 隐藏不完整备份。
  • 实现净增约 75 行(3 个生产文件)提供了归并和复制标志修正的明确收益;新增 364 行测试分别覆盖恢复边界、真实 producer 和小型 selector 控制,fixture 规模合理。测试的主要缺口是“已删除但被历史恢复点保留”的正交维度。无新增文档文件;PR 中“早于 restoreTS 即可省略”的表述也需要随契约修正。
  • 非阻断清理建议:LoadCheckpointEntriesFromKey 的 softDeletes 参数/收集分支在当前仓库调用点都传 nil,已无实际消费者,后续调整时可一并清理。

验证

macOS arm64 / Go 1.26.4 / -count=1。CGo、thirdparty 和模块依赖与上次已构建分支无变化,复用匹配的 native artifacts。

  1. 当前 head 的 5 个聚焦测试及其 selector subtests:PASS,2.011 秒。包含上次 P2 的真实 non-appendable/appendable producer 回归、原 copy/rewrite 回归、共享拥有者/epoch/type、logical TS、required-copy OR、destination/global-index、required-missing-file 负控。
  2. 新的判别测试:真实可读取单行 data object → incremental checkpoint → 实际 gc.MergeCheckpoint 生成保留该对象的 compacted checkpoint → execBackup → ListSnapshotCheckpoint → checkpoint 引用和对象读取。没有启动服务;retained bloom 输入按 ObjectIsSnapshotRefers 的既有规则确定。
    • 精确 base:PASS。备份含该对象,读取返回 42。
    • 当前 head:FAIL。备份成功且 snapshot selector 选中复制的 compacted checkpoint,但对象文件缺失,读取返回 20405。
    • 测试使用相同输入和断言,只有代码 revision 不同;测试本体约 0.22–0.23 秒。
  3. 复用作者针对受影响 backup/logtail/objectio 和 datasync/GC 消费者的包级、build/vet 证据;没有把包绿当作新反例的证明。刷新时当前 head 的 Ubuntu UT/coverage/shared build 已成功,SCA/部分 BVT 仍在运行;本结论依据已完成的本地判别证据。
  4. git diff --check 通过。

复杂度仍 O(N),新增临时 map 与不同 deleted lifecycle 数量相关;没有新后台状态、锁或执行路径。性能收益可落在正确排除的不再需要对象的复制 I/O 上,但没有 benchmark 支撑额外吞吐结论。保留引用遗漏属于正确性问题,不能用减少复制量作为收益来接受。

Comment thread pkg/backup/tae.go Resolved
@XuPeng-SH XuPeng-SH changed the title [4.2-dev] fix(backup): resolve historical object lifecycles before copying [4.2-dev] fix(backup): preserve historical objects across repeated backups Oct 3, 2026

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

Reviewed commit 16331feff0c00fe76aeae2cc046ad7f96d20f6da, against 4.2-dev / merge-base 0de7c54a043a93ef5ff3d5fdba30a5640dda8100.

APPROVE:本轮独立 deep review 未发现新的合并阻断问题,未使用 subagent。

三条既有 finding 均已实质解决:

  • #discussion_r4136239233:先按 table/type/name/createTS 消解生命周期,再做物理文件去重;真实 non-appendable 双行生产者及 appendable 对照通过,共享存活引用和 NeedCopy OR 保留。
  • #discussion_r4140513319:GC remaining 集合与 compacted checkpoint 引用共同保留历史对象;实际历史 checkpoint 选择及禁用缓存的数据读取通过。
  • #discussion_r4140902409:文件名仅表示恢复水位。完整增量扫描产生的 payload proof 与 remaining set 同一次发布,rename 不扩大证明,global/compacted 不填补扫描空洞;新旧元数据的连续两次备份均能读取历史数据。

设计上沿用 GCWindow 的扫描、持久化和重放职责,没有在备份侧复制 snapshot/PITR 策略。扫描读错、写错和取消不发布新证明;loader/collector 不再吞掉行读取错误,所有调用者已接线,废弃的 softDeletes 参数及分支已删除。

当前 head 的本地验证:macOS arm64 / Go 1.26.4,匹配分支的 native 依赖,重新构建 CGo,仓库测试入口 -p 2 -vet=all -count=1 -v -timeout 10m。backup、logtail、GC v3、datasync 全包分别通过(16.192s / 1.957s / 0.828s / 16.393s)。格式和 diff 检查通过。

额外独立 QA:真实 incremental producer → ScanCheckpoints → Merge → ExecuteGlobalCheckpointBasedGC → ReadTable → backup retention/selection,无手工 GCS1 payload,验证真实 GC 删除对象被省略、存活对象保留以及证明重放不变,通过。评审用例保存在本地审计材料,未改动 PR。

分别审视增量:实现 +355/-70(净 +285)、测试 +1198、文档 +71。测试覆盖生产者/消费闭环、生命周期边界、持久化失败和再次备份,使用小数据及共享 fixture;没有新集群、sleep 或大数据依赖。运行时新增两枚时间戳、一个固定大小 proof 记录,备份读取候选元数据并扫描一份选中的 remaining set;临时索引随输入线性增长,没有新 worker、全局缓存或执行路径。不声称吞吐收益。

保留已记录边界:legacy/gapped 元数据不能证明旧生命周期,历史源文件已缺失时仍可能保守失败;不会补回已发布备份里丢失的文件。未验证客户规模完整集群恢复或生产吞吐。当前提交的远端 UT/SCA/coverage/BVT 尚未全部完成,本次代码 APPROVE 不替代这些 CI 门禁。

@XuPeng-SH
XuPeng-SH merged commit 6d4569b into matrixorigin:4.2-dev Oct 3, 2026
LeftHandCold added a commit that referenced this pull request Oct 30, 2026
…#31886)

## 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:

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

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

---------

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

This branch was previously deployed

1 inactive deployment
ci — 16331fef Deployed Oct 3, 2026 by XuPeng-SH
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/enhancement size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants