Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Found by reading
origin/mainat 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_updateorphan 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:
writeMetaForRemainingswrites a GC metadata object that lists no stats.- Replaces
w.fileswith that empty list. - Builds a bloom from the empty list.
- Puts every
vecToGCname intofilesToGC, 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.
- 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
buildTableExistenceMapstill 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 ofvecToGC). - Let
canGCSinker.Syncsucceed so theDeleteObjectsdefer is registered. - Fail
cannotGCSinker.Sync. Cancelctxat the top ofSinker.Sync, or failtrySpillof the tail (tailSizeCap == 0). - Observe
RunreturnnewFiles == nilanderr == nil, because the defer assignserr = DeleteObjects(...)andDeleteObjectsreturns nil for an empty persisted list. - Observe
ExecutesetfilesNotGCto an empty slice and return nil. - Observe
ExecuteGlobalCheckpointBasedGCwrite empty metadata, setw.filesto that slice, and add table A's object name tofilesToGC(bloom miss). - Observe
doGCAgainstGlobalCheckpointLockedWAL-append that meta, callupdateGCWaterMark, andDeleteManythe 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 ontxn.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 ontxn.writes. GCWindow.ScanCheckpoints(window.go) alsodefer sinker.Close()withoutDeletePersisted. A failedWrite,Sync, orwriteMetaForRemainingsthere returns the error, so it does not commit an empty keep-set. It is not this bug.syncTableIDBatchinpkg/vm/engine/tae/logtail/ckp_writer.gois the cleanup pattern this job does not follow: it deletes persisted checkpoint objects unlesstransferredis set after a successfulSync.
Activity
Ariznawlll commentedon Nov 3, 2026
结论
补充本问题的实际执行证据:
GCExecutor.Run在中间文件读取失败后返回err == nil,3/3 复现。属于本 issue 的同根扩展,不是新增 bug,也不是修复验收。本轮没有据此认定完整 SQL 服务已发生数据误删。关键证据
1876b2f93e14c03ba538e3806e245e3c3203979a,2026-11-03,Go 1.27.1,临时独立 Go 程序直接调用生产gc.NewGCExecutor(...).Run(...),没有修改生产代码或仓库测试。查到的当前 mainc337122982537dcf957705cb6fc5f7f9bdc6a0f6的executor.go与实测文件 blob 均为69a70e59ca44ed58e695d7161035b7bf67b5bf2a;这只是文件一致性核对,不声称已运行当前 main 的完整构建。ObjectTableAttrs记录;粗过滤把三条送入 can-GC 分支。cacheSize=1使中间结果实际写出,再由 FileService 包装器在Read返回明确错误。正常对照执行同一真实写出/回读路径,不注入错误。读取失败的一条原始输出如下;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 执行器逻辑:另以返回错误的 fine-filter / final-sink 回调验证同一返回值覆盖机制,各 3/3;这两条仅作为组件错误传播测试,不假定生产 fine-filter 必然产生相同错误。
根因位置仍是 executor.go 的延迟清理:
err = DeleteObjects(...)覆盖了命名返回值。本次读取失败后的临时文件已清理,不能把这条结果描述为“本轮临时文件泄漏”。待解决点