Skip to content

[Bug]: backup global file index selects an older timestamp lexicographically #25937

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I searched the existing open issues.

MatrixOne version

main@7f9ef5de9bb9337d8db0a9b15c44cba3b2838aa2

What happened?

backup.LoadGlobalFileIndex can select an older global file index when the physical timestamp components have different decimal widths.

For example, when both files exist:

  • file_index_0-9.idx
  • file_index_0-10.idx

the loader selects file_index_0-9.idx, although 0-10 is newer than 0-9.

The selected index is used by incremental backup to decide whether an object was already backed up. Loading a stale index causes objects recorded only in the newer index to be copied again, defeating cross-backup deduplication and increasing backup size and duration.

What did you expect to happen?

The loader should compare MatrixOne timestamps numerically and load file_index_0-10.idx.

How can we reproduce it?

  1. Create an in-memory file service.
  2. Write file_index_0-9.idx containing only old-only.obj.
  3. Write file_index_0-10.idx containing only new-only.obj.
  4. Call LoadGlobalFileIndex.
  5. Check which entry is loaded.

Actual result: the returned index contains old-only.obj and does not contain new-only.obj.

Root cause

pkg/backup/file_index.go extracts the timestamp as a string and chooses the maximum using lexicographic comparison:

if ts > latestTS {
    latestTS = ts
    latestIndexName = entry.Name
}

Lexicographically, "0-9" > "0-10", which is the opposite of the numeric timestamp order.

Additional information

A focused white-box regression test reproduces the issue deterministically 3/3 times. Detailed commands and results are provided in a follow-up comment.

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/file_index_order_audit_test.go
    • 被测函数:backup.LoadGlobalFileIndex

    执行的测试用例

    1. 使用 fileservice.NewMemoryFS 创建内存文件服务。
    2. 写入旧索引 file_index_0-9.idx,内容只包含 old-only.obj。
    3. 写入新索引 file_index_0-10.idx,内容只包含 new-only.obj。
    4. 调用真实的 LoadGlobalFileIndex,不 mock 索引选择逻辑。
    5. 断言返回索引包含 new-only.obj,且不包含 old-only.obj。

    执行命令

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

    测试结果

    FAIL,连续 3 次均稳定复现(3/3)。 每一次日志都显示:

    backup: loaded global file index file_index_0-9.idx with 1 entries
    Error: Should be true
    Messages: timestamp 0-10 is newer than 0-9
    

    实际加载了旧索引 file_index_0-9.idx,因此 new-only.obj 不在返回索引中。

    结论

    确认是 bug。文件名中的时间戳使用字符串比较,位数变化时顺序错误;该旧索引随后参与增量备份的 globalIndex.Has(objName) 去重判断,导致新索引已记录的对象被重复复制,增加备份空间和耗时。本次验证未观察到数据丢失,因此不扩大结论。

  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 分支完成复验,global file index 已按 MatrixOne timestamp 数值顺序选择。

    测试版本

    测试过程

    执行以下正式回归:

    • TestLoadGlobalFileIndex_OrdersTimestampNumerically
    • TestLoadGlobalFileIndex_IgnoresInvalidTimestampNames
    • TestLoadGlobalFileIndex_InvalidTimestampDoesNotMaskValidIndex

    覆盖内容:

    1. 同时写入 file_index_0-9.idx 和 file_index_0-10.idx,断言选择数值更新的 0-10;
    2. 覆盖 physical 部分位数变化,断言 10-0 新于 9-0;
    3. 对缺少分隔符、空时间戳、非数字、字段过多、负数及 logical 溢出等非法文件名进行过滤;
    4. 同时存在合法与非法文件名时,断言非法项不能遮蔽合法的最新索引。

    执行命令:

    go test ./pkg/backup \
      -run '^(TestLoadGlobalFileIndex_OrdersTimestampNumerically|TestLoadGlobalFileIndex_IgnoresInvalidTimestampNames|TestLoadGlobalFileIndex_InvalidTimestampDoesNotMaskValidIndex)$' \
      -count=20 -v
    
    go test -race ./pkg/backup \
      -run '^(TestLoadGlobalFileIndex_OrdersTimestampNumerically|TestLoadGlobalFileIndex_IgnoresInvalidTimestampNames|TestLoadGlobalFileIndex_InvalidTimestampDoesNotMaskValidIndex)$' \
      -count=5

    实际结果

    • 三组正式回归普通模式各运行 20 次,全部通过;
    • Race 模式各运行 5 次,全部通过;
    • 0-10 能正确覆盖 0-9;
    • 10-0 能正确覆盖 9-0;
    • 非法时间戳文件名被忽略,且不会影响合法最新索引选择;
    • Race detector 未报告数据竞争。

    测试结论

    LoadGlobalFileIndex 已解析并按 timestamp 的 physical/logical 数值字段排序,不再依赖字符串字典序。增量备份会加载真正最新的 global index,原问题验证通过。

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