Skip to content

[Bug]: MinIO physical backup allocates 528 MiB per unknown-length stream copy #32077

Closed

Description

@LeftHandCold

Is there an existing issue for the same bug?

Branch Name

main and 4.2-dev

Commit ID

  • main inspected: dd2499cdcdf2722848851d4debca6cd6c66b4751
  • 4.2-dev inspected: 10d204b8763f19b2b37ba2147d1d4c1a7828d6d4
  • Initial real-MinIO reproduction: main dd762803d1e3cf117d352906fce9d537581c1523; the relevant backup stream/MinIO upload path is unchanged in the inspected main.

Other Environment Information

Linux amd64, Go 1.27.1 for the initial main experiment, real MinIO RELEASE.2023-11-01T18-37-25Z, MO's parallelCopyData and execBackup paths. The destination uses is_minio=true. Tests use owned, isolated resources; this is not a production heap attribution.

Actual Behavior

Physical backup stream copies pass IOEntry.Size=-1 even for immutable source files whose logical length is available through FileService.StatFile.

The current MinIO SDK (minio-go/v7 v7.0.99) treats this as an unknown-length upload. Its default part-size calculation reserves 528 MiB per active upload, including tiny checkpoint/GC metadata files. Slow storage prolongs the lifetime of these allocations. This is bounded allocation amplification, not a proven permanent memory leak.

Confirmed call chain

parallelCopyData / metadata copies -> CopyFileWithRetry -> CopyFile -> stream fallback -> destination IOEntry.Size=-1 -> S3FS without a size hint -> MinioSDK.Write -> PutObject(..., -1, ...) -> unknown-length multipart buffer.

Provider-side CopyObject success bypasses this mechanism. The destination SDK, not merely the source storage vendor, determines whether it occurs.

Initial measured evidence

For 15 concurrent copies of 128 MiB files, both groups completed and passed destination read-back SHA256 checks:

SDK allocation Unknown length Accurate length control
Per active upload 528 MiB 16 MiB
15 active uploads 7.734 GiB 240 MiB

The accurate-length control was an experimental adapter, not a completed product fix. The barrier measurement observes live allocated buffers; it must not be equated with the whole process RSS.

A separate actual execBackup + fresh-directory TAE restore test used 300 rows/13 columns and compared all restored row values. Both modes passed. In the unknown-length run, 39 uploads accounted for approximately 20.1 GiB of cumulative SDK allocation despite only about 115 KiB being observed on the stream-copy path. Cumulative allocation is not simultaneous live memory, and this byte count excludes rewritten backup objects.

Expected Behavior

For explicitly configured MinIO physical backups, stream copies of immutable files should provide their trustworthy logical content length, allowing the existing SDK to choose proportionate buffers. Other storage SDKs, ordinary business writes, datasync, and provider-side copying should preserve their existing behavior.

Steps to Reproduce

  1. Configure a MinIO backup destination with is_minio=true and a source for which provider-side copying is unavailable (for example, a local source or a different object-store endpoint).
  2. Exercise MO's physical-backup copying with parallelism=15, using 15 distinct 128 MiB source objects. Capture heap profiles while all uploads are active.
  3. Observe approximately 15 x 528 MiB of active unknown-length multipart buffers.
  4. In a controlled test only, provide the exact destination length while holding all other inputs constant. The existing SDK selects 16 MiB buffers for this size. Verify copied bytes and checksums.
  5. Also test small metadata files and perform a complete backup/restore comparison; optimizing only the bulk-data loop misses the small-file allocation churn.

Root Cause And Proposed Fix Boundary

This is a backup/SDK integration inefficiency: the backup already has immutable, stat-able files, but discards their size on the stream-copy path. It is not evidence that MinIO must remove buffering needed for multipart upload/retry, or that a recent commit introduced the problem.

The narrow fix should:

  • Opt in only for backup destinations explicitly configured with is_minio=true.
  • Keep provider-side copy first, including the separate checksum retry protection.
  • Obtain the logical source length before opening its GET stream; raw os.Stat is incorrect for legacy CRC-framed local files.
  • Pass the length to the existing SDK without changing global multipart defaults, backup concurrency, TN, or GC.
  • Reject short/long source streams, including the zero-length case. Merely setting Size can silently truncate if a downstream LimitReader never checks source EOF.
  • Preserve public copy defaults used by datasync and other SDKs. In particular, supplying length to the native Aliyun SDK can select a different small-file buffering path.

Acceptance Criteria

Focused length/error/cancel/retry tests; public-default and provider-copy controls; CRC/raw source coverage; real MinIO small/large/multipart boundary tests; full backup and fresh restore comparison; allocation measurement at the same concurrency. Extra HEAD and multipart request overhead must be measured separately from memory savings. The initial timing results do not establish a stable throughput improvement or zero shared-storage interference.

Activity

  1. added
    kind/bug
    on Nov 3, 2026
  2. LeftHandCold commented on Nov 3, 2026

    @LeftHandCold
    CollaboratorAuthor

    Implemented equivalent, narrowly scoped patches for review:

    These are for review only; do not merge yet. The user explicitly accepted publication with the latency risk below disclosed. Auto-merge is not enabled.

    Scope

    Only an explicitly configured is_minio=true physical-backup destination opts in. After provider-side copying declines, obtain the logical source size before opening its stream and pass that size to the existing SDK. Metadata/history copying is included, not just the bulk data loop. Other SDKs, public copy functions/datasync, normal FileService writes, file selection/retention, TN/GC, backup formats and worker counts remain unchanged.

    Length validation is essential: setting Size alone can silently truncate behind a downstream LimitReader. The patch checks EOF before returning the final byte and handles empty sources separately. Same-length overwrites remain outside the existing immutable-source premise.

    Completed Validation On 50

    • Both branches: complete pkg/backup tests, datasync TestCopyFile, focused short/long/empty/error/cancel/provider-copy tests, CRC/raw/subpath size contracts and incremental skip-without-stat assertions.
    • Both branches: pkg/backup golangci-lint, 0 issues (main 2.14.0/Go 1.27.1; 4.2 2.6.2/Go 1.26.4).
    • Real MinIO: empty/single-byte/small files, 64 MiB minus/at/plus-one, 128 MiB, short/long streams; invalid uploads do not publish destination objects. Main also verified successful retries after rejected small/multipart copies.
    • Both branches: actual execBackup and fresh-directory TAE restore; 300 rows/13 columns, complete row multisets and values match for old/fixed paths.
    • Both branches: actual production parallel copier, 15 x 128 MiB, destination SHA256 verification. This is the implemented policy, not the original size-injection adapter.

    In the main controlled pair with 80 ms added per-part response latency:

    Measure Old Fixed
    Active SDK buffers 15 x 528 MiB = 7.734 GiB 15 x 16 MiB = 240 MiB
    Observed peak process RSS ~2016 MiB ~337 MiB
    Multipart part requests 15 120
    Copy elapsed 11.52 s 9.22 s

    The 4.2 small full backup also reduced cumulative allocation from ~20.15 GiB to ~36.54 MiB, with matching restore results. Cumulative allocation, active buffers and RSS must not be conflated. These measurements neither impose a total-CN memory bound nor prove that all reported IDC 30-GiB usage comes from this mechanism.

    Performance Risk Not Hidden

    The fifteen-worker foreground-read comparison did not complete within its time budget; the old path alone took ~206 s during substantial shared-host I/O pressure. This is not a passing business-performance sample.

    A smaller completed main ABBA test used two 128-MiB backup files, real MinIO, actual restored-TAE scans, 80 ms per-part response latency, and 8-s foreground windows:

    Metric No backup (bookends) Old A/A Fixed B/B
    QPS 6.53 / 6.50 5.93 / 5.71 6.13 / 6.19
    P95 ms 163 / 163 165 / 166 249 / 225
    P99 ms 174 / 166 908 / 971 321 / 244

    All foreground queries returned correctly, with 17,940-20,670 real GETs/window. QPS/P99 improve, but P95 increases: this is an explicit tradeoff, not "zero business impact." It is also not fifteen-worker or production-4.2 latency acceptance. Every streamed file adds a Stat/HEAD; 128-MiB uploads use more parts. Keep existing concurrency and review shared-storage latency before merge/rollout.

    Main subsequently advanced to 1876b2f9 (#32053, MinIO bounded-read changes). The pinned experiment does not validate that later commit. No full CN/TN/Proxy deployment or mo-backup CLI incremental-chain test is claimed.

    Publication readback found Mergify had synchronized main into #32079, producing 387da6a1280b13e10936896f522d4ddb15f27555. An additional source-matched run on 50 passed the integrated backup package, real MinIO size/boundary/retry checks and the fresh-directory 300-row/13-column restore (exit 0). The earlier memory and mixed-read performance figures were not rerun on that merge; their original attribution and the P95 hold remain unchanged.

    Detailed logs/profiles, exact scripts and review notes are retained under docs/codex-handoffs/backup-minio-fix-20261103-evidence/ locally and /tmp/mo-backup-minio-validation-20261103/ on 50. Owned MinIO test containers were removed; no production environment was modified.

  3. self-assigned this
    on Nov 3, 2026
  4. added
    severity/s0
    and removed on Nov 3, 2026
  5. XuPeng-SH commented on Nov 4, 2026

    @XuPeng-SH
    Contributor

    Scoped main QA handoff after #32079 merged (0a7847abed712ed893d841a3c5fa415327eec761). This is not acceptance or production-rollout approval. Only physical-backup stream fallback to explicitly configured is_minio=true destinations uses logical source length and EOF checks, including data and metadata. Provider copy, public/datasync defaults, formats and concurrency remain unchanged.

    Author reports real-MinIO boundary/retry checks, 300-row/13-column backup/restore, and 15 x 128 MiB copies with checksum verification; review independently ran backup/datasync tests and SDK sizing probes. This handoff run performed no local tests.

    The measured latency risk in comment 6598044260 remains visible: each streamed file adds Stat/HEAD, a 128 MiB upload uses eight rather than one part, and two-worker mixed-read P95 rose from 165/166 ms to 249/225 ms. The fifteen-worker foreground test was incomplete. Earlier allocation/performance figures were not rerun after the later main integration. The subsequent final review treats this as a disclosed cost rather than an unfinished correctness fix; QA must not call it zero business impact.

    Please verify merged-build length mismatch rejection, provider-copy retries, CRC/subpath handling, metadata/history and skip paths, complete incremental chains and deployment backup/restore. Independently evaluate shared-storage foreground latency without increasing backup concurrency. Buffer reduction is not a total-CN RSS bound, and the old P95 hold is not silently treated as rollout acceptance.

  6. slyunnn commented on Nov 9, 2026

    @slyunnn

    Regression and extended verification for #32077 (2026-11-09)

    Verification Environment

    • Frozen MatrixOne main e2459cc55f4b514893e19732743460bc5f16d552 — docs: design early runtime filtering and dictionary vector execution (#32380).
    • Native 2 CN / 1 TN / 1 Log service / Proxy deployment on macOS arm64, built with Go 1.27.1. Source storage used DISK-V2. Real MinIO used pinned official RELEASE.2025-09-07T16-13-09Z source.
    • Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001 and CN2 127.0.0.1:16002 were reachable with the verified binary version. Physical-backup requests used the public mo-backup CLI through Proxy 6001. Complete recovered row values, subsequent writes and rollback were checked through all three endpoints.
    • Go FileService/MinIO API tests exercised the upload protocol directly. An independent Linux amd64 Actions execution used the same MatrixOne SHA and passed all named integration tests with cleanup exit 0. Linux verification

    What Was Covered

    • OK — Reproduced the unknown-size allocation counterfactual in the same build. Identical 128 MiB streams used approximately 1,056 MiB active SDK heap for 2 unknown-size workers and 32 MiB for 2 fixed-policy workers, measured after allocation with readers paused.
    • OK — The original 15-worker boundary completed with approximately 240 MiB active SDK heap, transferring 1,920 MiB with verified object checksums. Both local and Linux executions passed.
    • OK — Checked real MinIO copies with CRC/raw local FileServices, subpaths, empty streams, 1 byte, 4 KiB, 64 MiB-1, 64 MiB, 64 MiB+1 and 128 MiB. Short/long advertised sizes were rejected and invalid target objects remained unpublished.
    • OK — Ran caller-policy, provider-copy/retry, cancellation, logical-length and backup-history component regressions. The real MinIO-backed TAE consumer restored its 300-row, 13-column fixture with committed deletes applied.
    • OK — Used real mo-backup commit 84cb6f797cbfda622258a96f5bd629ce566d24f4 to take a full backup and 2 successive incremental backups after updates/deletes/inserts. Restored the final chain with checksum verification into a new MinIO prefix and fresh deployment directories. All 992 recovered rows matched the complete independent saved row oracle through Proxy/CN1/CN2. New catalog writes, cross-CN reads and rollback also passed.
    • OK — Recorded same-service uncached foreground GET samples in ABBA order at 2 workers and in the 15-worker fixed-policy run.
    • Failed — The independent existing empty-object provider-copy checksum path returns EOF after publishing its target. Public-API repeats confirmed the empty/non-empty contrast, and this defect is tracked separately as #32413.
    • Not covered — Production business-SQL latency, a rollout-SLO campaign and a total-CN RSS bound.

    Findings

    Fix 0a7847abed712ed893d841a3c5fa415327eec761, fix(backup): use logical file sizes for MinIO stream copies, is delivered by PR #32079. The measured buffer reduction and real backup/recovery checks pass for its scoped stream fallback. The extra source stat and multipart behavior remain relevant operational costs. Foreground GET observations describe this test workload. Fix PR

    The separate provider-copy checksum defect predates this fix and is associated with the provider-copy path from PR #26291. New defect #32413

    MOTR / BVT Coverage

    Reused existing backup component coverage and added an opt-in real-MinIO regression to the Nightly testing repository. Independent upload workers run concurrently. Allocation waves and size fixtures run sequentially with unique buckets and explicit cleanup. The first Linux attempt reached MinIO's free-drive protection threshold. The delivered test releases compilation temporary storage and deletes verified objects between waves, and the subsequent Linux run passed.

    The independent branch is test/issue-32077-minio-stream-memory. Its test change is submitted for review. Existing SQL coverage was reused. Nightly PR #1915

    Final Conclusion

    Fixed for the scoped MinIO physical-backup stream-allocation defect on the tested main build. The independent provider-copy defect remains tracked in #32413.

    Large-data regression is required and completed because the failure depends on upload buffer size and concurrent active streams. The 128 MiB objects and 15 fixed-policy workers directly cross that boundary. Further unrelated data growth or a TKE performance campaign is unnecessary for this allocation conclusion.

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

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions