Skip to content

fix(backup): use logical file sizes for MinIO stream copies - #32079

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
LeftHandCold:fix/backup-minio-known-size
Nov 4, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
LeftHandCold:fix/backup-minio-known-size

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #32077

What this PR does / why we need it:

Physical backup stream copies currently pass Size=-1 for stat-able immutable files. The MinIO SDK chooses its worst-case unknown-length multipart buffer: 528 MiB per active upload, including tiny metadata files. This causes large live allocations and allocation churn; it is not a demonstrated permanent memory leak.

This patch only opts in when the backup destination explicitly sets is_minio=true:

  • Preserve provider-side CopyObject first and its independent destination-checksum retry. Only a declined provider copy reaches the changed stream fallback.
  • Stat the source's logical length before opening the source stream, then pass it to the existing SDK. Legacy local CRC framing and subpaths use FileService's logical size, not raw os.Stat.
  • Keep source reads EOF-capable. A constant-space reader withholds the last byte until source EOF is verified, so downstream bounded readers cannot silently accept an underestimated length. Reject short, long, empty-mismatch and negative-size cases before reporting successful copying.
  • Carry the private per-backup policy through data, checkpoint, GC metadata and table-ID-history copies. Incremental skipped files remain skipped without stat/read work.
  • Preserve public CopyFile/CopyFileWithRetry defaults used by datasync. Non-MinIO backups, ordinary business FileService writes, provider-copy success, TN/GC, file selection, backup formats and worker counts do not change.

Validation

Linux amd64 validation on server 50, pinned main base dd2499cdcdf2722848851d4debca6cd6c66b4751, with matching Go/native artifacts:

  • Focused reader/copy/configuration tests, including final-byte-plus-error handling, LimitReader/ReadFull, cancellation/failure closure, provider-copy checksum retry, CRC/raw source sizes, incremental skip and default behavior.
  • Complete pkg/backup package tests.
  • pkg/datasync TestCopyFile and golangci-lint 2.14.0 for pkg/backup (0 issues).
  • Real MinIO: 0/1/31 bytes, 64 MiB minus/at/plus one, 128 MiB; wrong lengths reject uploads without publishing destination objects; valid retries and SHA256 readback checks.
  • Actual execBackup, 300 rows/13 columns, then a fresh-directory TAE restore: all columns and the complete row multiset match for both old and fixed paths. This is not a full CN/TN/Proxy deployment or a mo-backup CLI incremental-chain acceptance run.
  • Actual production parallel copier with 15 x 128 MiB files, an allocation barrier and 80 ms added per-part response latency: all copied checksums match. Active SDK buffers fall from 15 x 528 MiB (7.734 GiB) to 15 x 16 MiB (240 MiB), with no injected size adapter. Observed peak process RSS in this pair was about 2016 MiB vs 337 MiB; this is not a production RSS guarantee.

Tradeoffs And Review

The existing SDK now chooses 8 parts instead of 1 for a 128 MiB file: this pair issued 120 rather than 15 part requests, still with 15 file workers. Every streamed file also gains a source Stat/HEAD. The controlled copy pair completed in 11.52 s / 9.22 s; timing on this shared host does not establish a general speedup.

No global buffer tuning, pooling, extra background workers, backup-concurrency increase, filesystem/cache changes, or new upload algorithm. The policy is immutable during copying and each source reader retains the existing close owner. Same-length overwrites remain outside the pre-existing immutable-source assumption.

The high-concurrency foreground-read experiment did not complete its comparison within budget: the old path took about 206 s during substantial host I/O pressure. Its partial results are not counted as passing business-performance evidence. Shared-storage rollout still requires workload observation; this PR does not promise zero contention or a fixed total CN memory bound.

A smaller completed ABBA experiment used the same real MinIO, restored 300-row TAE table, two 128 MiB backup files, and 80 ms per-part response delay. Each foreground observation window was 8 s and performed real object-store GETs (17,940-20,670/window), with zero query errors:

Foreground metric No backup (bookends) Old backup (A/A) Fixed backup (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

QPS/P99 improved relative to the old path, but P95 increased. This is an explicit latency-distribution tradeoff, not a passed "no business-performance impact" claim. The completed mixed test has two backup workers, not fifteen; the separate fifteen-worker test establishes copying correctness and memory behavior only. No change is proposed to production concurrency.

Main advanced to 1876b2f93e14c03ba538e3806e245e3c3203979a (#32053, MinIO bounded-read changes) after the pinned validation base. Mergify synchronized it into this PR as 387da6a1280b13e10936896f522d4ddb15f27555. A follow-up on 50 matched that integrated source and passed the complete backup package, real MinIO size/boundary/retry tests and fresh-directory 300-row/13-column TAE restore. The memory/foreground-performance numbers above remain from the earlier pinned source; performance was not rerun after this merge, and no production deployment is claimed.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Fixed the SCA failure in 280a554. The failing gate was Makefile err-check, which rejects errors.New in production code, before golangci-lint ran.

The size-mismatch error now uses moerr.NewInternalErrorNoCtx. Existing boundary tests additionally assert the MO error code and that an overlong source is not retryable. No successful-copy path, buffer size, concurrency, or other SDK behavior changes.

Validation on server 50: repository-wide make err-check; focused BackupSizeReader/SizedCopy/MinioSizePolicy tests; full pkg/backup tests; golangci-lint 2.14.0 on pkg/backup; the branch-pinned molint check on pkg/backup. All passed. git diff --check also passed. This is scoped validation, not a claim that the new full CI has finished.

The new CI is running. The previous review-only status and disclosed performance-validation caveat remain unchanged; this update does not authorize merging.

@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 280a554c5c10b13a0d6dd96ba85afe15e5772d36

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 280a554c5c10b13a0d6dd96ba85afe15e5772d36

Assessment: approve

The MinIO-only policy coherently reuses logical FileService sizes and existing SDK uploads while preserving public copy defaults and provider-copy retry behavior. The constant-space EOF guard closes the bounded-reader truncation risk; existing SDK byte counting cannot replace it. Data, checkpoint, GC and table-history paths carry the policy. No actionable correctness or design defect remains. Extra stat/part requests and the disclosed latency tradeoff are retained as scoped costs, without a production-performance claim.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Full pkg/backup passed at the frozen head: 64 top-level tests, 180 including subtests, no skips, -count=1; includes new size/error/policy tests and existing restore tests. Receipt checks/1793702385971151086-3.json; backup-normal.jsonl and backup-normal.stderr.log.

  • Datasync TestCopyFile and TestCopyFiles passed with -count=1 and the supplied test-exec; named output in datasync-copy.jsonl. Receipt and terminal exit reconciled in validation-audit.json.

  • Pinned minio-go/v7 v7.0.99 sizing probe passed: unknown length selects 528 MiB; 128 MiB selects eight 16 MiB parts. Receipt checks/1793702234178990290-3.json; sdk-part-size.go and sdk-part-size.log. This checks sizing, not workload latency.

  • Private-tmp/loopback preflight and frozen-range git diff --check passed. Native provenance matched current inputs; repository mo-cgo-test linked both test runs. validation-audit.json reconciles clean head fingerprints, receipts, exits, log hashes and all three discussion keys.

  • Frozen evidence reports successful current-head build, UT, SCA and applicable BVT checks. Skipped and neutral checks are excluded. Complete patch, linked issue and discussion reviewed.

Limitations:

  • Real-MinIO upload/restore experiments are author-reported; their raw artifacts were not included in local_validation. Local package tests and SDK sizing were reproduced independently.

  • Earlier memory and mixed-workload measurements predate main integration. The disclosed P95 increase and incomplete 15-worker foreground run remain limitations; production latency, full CN/TN/proxy deployment and CLI incremental-chain behavior were not independently validated.

@mergify mergify Bot added the queued label Nov 3, 2026
@mergify

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request branch update failed

Less than a minute in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 3 Nov, 10:42 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 10:42 · 280a554

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/ci-cancellation.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

To get back in the queue

  • Update or rebase the branch yourself: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Requeued — the merge queue status continues in this comment ↓.

Times in UTC · dashboard · how the merge queue works

@mergify

mergify Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request branch update failed

49 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 4 Nov, 06:51 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 07:40 · 280a554

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/ci-cancellation.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

To get back in the queue

  • Update or rebase the branch yourself: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot removed the dequeued label Nov 4, 2026
XuPeng-SH added a commit that referenced this pull request Nov 4, 2026
#32080)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #32077

Main companion: #32079. Validated source commit:
`c2fb54e6eecb4e5e7db711df413df29abd2fcecc`.

**Review requested, not a merge request:** publish for review with the
performance tradeoff below disclosed. Do not merge or enable auto-merge
pending that review.

## What this PR does / why we need it:

4.2-dev has the same backup/MinIO integration inefficiency as main:
stream copies pass `Size=-1` even for immutable source files with an
available logical length. MinIO's unknown-length path allocates a 528
MiB multipart buffer per active upload, including tiny metadata files.
This is allocation amplification, not a proven permanent leak.

This is the equivalent narrow main fix, adapted to 4.2-dev's existing
backup tests and retention code:

- Opt in only for physical backup destinations explicitly configured
with `is_minio=true`.
- Keep provider-side copying first, including the independent
destination-checksum retry. Stat only after it declines server-side
copying, before opening the source GET.
- Pass FileService's logical source length to the existing upload SDK.
CRC-framed local files and subpaths must not use their raw on-disk
length.
- Reject truncated/extended sources. Withhold the last byte until source
EOF is confirmed, so a downstream `LimitReader`/`ReadFull` cannot report
success for an underestimated length; explicitly validate empty sources.
- Propagate an immutable private backup policy through data, checkpoint,
GC metadata and table-ID-history copying. Incremental `NeedCopy=false`
files stay untouched.
- Preserve public copy defaults for datasync and non-MinIO callers;
preserve provider-copy behavior, backup selection/retention, formats,
worker counts, TN and GC. No SDK or FileService implementation changes.

### Validation

Server 50, Linux amd64, 4.2-dev base
`10d204b8763f19b2b37ba2147d1d4c1a7828d6d4`, Go 1.26.4 and matching
native artifacts:

- Complete `pkg/backup` package, including existing 4.2-specific
history/retention/restore tests and new
size/configuration/error-boundary tests.
- `pkg/datasync` `TestCopyFile`, preserving the public caller contract.
- golangci-lint 2.6.2 (Go 1.26.4) for `pkg/backup`: 0 issues.
- Real MinIO 0/1/31-byte, 64 MiB minus/at/plus-one and 128 MiB copies;
checksum verification and rejection of small/multipart size mismatches
without publishing the invalid target.
- Actual `execBackup` plus fresh-directory TAE restore: 300 rows, 13
columns, complete restored row multisets match with both old and fixed
paths.
- Real 15 x 128 MiB parallel copy using the production size policy, not
an injected-size adapter: all checksums match, 15 active upload buffers
are 16 MiB each (240 MiB total), observed process peak RSS about 367
MiB.
- The small complete backup's cumulative allocation fell from
approximately 20.15 GiB to 36.54 MiB in this pair. These are cumulative
allocations, not simultaneous RSS.

No full CN/TN/Proxy deployment or mo-backup CLI incremental-chain
acceptance is claimed. The real backup fixture validates the kernel
copy/restore boundary; unchanged incremental selection and newly added
skip assertions are covered by package tests.

### Performance Tradeoff / Hold Before Merge

An actual streamed file gains a source Stat/HEAD. For 128 MiB objects
the existing SDK uses 8 parts instead of 1, so fifteen files issue 120
rather than 15 part requests. File concurrency is unchanged. This 4.2
copy run completed in about 100.5 s during substantial shared-host I/O
pressure; it is not a controlled timing comparison or a speedup claim.

The equivalent main patch was measured with a smaller real-TAE
foreground-read ABBA test: two concurrent 128 MiB backup files, real
MinIO and 80 ms per-part response delay. QPS improved from 5.93/5.71 to
6.13/6.19 and P99 from 908/971 ms to 321/244 ms, but **P95 rose from
165/166 ms to 249/225 ms**. This is not a 4.2-specific benchmark or
proof of zero business interference. The fifteen-worker mixed test did
not finish the comparison within budget and is not counted as a pass.

The user explicitly accepted publishing the minimal patch for review
with this risk, **not merging it**. Shared-storage latency must be
assessed before rollout; do not raise backup concurrency because the
buffer allocation falls. Source objects retain their existing
immutability assumption; the new reader does not detect same-length
overwrites.

---------

Co-authored-by: XuPeng-SH <[email protected]>
@mergify mergify Bot added dequeued and removed queued labels Nov 4, 2026

This branch was successfully deployed

No deployments
ci — f9d1b547 Deployed Nov 4, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants