Skip to content

[Bug]: backup checkpoint rewrite leaks input-batch memory after successful completion #32084

Open

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I searched open and closed issues for the exact rewrite symbol and backup/checkpoint memory leaks.

Branch Name

main; the same missing input-batch cleanup is also present in inspected 4.2-dev source.

Commit ID

  • Current main at investigation: 1876b2f93e14c03ba538e3806e245e3c3203979a.
  • Executed diagnostic source: 387da6a1280b13e10936896f522d4ddb15f27555, a main-based MinIO backup PR head. pkg/vm/engine/tae/logtail/backup.go, pkg/objectio/ioutil/sinker.go, and pkg/common/mpool/mpool.go are byte-identical to the main commit above. The MinIO patch does not modify the failing code.
  • Inspected 4.2-dev base: 10d204b8763f19b2b37ba2147d1d4c1a7828d6d4. Runtime reproduction below is on main only; 4.2 runtime verification is pending.

Other Environment Information

  • Linux amd64, Go 1.27.1, GOEXPERIMENT=simd, GOAMD64=v3, repository CGo test wrapper.
  • Isolated test process, 2 CPU and 6 GiB limits, 90-second Go test timeout.
  • Persisted checkpoint format through MemoryFS with caches disabled; real checkpoint writer/reader/rewrite functions. No running cluster, MinIO, SQL driver, or network is needed.

Actual Behavior

ReWriteCheckpointAndBlockFromKey allocates input batches using common.CheckpointAllocator, fills them with checkpoint object metadata, and passes them to dataSinker.Write, but never cleans the input batches:

  • objectInfoMeta and tombstoneInfoMeta in the len(insertObjBatch) > 0 branch;
  • dest in the other branch.

Sinker.Write copies with UnionWindow; it does not take ownership of its input. dataSinker.Close releases the sinker's own copies, not these original batches. The rewrite's existing objData cleanup also does not own these three locals.

MPool records these on-heap allocations in the global pointer registry keyed by unsafe.Pointer. Therefore losing the local batch variable does not make its backing allocations collectible. Explicit Batch.Clean is required. This is retained live memory, not merely a cumulative allocation counter or an RSS decay delay.

Runtime Evidence

A diagnostic invokes the actual rewrite three times on the same 32-object checkpoint, with a fresh disabled-cache destination each time. After every successful return it calls runtime.GC() and reads common.CheckpointAllocator.OnHeapOutstanding() relative to the pre-rewrite baseline.

Both branches reproduce independently:

Iteration Additional retained bytes Additional retained allocations
1 9,632 10
2 19,264 20
3 28,896 30

The two fixtures are (1) unchanged/non-rewritten object metadata and (2) nonappendable objects whose deletion timestamp is cleared by backup rewriting. Both original-source subtests fail the zero-residual-ownership assertion; all rewrite calls themselves succeed.

An isolated Go overlay adds only three deferred Clean(common.CheckpointAllocator) calls, one immediately after each batch construction. With unchanged inputs, both subtests pass and report 0 retained bytes / 0 retained allocations after all three iterations. No product branch or existing PR was changed by this diagnostic control.

Expected Behavior

The creator retains ownership of input batches passed to copying Sinker.Write. Release them on success and on all error exits. Repeated successful checkpoint rewriting must not accumulate outstanding allocations from these input batches.

Steps to Reproduce

  1. Create a disabled-cache MemoryFS source and a real checkpoint with 32 object metadata rows using ckputil.NewDataSinker, appendValToBatch, and CheckpointData_V2.Sync. Clean the fixture input and close its sinker before measuring.
  2. For the unchanged branch use create TS 20 and empty delete TS. For the nonappendable rewrite branch use create TS 5 and delete TS 30. Use backup TS 15.
  3. Open the checkpoint with GetCheckpointReader.
  4. Record common.CheckpointAllocator.OnHeapOutstanding().
  5. Three times: create a new disabled-cache MemoryFS destination, call ReWriteCheckpointAndBlockFromKey, assert success, call runtime.GC(), and record outstanding bytes/allocations.
  6. Assert the final ownership equals the initial baseline. It fails with the increments above.
  7. Repeat with only the three missing input-batch cleanup calls added: residual ownership is zero.

Command used through the repository-supported CGo wrapper:

.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=90s \
  -run '^TestDiagnosticBackupRewriteMemoryOwnership$' ./pkg/vm/engine/tae/logtail

Root Cause And Code References

Scope And Limits

Activity

  1. added
    kind/bug
    on Nov 3, 2026
  2. self-assigned this
    on Nov 3, 2026
  3. added
    severity/s1
    and removed on Nov 3, 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/s1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions