Skip to content

fix(fileservice): bound MinIO range reads without draining on close - #32053

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
ck89119:issue-31692-main
Nov 3, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
ck89119:issue-31692-main

Conversation

@ck89119

@ck89119 ck89119 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

Fixes #31692

What this PR does / why we need it:

MinIO bounded reads limited returned bytes but requested an open-ended object suffix and drained it on Close, amplifying small reads into large downloads.

  • Set the HTTP Range upper bound on every initial/retry request and avoid Seek overwriting it. Close bounded readers without draining unread data; preserve unbounded-read behavior.
  • Preserve ETag/VersionID conditions and retry offsets. Centralize byte limiting, handle nil starts, reject empty/reversed ranges, and close readers after initialization failures.
  • Add deterministic regression coverage for actual HTTP response bytes, range boundaries, uncached S3FS consumers, partial-response retries, identity failures, early close, and cancellation.

Local validation on macOS arm64 with Go 1.27.1:

  • mo-cgo-test -json -count=1 -timeout=600s ./pkg/fileservice and the corresponding -race run passed (7 existing skips; no new tests skipped).
  • Six focused tests each passed 100 repetitions under -race.
  • gofmt, package go vet, and golangci-lint 2.14.0 passed.
  • Changed executable-block coverage: 100% (15/15 statements).

No SQL BVT was added: SQL semantics are unchanged; the HTTP byte-count and real SDK/S3FS tests directly verify the affected boundary.

@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 →

@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: b587ee96ca2f727be2b1df18fef0dc9a81895cdd

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: b587ee96ca2f727be2b1df18fef0dc9a81895cdd

Assessment: approve

Bounded MinIO reads preserve range limits across retries and avoid draining on close while retaining identity checks and unbounded behavior. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Complete delta, consumers, linked issue and discussion reviewed; source remained unchanged.

  • Isolation preflight and source/formatting audits passed.

  • Full fileservice normal and race suites passed: 519 top-level passes and six skips each.

  • All six new tests passed 100 repetitions each under the race detector.

  • Receipts and retained logs reconciled in attempt-1/validation-evidence.json.

Limitations:

  • Credential-dependent external-storage cases and opt-in reproduction tests were skipped; no live S3 service was exercised.

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

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 1876b2f at 06:54 UTC

1 h 16 min in the queue, 1 h 16 min of it CI.

So far

  • ✅ Entered the queue Tue 3 Nov, 05:38 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 06:54 · 1876b2f · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot merged commit 1876b2f into matrixorigin:main Nov 3, 2026
@mergify mergify Bot removed the queued label Nov 3, 2026
@ck89119
ck89119 deleted the issue-31692-main branch November 3, 2026 08:43
mergify Bot pushed a commit that referenced this pull request Nov 4, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes #31692

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

Address the remaining uncached-read amplification reported in the [validation comment](#31692 (comment)). #32053 fixed bounded MinIO requests, but S3FS still expanded buffered reads to the full object under the default policy even when configuration disabled the disk cache. The downloaded suffix could not be retained for reuse.

- Select the minimal unfinished-entry range when no disk-cache instance exists, without mutating the caller's policy. Preserve read-to-end behavior and the full-object cache-fill default when disk caching is enabled.
- Extend existing regression fixtures for zero cache capacities, memory-only caching, disabled cache initialization, and explicit policies. Exercise the real MinIO SDK through NewS3FS with disabled caches and default policy, asserting HTTP Range, response-body bytes, and returned content.
- The new regression fails before the fix: a three-byte buffered read downloads all 16 fixture bytes. After the fix, it downloads exactly three bytes.

Validation on macOS arm64, Go 1.27.1:
- Full fileservice and objectio suites passed: 525 and 154 top-level passes respectively; fileservice had seven existing skips.
- Eleven focused tests passed normally and under `-race`, including MinIO retry offsets/upper bounds, identity failures, cancellation, and early-close cleanup.
- Changed executable-block coverage: 100% (4/4 statements). gofmt, package go vet, and golangci-lint 2.14.0 passed.
- Merged current main; relevant implementation, dependencies, and test inputs remain unchanged, so validation evidence is reused.

Limitations: no live MinIO/S3 service or original 40,000-row SQL scenario was rerun. Credential-dependent/opt-in cases remain skipped; this is not complete QA or production-scale performance acceptance. No SQL BVT was added because SQL result/error semantics are unchanged and the HTTP byte-count oracle directly verifies this storage boundary.


Approved-by: XuPeng-SH <[email protected]>
XuPeng-SH added a commit that referenced this pull request Nov 4, 2026
## 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

## 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.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — f482d5bd Deployed Nov 3, 2026 by mergify[bot]
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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MinIO bounded reads download and drain the entire object suffix

3 participants