Skip to content

[Bug]: checkpoint compact leaves new objects behind when metadata write fails after Sync #29259

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 compact (pkg/vm/engine/tae/db/gc/v3/merge.go). This is not #29257 (CN insert / multi_update objects that never reach txn.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

  1. On a TN that is compacting incremental checkpoints, let MergeCheckpoint pass ckpWriter.Sync (non-empty object list; NewDataSinker uses WithTailSizeCap(0), so the tail is spilled).
  2. Fail the following metadata Write or WriteEnd. A canceled context is enough: WriteEnd calls fs.Write(ctx, ...).
  3. Observe mergeCheckpointFilesLocked log extra-err-msg=MergeCheckpoint failed and return.
  4. The sinker data object names and the table-range object from location remain in the file service. They are absent from AddCheckpointMetaFile, the WAL append, and UpdateCompacted. 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 Sync error before transferred = true is not this bug. deletePersistedCheckpointObjects still runs.
  • Global and incremental checkpoint publication (doGlobalCheckpoint, RunICKP) delete unpublished objects unless metadataPublished is set. This compact path does not.
  • NewObjectWriterSpecial (newObjectWriterSpecialV1) currently always returns a nil error, so the writer, err := NewObjectWriterSpecial branch is not the practical trigger. Write and WriteEnd are.
  • This does not delete user table data or the old checkpoints. It leaks the new compact objects on a failed merge.

Activity

  1. added
    kind/bug
    on Sep 22, 2026
  2. Ariznawlll commented on Sep 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    Sibling of the metadata Write / WriteEnd hole, on the caller side. A fix that only deletes objects inside MergeCheckpoint when Write or WriteEnd fails does not cover this path: MergeCheckpoint has already returned nil.

    origin/main 66da3877e9e77f01083c4aac0cb9f94ab6e11fe6.

    After ckpWriter.Sync succeeds, CheckpointData_V2.Sync has set transferred = true, so its cleanup defer will not delete the sinker data objects. MergeCheckpoint then writes the compact metadata, calls client.AddCheckpointMetaFile, and returns nil with:

    • newFiles / the caller's tmpNewFiles: sinker data-object names (ckpfiles in Sync) plus the compact metadata name (merge.go appends EncodeCompactCKPMetadataFullName after AddCheckpointMetaFile)
    • checkpointEntry.SetLocation(location, location): the table-range object. That name is not in ckpfiles and therefore not in tmpNewFiles. Sync only appends obj.ObjectName() from sinker.GetResult().

    mergeCheckpointFilesLocked then does:

    newFiles := tmpNewFiles
    for _, stats := range c.GetScannedWindowLocked().files {
        newFiles = append(newFiles, stats.ObjectName().String())
    }
    if err = c.appendFilesToWAL(newFiles...); err != nil {
        return
    }
    c.checkpointCli.UpdateCompacted(newCkp)       // not reached
    c.updateCheckpointGCWaterMark(&newWaterMark)  // not reached
    // deleteFilesWithPolicy(deleteFiles)          // not reached

    appendFilesToWAL returns nil immediately when logDriver == nil. The failure needs a non-nil driver and a failed AppendEntry(wal.GroupFiles, ...). GroupFiles is 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:

    1. Sinker data objects from this Sync.
    2. The table-range object named by newCkp's location.
    3. The compact metadata object. AddCheckpointMetaFile has already inserted that name into runnerStore.metaFiles. UpdateCompacted has not run, so GetCompacted() is still the previous entry.

    deleteFiles inside MergeCheckpoint is 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. deleteStaleCKPMetaFileLocked only walks cleaner.mutation.metaFiles, not runnerStore.metaFiles, and not objects that were never registered.

    getEntriesToMerge builds the next merge from GetCompacted() plus ICKPRange. 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 nil MergeCheckpoint therefore 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.readCheckpointEntries lists TS-range files, sorts by end TS, and replays only compactedEntries[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, UpdateCompacted and deleteFilesWithPolicy do 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)
    • the table-range object from newCkp.GetLocation()
    • RemoveCheckpointMetaFile for the compact name already passed to AddCheckpointMetaFile

    Do not delete the scanned-window names that were appended only to build the GroupFiles entry. Those are the current GC window. Do not delete deleteFiles here either: those inputs are still the live chain because UpdateCompacted did not run.

    FillUsageBatOfCompacted runs before the WAL append and its error is ignored, so it is not this trigger. A later deleteFilesWithPolicy error, after UpdateCompacted has already succeeded, is the existing "SJW TODO: need to handle not updated scenario" gap (old inputs may remain). That one is not this leak.

  3. added this to the MO-202609 milestone on Sep 23, 2026
  4. added theissue type on Sep 23, 2026
  5. added
    severity/s0
    and removed on Sep 23, 2026
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