Skip to content

[Bug]: checkpoint GC clears a keep-set failure and can delete an object a live table still references #29258

Open

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

66da387

Other Environment Information

  • Found by reading origin/main at the commit above. Not reproduced with a live SQL session.
  • Hardware parameters: code inspection
  • OS type: n/a
  • Others: TN checkpoint GC (pkg/vm/engine/tae/db/gc/v3). This is not the CN insert / multi_update orphan in #29257.

Actual Behavior

GCExecutor.Run registers a deferred cleanup that assigns the named err result. After the coarse can-GC sinker has synced, every later failure is turned into a nil error, including a failed fine filter and a failed sync of the cannot-GC keep-set. The caller then commits an empty keep-set, advances the GC watermark, and deletes every name the fine filter already put in vecToGC.

Run (pkg/vm/engine/tae/db/gc/v3/executor.go):

canGCObjects, canGCMemTable := canGCSinker.GetResult()
defer func() {
    if err = DeleteObjects(ctx, exec.fs, canGCObjects); err != nil {
        //TODO: handle error
        err = nil
    }
}()
// ...
if err = exec.doFilter(ctx, fineSourcer, fineFilter, cannotGCSinker.Write, finalCanGCSinker); err != nil {
    return
}
if err = cannotGCSinker.Sync(ctx); err != nil {
    return
}
newFiles, _ = cannotGCSinker.GetResult()

err is the named result. The defer runs on the bare return and always stores DeleteObjects's result into err. DeleteObjects returns nil when canGCObjects is empty (pkg/vm/engine/tae/db/gc/v3/util.go). When DeleteObjects itself fails, the inner err = nil clears that error too. Either way the fine-filter error or the cannot-GC Sync error is gone, and newFiles is still nil because GetResult has not run.

CheckpointBasedGCJob.Execute treats that nil error as success and copies newFiles into filesNotGC (pkg/vm/engine/tae/db/gc/v3/exec_v1.go). The slice is empty.

GCWindow.ExecuteGlobalCheckpointBasedGC then:

  1. writeMetaForRemainings writes a GC metadata object that lists no stats.
  2. Replaces w.files with that empty list.
  3. Builds a bloom from the empty list.
  4. Puts every vecToGC name into filesToGC, because the bloom says the name is absent (pkg/vm/engine/tae/db/gc/v3/window.go).

checkpointCleaner.doGCAgainstGlobalCheckpointLocked appends that meta file to the WAL, records it, and calls updateGCWaterMark (pkg/vm/engine/tae/db/gc/v3/checkpoint.go). tryGCAgainstGCKPLocked then deleter.DeleteMany(filesToGC).

That bloom is the protection for one object referenced by more than one table. Checkpoint rows are stored as object name → table id (collectObjectsFromCheckpointData in window.go). The production fine filter (MakeSnapshotAndPitrFineFilter) decides each row on its own: a dropped table's row is added to the bitmap, a live table's row with an empty drop timestamp is not. doFilter sends bitmap rows to finalCanGCSinker (object name appended to vecToGC) and Shrink(sels, true) leaves the other rows for cannotGCSinker. After a successful cannot-GC Sync, those stats become filesNotGC and the bloom keeps the shared file. window_test.go documents the same rule: an object shared by a dropped table and a live table must not be deleted. With an empty filesNotGC, the live table's row never reaches the bloom, and DeleteMany removes the file the live table still names.

The cannot-GC sinker is created without WithTailSizeCap, so tailSizeCap stays 0. Sinker.Sync calls trySpill whenever staged memory is non-zero (pkg/objectio/ioutil/sinker.go, threshold DefaultInMemoryStagedSize = 16MiB). A context cancel, a spill error, or any other Sync error is enough to hit the wiped return. Sinker.Close then nils staged.persisted and does not call DeletePersisted, so the unpublished keep-set objects are also dropped. Those orphans are secondary. The primary bug is the successful GC of the shared data object.

A fine-filter error in a later batch has the same shape once an earlier batch has already appended a dropped reference to vecToGC and written the live reference into the cannot-GC sinker. doFilter sorts each batch by the drop-timestamp column before the filter, so the two references do not have to sit in one batch.

Objects that are only in the keep-set are not in vecToGC, so this round does not delete them. They are still removed from the window: w.files becomes empty and the watermark moves to the global checkpoint end. The next scan will not see them.

On the success path the same defer forces err = nil when deleting the temporary can-GC objects fails. That is the existing TODO and leaks only those intermediates. It is not the data-loss path above.

Expected Behavior

A fine-filter error or a cannot-GC Sync error must stay on Run's result. ExecuteGlobalCheckpointBasedGC must not write an empty keep-set, must not replace w.files, and must not advance updateGCWaterMark. DeleteMany must not run for that attempt. Deleting the temporary can-GC objects must not overwrite the job error. A file may be deleted only when every reference is in vecToGC and the keep-set bloom does not contain its name.

Steps to Reproduce

Code path on main @ 66da3877e9. No live cluster run.

  1. Build a GC window that contains one object name twice: table A with a non-empty drop timestamp, table B with an empty drop timestamp and a table id that buildTableExistenceMap still contains. The object name must miss the global-checkpoint bloom so the coarse filter sends both rows to the can-GC sinker (a bloom hit keeps both rows out of vecToGC).
  2. Let canGCSinker.Sync succeed so the DeleteObjects defer is registered.
  3. Fail cannotGCSinker.Sync. Cancel ctx at the top of Sinker.Sync, or fail trySpill of the tail (tailSizeCap == 0).
  4. Observe Run return newFiles == nil and err == nil, because the defer assigns err = DeleteObjects(...) and DeleteObjects returns nil for an empty persisted list.
  5. Observe Execute set filesNotGC to an empty slice and return nil.
  6. Observe ExecuteGlobalCheckpointBasedGC write empty metadata, set w.files to that slice, and add table A's object name to filesToGC (bloom miss).
  7. Observe doGCAgainstGlobalCheckpointLocked WAL-append that meta, call updateGCWaterMark, and DeleteMany the shared object. Table B's catalog entry still names the deleted file.

Additional information

Searched open and closed issues for GCExecutor, filesNotGC, cannotGC, ExecuteGlobalCheckpointBasedGC, updateGCWaterMark, and DeleteObjects. No matching issue.

  • Not #29257. That issue is CN insert / multi_update / deletion / disttae writers that upload objects and never register them on txn.writes. This path is TN checkpoint GC, and the bad outcome is a deleted data object plus an advanced watermark, not an unregistered CN upload.
  • Not #25204. That issue is workspace-size accounting and an async delete failure for objects already on txn.writes.
  • GCWindow.ScanCheckpoints (window.go) also defer sinker.Close() without DeletePersisted. A failed Write, Sync, or writeMetaForRemainings there returns the error, so it does not commit an empty keep-set. It is not this bug.
  • syncTableIDBatch in pkg/vm/engine/tae/logtail/ckp_writer.go is the cleanup pattern this job does not follow: it deletes persisted checkpoint objects unless transferred is set after a successful Sync.

Activity

  1. added
    kind/bug
    on Sep 22, 2026
  2. added this to the MO-202609 milestone on Sep 23, 2026
  3. added theissue type on Sep 23, 2026
  4. added
    severity/s0
    and removed on Sep 23, 2026
  5. Ariznawlll commented on Nov 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    补充本问题的实际执行证据:GCExecutor.Run 在中间文件读取失败后返回 err == nil,3/3 复现。属于本 issue 的同根扩展,不是新增 bug,也不是修复验收。本轮没有据此认定完整 SQL 服务已发生数据误删。

    关键证据

    • 实测官方提交 1876b2f93e14c03ba538e3806e245e3c3203979a,2026-11-03,Go 1.27.1,临时独立 Go 程序直接调用生产 gc.NewGCExecutor(...).Run(...),没有修改生产代码或仓库测试。查到的当前 main c337122982537dcf957705cb6fc5f7f9bdc6a0f6 的 executor.go 与实测文件 blob 均为 69a70e59ca44ed58e695d7161035b7bf67b5bf2a;这只是文件一致性核对,不声称已运行当前 main 的完整构建。
    • 每次独立创建 MemoryFS、mpool、buffer 和 executor。输入 3 条合法 ObjectTableAttrs 记录;粗过滤把三条送入 can-GC 分支。cacheSize=1 使中间结果实际写出,再由 FileService 包装器在 Read 返回明确错误。正常对照执行同一真实写出/回读路径,不注入错误。
    • 三次独立实例的结果完全一致:
    路径 实际 FS.Read 次数 进入最终 sink 的行数 返回结果
    正常内存路径 0 3 nil,符合预期
    粗过滤前 source 报错 0 0 原错误保留,符合预期
    正常中间文件写出/回读 2 3 nil,符合预期
    中间文件读取报错 1 0 nil,原读取错误丢失

    读取失败的一条原始输出如下;generation 1、2 相同:

    {"actual_error":"<nil>","error_preserved":false,"expected_error":true,"fine_calls":0,"generation":0,"mode":"spill_read_error","read_calls":1,"remaining_files":0,"returned_files":0,"sink_calls":0,"sink_rows":0,"source_calls":2}

    失败点是以下包装器,底层使用实际 fileservice.NewMemoryFS;它没有替换 GC 执行器逻辑:

    func (f *failReadFS) Read(ctx context.Context, v *fileservice.IOVector) error {
        f.reads++
        if f.fail { return injected }
        return f.FileService.Read(ctx, v)
    }

    另以返回错误的 fine-filter / final-sink 回调验证同一返回值覆盖机制,各 3/3;这两条仅作为组件错误传播测试,不假定生产 fine-filter 必然产生相同错误。

    根因位置仍是 executor.go 的延迟清理:err = DeleteObjects(...) 覆盖了命名返回值。本次读取失败后的临时文件已清理,不能把这条结果描述为“本轮临时文件泄漏”。

    待解决点

    • 保留原始读取/过滤/写入错误;清理失败不能覆盖主错误。
    • 本轮范围是生产 GC 执行器组件的可执行故障对照,不是完整 SQL 服务中共享对象误删、水位提交或重启恢复的端到端证明。需要后续针对这些影响分别验收,不能由组件复现直接外推。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

4.3-devkind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions