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 compact (
pkg/vm/engine/tae/db/gc/v3/merge.go). This is not#29257(CN insert /multi_updateobjects that never reachtxn.writes) and not#29258(GC keep-set failure rewritten to success, then a live shared object can be deleted). Here the merge stays failed: old checkpoints are kept and the GC watermark is not advanced. The new compact objects have no remaining owner.
Actual Behavior
MergeCheckpoint uploads the compacted checkpoint data, then CheckpointData_V2.Sync marks that upload as transferred so its cleanup defer will not delete it. A later failure while writing the compact metadata returns that error and drops the object names. mergeCheckpointFilesLocked returns immediately and never deletes those names. Sinker.Close also does not delete them.
MergeCheckpoint (pkg/vm/engine/tae/db/gc/v3/merge.go):
sinker := ckputil.NewDataSinker(pool, fs)
defer sinker.Close()
if err = sinker.Write(ctx, ckpData); err != nil {
return
}
ckpWriter := logtail.NewCheckpointDataWithSinker(sinker, pool)
if location, files, err = ckpWriter.Sync(ctx, fs); err != nil {
return
}
newFiles = append(newFiles, files...)
// metadata batch is built here, then:
writer, err := objectio.NewObjectWriterSpecial(objectio.WriterCheckpoint, name, fs)
if err != nil {
return
}
if _, err = writer.Write(containers.ToCNBatch(bat)); err != nil {
return
}
_, err = writer.WriteEnd(ctx)
if err != nil {
return
}
client.AddCheckpointMetaFile(tsFile.GetName())CheckpointData_V2.Sync (pkg/vm/engine/tae/logtail/ckp_writer.go) only sets transferred = true after sinker.Sync, CollectTableRanges, and the table-range writer.Sync have all succeeded. The defer then skips deletePersistedCheckpointObjects. The names returned in files are only the sinker data objects. The table-range object is a separate BuildObjectName result and is reachable only through the local location, which this error return discards.
Sinker.Close (pkg/objectio/ioutil/sinker.go) nils staged.persisted and staged.unpublished and does not call DeletePersisted.
mergeCheckpointFilesLocked (pkg/vm/engine/tae/db/gc/v3/checkpoint.go) does:
if deleteFiles, tmpNewFiles, newCkp, newCkpData, err = MergeCheckpoint(...); err != nil {
extraErrMsg = "MergeCheckpoint failed"
return err
}Its defers only record metrics, log GC-TRACE-MERGE-CHECKPOINT-FILES, and Clean newCkpData. appendFilesToWAL, UpdateCompacted, updateCheckpointGCWaterMark, and deleteFilesWithPolicy all run only after MergeCheckpoint returns nil. The old checkpoint files in deleteFiles are therefore not removed on this path.
objectWriterV1.WriteEnd uploads in Sync via fs.Write. Write itself only buffers. A context cancel or file-service error at WriteEnd, or an AddBlock error from Write, happens after the data objects and the table-range object are already durable. AddCheckpointMetaFile has not run, so the client does not retain the compact name either.
Those objects are normal object names, not entries of a published checkpoint. Later GC scans published checkpoints and deletes names that aged out of that metadata. It does not reap an object that was never registered. GCWindow verify only logs [Verify GC]not found object for catalog names it expected to find.
Expected Behavior
If compact metadata is not published, every object created by the successful CheckpointData_V2.Sync (sinker data objects and the table-range object) should be deleted before MergeCheckpoint returns the error. A failed sinker.Sync already does this: transferred stays false and deletePersistedCheckpointObjects runs. The post-transfer metadata failure needs the same owner.
Steps to Reproduce
- On a TN that is compacting incremental checkpoints, let
MergeCheckpointpassckpWriter.Sync(non-empty object list;NewDataSinkerusesWithTailSizeCap(0), so the tail is spilled). - Fail the following metadata
WriteorWriteEnd. A canceled context is enough:WriteEndcallsfs.Write(ctx, ...). - Observe
mergeCheckpointFilesLockedlogextra-err-msg=MergeCheckpoint failedand return. - The sinker data object names and the table-range object from
locationremain in the file service. They are absent fromAddCheckpointMetaFile, the WAL append, andUpdateCompacted. A later successful compact does not list them for deletion.
No unit test injects a post-Sync Write / WriteEnd failure into MergeCheckpoint.
Additional information
- A
Syncerror beforetransferred = trueis not this bug.deletePersistedCheckpointObjectsstill runs. - Global and incremental checkpoint publication (
doGlobalCheckpoint,RunICKP) delete unpublished objects unlessmetadataPublishedis set. This compact path does not. NewObjectWriterSpecial(newObjectWriterSpecialV1) currently always returns a nil error, so thewriter, err := NewObjectWriterSpecialbranch is not the practical trigger.WriteandWriteEndare.- This does not delete user table data or the old checkpoints. It leaks the new compact objects on a failed merge.
Activity
Ariznawlll commentedon Sep 22, 2026
Sibling of the metadata
Write/WriteEndhole, on the caller side. A fix that only deletes objects insideMergeCheckpointwhenWriteorWriteEndfails does not cover this path:MergeCheckpointhas already returned nil.origin/main66da3877e9e77f01083c4aac0cb9f94ab6e11fe6.After
ckpWriter.Syncsucceeds,CheckpointData_V2.Synchas settransferred = true, so its cleanup defer will not delete the sinker data objects.MergeCheckpointthen writes the compact metadata, callsclient.AddCheckpointMetaFile, and returns nil with:newFiles/ the caller'stmpNewFiles: sinker data-object names (ckpfilesinSync) plus the compact metadata name (merge.goappendsEncodeCompactCKPMetadataFullNameafterAddCheckpointMetaFile)checkpointEntry.SetLocation(location, location): the table-range object. That name is not inckpfilesand therefore not intmpNewFiles.Synconly appendsobj.ObjectName()fromsinker.GetResult().mergeCheckpointFilesLockedthen does:appendFilesToWALreturns nil immediately whenlogDriver == nil. The failure needs a non-nil driver and a failedAppendEntry(wal.GroupFiles, ...).GroupFilesis the master-slave file copy (GTFiles: "the logservice will read the files required for checkpoint and gc"). It is not the local GC keep-set. A failed append does not by itself make local GC delete these objects, and it also does not publish the new compact.What is left behind:
Sync.newCkp's location.AddCheckpointMetaFilehas already inserted that name intorunnerStore.metaFiles.UpdateCompactedhas not run, soGetCompacted()is still the previous entry.deleteFilesinsideMergeCheckpointis the input checkpoint metadata, location, and table-id location names. A later successful merge of those same inputs does not list the previous attempt's outputs.deleteStaleCKPMetaFileLockedonly walkscleaner.mutation.metaFiles, notrunnerStore.metaFiles, and not objects that were never registered.getEntriesToMergebuilds the next merge fromGetCompacted()plusICKPRange. It does not see this unpublished compact, so the retry writes another generation (BuildObjectName(NewSegmentid(), ...)for the data and range objects). Each failed WAL append after a nilMergeCheckpointtherefore leaks another data + range generation. The compact metadata name is deterministic for the same start/end, so that one file may be overwritten; the object names inside it are not.Crash-only is different.
CkpReplayer.readCheckpointEntrieslists TS-range files, sorts by end TS, and replays onlycompactedEntries[len-1]. The max compact-ext file is adopted, so its data and range objects stay referenced. This comment is not "restart deletes user data". Equal end timestamps are not a stable tie-break, and every non-max compact generation is not replayed and is not deleted.The GC job stays fail-closed: old checkpoints are kept,
UpdateCompactedanddeleteFilesWithPolicydo not run, and this is not the empty keep-set success path in#29258.Cleanup on this error has to be caller-side, and only for objects this attempt created:
tmpNewFiles(sinker data names + compact metadata name)newCkp.GetLocation()RemoveCheckpointMetaFilefor the compact name already passed toAddCheckpointMetaFileDo not delete the scanned-window names that were appended only to build the
GroupFilesentry. Those are the current GC window. Do not deletedeleteFileshere either: those inputs are still the live chain becauseUpdateCompacteddid not run.FillUsageBatOfCompactedruns before the WAL append and its error is ignored, so it is not this trigger. A laterdeleteFilesWithPolicyerror, afterUpdateCompactedhas already succeeded, is the existing "SJW TODO: need to handle not updated scenario" gap (old inputs may remain). That one is not this leak.