Skip to content

[4.2-dev] fix(fileservice): prevent duplicate range fan-out - #26842

Merged
mergify[bot] merged 2 commits into
matrixorigin:4.2-devfrom
LeftHandCold:backport/4.2-fileservice-range-fanout
Aug 9, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:4.2-devfrom
LeftHandCold:backport/4.2-fileservice-range-fanout

Conversation

@LeftHandCold

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 #25129
issue #26172

What this PR does / why we need it:

Backport the complete FileService range fan-out fix to 4.2-dev.

4.2-dev contains the range-bypass and 200 ms fallback introduced by #24759
and #24871, but does not contain #26758. Therefore backporting only the
single-entry follow-up from #26834 would leave the multi-entry sparse-range
fan-out unchanged. This PR applies both fixes in dependency order:

  1. fix(fileservice): prevent expensive S3 range fan-out #26758: avoid wide sparse fallback reads and bind waiters to the exact
    cache-producing merge generation.
  2. fix(fileservice): coalesce duplicate single-range fallbacks #26834: coalesce duplicate single-entry exact-range fallbacks after the
    full-object generation exceeds its short wait.

The normal cache-hit and uncontended read paths are unchanged. All waits remain
caller-cancelable and bounded. Merge generations have no background goroutine
or persistent queue and are deleted on leader completion. Followers recheck
cache publication before falling back to a bounded exact read.

Validation on the 4.2-dev base (4066fffaf7):

  • focused FileService regression set, -count=3
  • six concurrency/lifecycle tests under -race (20 or 100 repetitions)
  • full pkg/fileservice test
  • full pkg/fileservice race test
  • go build and go vet for pkg/fileservice

Backported commits retain -x provenance for #26758 and #26834.

LeftHandCold and others added 2 commits August 9, 2026 13:44
)

### Root cause

When a full-object disk-cache fill is still running, followers wait only 200ms and then use `readMinimalRange`. For a multi-column `IOVector`, that function reads one continuous `[min offset, max end]` envelope rather than the logical entry bytes. Sparse columns can therefore turn a few MiB of requested data into a 100+ MiB S3 GET per follower. Under high concurrency this bypasses the existing I/O merge, saturates the 100-connection HTTP pool, and amplifies heap/network pressure until transactions and client connections time out.

### Fix

- Compute the logical bytes, span bytes, and amplification of unfinished entries before bypassing a full-object merge.
- Preserve the existing 200ms fallback for single entries, small spans, and low-amplification ranges.
- Record on each active merger generation whether its actual leader can publish a reusable full-object disk-cache artifact; followers use the capability of the exact generation they joined, rather than inferring it from their own vector.
- When a cache-producing full-object generation is active and the fallback span is larger than 8MiB with amplification above 8x, wait for that generation instead of issuing another broad range GET.
- Bound this second-stage wait with both the caller context and the existing one-minute I/O merge limit.
- If the leader is not cache-producing, or the local limit expires, read unfinished entries as sequential exact ranges instead of one large sparse envelope. The timeout path rechecks caches once first.
- Record the long wait in existing S3FS/IOMerger timing metrics and slow-event details.

### Safety boundaries

- No change to on-disk/wire formats, configuration defaults, cache-hit paths, or reads without merge contention.
- No new goroutine, persistent per-object state, queue, semaphore, or retry loop.
- The cache-producer capability is immutable and scoped to one merger generation. Completion checks and second-stage waits remain bound to that same generation even if a new leader starts for the key.
- `WriterForRead` and `ReadCloserForRead` leaders do not extend follower waits because they cannot publish the shared full-file cache result.
- Leader completion, caller cancellation, and the local wait limit are independent terminal events.
- A wait timeout only changes the current follower's local read mode. It does not cancel, delete, or otherwise mutate the active merge generation.
- Fallback is sequential and fetches each unfinished entry's exact range, preserving follower progress without recreating the large envelope.

### Regression evidence

Three deterministic regressions cover the expensive sparse branch:

- On clean `base/main`, a held full-object merge causes the sparse follower to issue one extra broad ObjectStorage read before its caller deadline (`expected 0, actual 1`). The patch keeps the remote read count at zero until cancellation.
- On the first PR head, a no-deadline caller remains blocked behind a held cache-producing leader and fails a one-second progress guard. The final patch reaches the bounded fallback and issues exactly `[0,1)` and `[9MiB,9MiB+1)`, never the 9MiB envelope.
- On the previous PR head, a real `WriterForRead` leader blocked in its writer causes an ordinary sparse follower to lose its deadline without issuing a read. The final patch identifies that generation as non-cache-producing and performs exactly the two requested range reads after the original short wait.

Verified on final commit:

- `GOWORK=off go build -mod=readonly ./pkg/fileservice`
- `GOWORK=off go vet -mod=readonly ./pkg/fileservice`
- `mo-cgo-test -count=1 -timeout=300s ./pkg/fileservice`
- Relevant merger and sparse-range tests with `-race -count=100`, including generation ownership, cancellation, no-deadline fallback, non-cache-producing leaders, and historical cheap-range fallback
- Full `pkg/fileservice` package with `-race -count=1`

Approved by: @XuPeng-SH

(cherry picked from commit 47c8302)
@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 →

@mergify mergify Bot added the queued label Aug 9, 2026
@mergify

mergify Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-09 06:42 UTC · Rule: release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-08-09 06:42 UTC · at 74f1d3bd7d2c3738a8df4d7a397dfe0318c15bcb · squash

This pull request spent 15 seconds in the queue, including 1 second running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)

@mergify
mergify Bot merged commit 2bbe6a8 into matrixorigin:4.2-dev Aug 9, 2026
24 of 25 checks passed
@mergify mergify Bot removed the queued label Aug 9, 2026

This branch was previously deployed

1 inactive deployment
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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants