Skip to content

[Bug]: CopyGCDir misses GC watermark inheritance after metadata filtering #25935

Closed

Description

@Ariznawlll

Description

CopyGCDir uses the length of the original metaFiles slice when deciding whether the current entry is the last successfully copyable GC metadata file.

GC metadata whose referenced objects cannot be copied is intentionally omitted from copyFiles. Therefore copyFiles can be shorter than metaFiles. In that case the last entry in copyFiles does not satisfy i == len(metaFiles)-1, so its filename is not rewritten to inherit the checkpoint minimum timestamp.

Affected code

pkg/backup/tae.go:

for i, metaFile := range copyFiles {
    name := metaFile.GetName()
    if i == len(metaFiles)-1 {
        if !min.IsEmpty() && metaFile.GetEnd().LT(&min) {
            name = ioutil.InheritGCMetadataName(name, metaFile.GetEnd(), &min)
        }
    }
    // copy metadata file using name
}

The loop iterates over copyFiles, so the last-entry comparison must use the same filtered slice.

Tested version

  • Branch: main
  • Commit: 7f9ef5de9bb9337d8db0a9b15c44cba3b2838aa2
  • The same code was verified directly in the current main raw source.

Reproduction

A focused white-box test uses real GC metadata files and the production CopyGCDir path:

  1. Write GC meta gc_1-0_10-0.ckp referencing an object that does not exist, so this meta is skipped.
  2. Write GC meta gc_11-0_20-0.ckp referencing an object that exists, so this meta is copied successfully.
  3. Call CopyGCDir with checkpoint minimum timestamp 30-0.
  4. Verify that the last successful meta is written as gc_20-0_30-0.ckp.

Run:

go test ./pkg/backup -run '^TestAuditCopyGCDirInheritsLastSuccessfulMetaWatermark$' -count=3 -v

Actual behavior

All three runs fail. The destination contains only the original name:

[Backup] copy file ... failed
[]string{"gc_11-0_20-0.ckp"} does not contain "gc_20-0_30-0.ckp"

CopyGCDir returns no error, but the last successful GC metadata file keeps the stale end timestamp.

Expected behavior

After uncopyable metadata is filtered out, the last entry of copyFiles must inherit minTs when its end timestamp is lower than minTs.

Impact

The production comment explains that restore relies on the last GC metadata filename to raise the GC watermark when GC consumption lags behind the checkpoint. Under a partial/meta-object-missing backup, the stale filename can leave the restored GC state unable to find the required checkpoint.

Root cause

The loop iterates over the filtered copyFiles slice but compares its index against len(metaFiles)-1, which refers to the pre-filter slice.

Activity

  1. added this to the MO-202607 milestone on Jul 21, 2026
  2. added
    kind/bug
    on Jul 21, 2026
  3. Ariznawlll commented on Jul 21, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 白盒验证

    • 测试基线:main@7f9ef5de9bb9337d8db0a9b15c44cba3b2838aa2
    • 测试范围:pkg/backup.CopyGCDir 的 GC meta 部分失败过滤与恢复水位文件名继承,不涉及 txn/2PC。
    • 测试目的:确认前面的 GC meta 因对象缺失被跳过后,最后一个成功复制的 meta 是否仍会继承 checkpoint 的 minTs。

    测试过程/用例

    测试 TestAuditCopyGCDirInheritsLastSuccessfulMetaWatermark 使用真实生产格式和 MemoryFS:

    1. 通过 objectio.NewObjectWriterSpecial(WriterGC, ...) 写入第一份真实 GC meta:gc_1-0_10-0.ckp;
    2. 第一份 meta 引用一个不存在的对象,模拟 GC 已删除旧对象,因此 CopyGCDir 会记录复制失败并过滤该 meta;
    3. 写入第二份真实 GC meta:gc_11-0_20-0.ckp,并在源 FS 写入它引用的对象,使该 meta 可以完整复制;
    4. 调用真实 CopyGCDir(ctx, srcFS, dstFS, "gc", emptyBackupTS, minTS=30-0);
    5. 按生产代码注释的恢复要求,断言最后一个成功 meta 被改名为 gc_20-0_30-0.ckp。

    执行命令

    go test ./pkg/backup \
      -run '^TestAuditCopyGCDirInheritsLastSuccessfulMetaWatermark$' \
      -count=3 -v

    实际结果

    FAIL 3/3,稳定复现。 每次第一份 meta 都按预期因对象缺失被过滤,但第二份保留了旧文件名:

    WARN [Backup] copy file 01000000-..._00000 failed
    
    Error: []string{"gc_11-0_20-0.ckp"}
           does not contain "gc_20-0_30-0.ckp"
    Messages: the last successfully copied GC meta must inherit the checkpoint minimum timestamp
    

    根因对照

    过滤后:

    • metaFiles 长度为 2;
    • copyFiles 长度为 1;
    • 循环遍历的是 copyFiles,最后一个元素下标为 0;
    • 代码却判断 i == len(metaFiles)-1,即 0 == 1,条件不成立。

    因此 InheritGCMetadataName(lastMeta, end=20-0, min=30-0) 永远没有执行。

    结论

    确认是 backup/restore GC 元数据水位处理的确定性 bug;最新 main 3/3 稳定复现,不是文件服务或时序抖动。

  4. added theissue type on Jul 21, 2026
  5. added
    severity/s0
    and removed on Jul 21, 2026
  6. LeftHandCold commented on Jul 22, 2026

    @LeftHandCold
    Collaborator

    fixed

  7. Ariznawlll commented on Jul 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 分支完成复验,GC metadata 过滤后的 watermark 继承问题已修复。

    测试版本

    测试过程

    执行正式回归用例 TestCopyGCDirInheritsLastCopiedMetadataWatermark:

    1. 写入第一份真实 GC metadata,使其引用不存在的对象;
    2. CopyGCDir 尝试复制时,该 metadata 因引用对象缺失而被过滤;
    3. 写入第二份真实 GC metadata,并提供其引用的真实对象,使它能成功复制;
    4. checkpoint minTs 设置为高于第二份 metadata 的 end timestamp;
    5. 调用真实 CopyGCDir;
    6. 断言过滤后的 copyFiles 中最后一个成功 metadata 被重命名,并继承 checkpoint 最小水位。

    执行命令:

    go test ./pkg/backup \
      -run '^TestCopyGCDirInheritsLastCopiedMetadataWatermark$' \
      -count=20 -v
    
    go test -race ./pkg/backup \
      -run '^TestCopyGCDirInheritsLastCopiedMetadataWatermark$' \
      -count=5

    实际结果

    • 普通模式:20/20 通过;
    • Race 模式:5/5 通过;
    • 第一份 metadata 因对象缺失被过滤,测试日志中的 copy warning 属于预期夹具行为;
    • 第二份、也是最后一份成功复制的 metadata 正确继承 checkpoint minTs;
    • 目标目录中出现继承水位后的文件名,不再保留错误的旧 end timestamp;
    • Race detector 未报告数据竞争。

    测试结论

    CopyGCDir 已使用过滤后的 copyFiles 长度判断最后一个成功条目。即使前面的 GC metadata 无法复制,最终成功复制的 metadata 仍能正确抬升恢复所需的 GC watermark,原问题验证通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions