Repository navigation
fix(fileservice): prevent expensive S3 range fan-out - #26758
mergify[bot] merged 7 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Requesting changes for one liveness regression.
[P1] Bound the second-stage full-object merge wait independently of caller deadlines.
After the existing Merge(..., shortIOWaitDuration) returns at about 200 ms, the new expensive-range branch calls waitContext(ctx, mergeKey). That helper has no local bound: it returns only when the leader closes its merge channel or ctx.Done() fires. FileService accepts valid contexts with no deadline (for example context.Background()). If the leader's full-object remote read stalls, a sparse follower that previously fell back to its own range read after the bounded wait can now block forever behind the same stalled data path.
The new regression test supplies a 100 ms context deadline, so it proves cancellation propagation but does not cover the no-deadline liveness regression.
Please preserve a bounded follower-progress contract while still avoiding the large sparse envelope/fan-out (the exact fallback/admission design can remain local). Add a stuck-leader regression using a no-deadline caller context and prove the follower reaches a bounded fallback without issuing the huge envelope.
|
已确认该 review 指出的是实际可达的 P1 活性问题,并已在
新增 |
XuPeng-SH
left a comment
There was a problem hiding this comment.
The previous no-deadline liveness issue is bounded in the new commit, and the timeout path itself has bounded timer, connection, and goroutine ownership. One blocking producer/consumer classification issue remains: the second-stage wait is not restricted to a merge generation that can actually populate the cache the follower plans to reuse. See the inline P1 and the deterministic WriterForRead counterexample.
Merge Queue Status
This pull request spent 51 minutes 28 seconds in the queue, including 41 minutes 10 seconds running CI. Required conditions to merge
|
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. #26758: avoid wide sparse fallback reads and bind waiters to the exact cache-producing merge generation. 2. #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. Approved by: @XuPeng-SH
## 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 #26172 Follow-up to #26758. ## What this PR does / why we need it: ### Root cause #26758 prevents a stalled full-object cache fill from turning sparse multi-entry reads into large amplified S3 ranges. It intentionally preserves the 200ms fallback for a single bounded entry. That remaining path bypasses the I/O merger. When many requests need the same entry while the full-object fill is still running, every follower starts the same exact S3 range GET after 200ms. A small hot range can therefore fan out across the object-storage connection pool and increase network, heap, and query latency pressure. ### Fix - After the existing 200ms full-object wait expires, create a second merger generation keyed by the exact single-entry range. - Admit this merge only when the leader can publish a reusable memory-cache or per-entry disk-cache result. - Bind followers to the exact generation and wait at most the existing one-minute I/O limit, also respecting the caller context. - Recheck caches after leader completion. If publication fails or the wait expires, continue with the existing exact-range fallback without rejoining either merge generation. - Keep leader completion ordered after deferred cache updates, so followers cannot wake before the reusable result is published. ### Safety boundaries - Cache hits, uncontended reads, multi-entry reads, stream reads, and no-cache-write reads are unchanged. - Different ranges use different merge keys and proceed independently. - No goroutine, queue, retry loop, wire format, disk format, or configuration is added. - Cancellation and the existing local I/O wait limit remain terminal bounds. - Cache admission failure remains a normal cache miss and falls back to one exact range read. ### Tests - A deterministic blocked-storage test starts 16 same-range followers and proves they do not issue duplicate object-storage reads, honor caller cancellation, and reuse the leader's published cache result. - A second deterministic test proves different exact ranges do not block each other. - Focused tests passed with `-race -count=20`. - Full `pkg/fileservice` tests and full package race tests passed. - `go build`, `go vet`, and `git diff --check` passed. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
) ### 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
…igin#26834) ## 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 matrixorigin#26172 Follow-up to matrixorigin#26758. ## What this PR does / why we need it: ### Root cause matrixorigin#26758 prevents a stalled full-object cache fill from turning sparse multi-entry reads into large amplified S3 ranges. It intentionally preserves the 200ms fallback for a single bounded entry. That remaining path bypasses the I/O merger. When many requests need the same entry while the full-object fill is still running, every follower starts the same exact S3 range GET after 200ms. A small hot range can therefore fan out across the object-storage connection pool and increase network, heap, and query latency pressure. ### Fix - After the existing 200ms full-object wait expires, create a second merger generation keyed by the exact single-entry range. - Admit this merge only when the leader can publish a reusable memory-cache or per-entry disk-cache result. - Bind followers to the exact generation and wait at most the existing one-minute I/O limit, also respecting the caller context. - Recheck caches after leader completion. If publication fails or the wait expires, continue with the existing exact-range fallback without rejoining either merge generation. - Keep leader completion ordered after deferred cache updates, so followers cannot wake before the reusable result is published. ### Safety boundaries - Cache hits, uncontended reads, multi-entry reads, stream reads, and no-cache-write reads are unchanged. - Different ranges use different merge keys and proceed independently. - No goroutine, queue, retry loop, wire format, disk format, or configuration is added. - Cancellation and the existing local I/O wait limit remain terminal bounds. - Cache admission failure remains a normal cache miss and falls back to one exact range read. ### Tests - A deterministic blocked-storage test starts 16 same-range followers and proves they do not issue duplicate object-storage reads, honor caller cancellation, and reuse the leader's published cache result. - A second deterministic test proves different exact ranges do not block each other. - Focused tests passed with `-race -count=20`. - Full `pkg/fileservice` tests and full package race tests passed. - `go build`, `go vet`, and `git diff --check` passed. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
) ### 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
…igin#26834) ## 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 matrixorigin#26172 Follow-up to matrixorigin#26758. ## What this PR does / why we need it: ### Root cause matrixorigin#26758 prevents a stalled full-object cache fill from turning sparse multi-entry reads into large amplified S3 ranges. It intentionally preserves the 200ms fallback for a single bounded entry. That remaining path bypasses the I/O merger. When many requests need the same entry while the full-object fill is still running, every follower starts the same exact S3 range GET after 200ms. A small hot range can therefore fan out across the object-storage connection pool and increase network, heap, and query latency pressure. ### Fix - After the existing 200ms full-object wait expires, create a second merger generation keyed by the exact single-entry range. - Admit this merge only when the leader can publish a reusable memory-cache or per-entry disk-cache result. - Bind followers to the exact generation and wait at most the existing one-minute I/O limit, also respecting the caller context. - Recheck caches after leader completion. If publication fails or the wait expires, continue with the existing exact-range fallback without rejoining either merge generation. - Keep leader completion ordered after deferred cache updates, so followers cannot wake before the reusable result is published. ### Safety boundaries - Cache hits, uncontended reads, multi-entry reads, stream reads, and no-cache-write reads are unchanged. - Different ranges use different merge keys and proceed independently. - No goroutine, queue, retry loop, wire format, disk format, or configuration is added. - Cancellation and the existing local I/O wait limit remain terminal bounds. - Cache admission failure remains a normal cache miss and falls back to one exact range read. ### Tests - A deterministic blocked-storage test starts 16 same-range followers and proves they do not issue duplicate object-storage reads, honor caller cancellation, and reuse the leader's published cache result. - A second deterministic test proves different exact ranges do not block each other. - Focused tests passed with `-race -count=20`. - Full `pkg/fileservice` tests and full package race tests passed. - `go build`, `go vet`, and `git diff --check` passed. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
) ### 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
…igin#26834) ## 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 matrixorigin#26172 Follow-up to matrixorigin#26758. ## What this PR does / why we need it: ### Root cause matrixorigin#26758 prevents a stalled full-object cache fill from turning sparse multi-entry reads into large amplified S3 ranges. It intentionally preserves the 200ms fallback for a single bounded entry. That remaining path bypasses the I/O merger. When many requests need the same entry while the full-object fill is still running, every follower starts the same exact S3 range GET after 200ms. A small hot range can therefore fan out across the object-storage connection pool and increase network, heap, and query latency pressure. ### Fix - After the existing 200ms full-object wait expires, create a second merger generation keyed by the exact single-entry range. - Admit this merge only when the leader can publish a reusable memory-cache or per-entry disk-cache result. - Bind followers to the exact generation and wait at most the existing one-minute I/O limit, also respecting the caller context. - Recheck caches after leader completion. If publication fails or the wait expires, continue with the existing exact-range fallback without rejoining either merge generation. - Keep leader completion ordered after deferred cache updates, so followers cannot wake before the reusable result is published. ### Safety boundaries - Cache hits, uncontended reads, multi-entry reads, stream reads, and no-cache-write reads are unchanged. - Different ranges use different merge keys and proceed independently. - No goroutine, queue, retry loop, wire format, disk format, or configuration is added. - Cancellation and the existing local I/O wait limit remain terminal bounds. - Cache admission failure remains a normal cache miss and falls back to one exact range read. ### Tests - A deterministic blocked-storage test starts 16 same-range followers and proves they do not issue duplicate object-storage reads, honor caller cancellation, and reuse the leader's published cache result. - A second deterministic test proves different exact ranges do not block each other. - Focused tests passed with `-race -count=20`. - Full `pkg/fileservice` tests and full package race tests passed. - `go build`, `go vet`, and `git diff --check` passed. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
fixes #26172
What this PR does / why we need it:
Root cause
When a full-object disk-cache fill is still running, followers wait only 200ms and then use
readMinimalRange. For a multi-columnIOVector, 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
Safety boundaries
WriterForReadandReadCloserForReadleaders do not extend follower waits because they cannot publish the shared full-file cache result.Regression evidence
Three deterministic regressions cover the expensive sparse branch:
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.[0,1)and[9MiB,9MiB+1), never the 9MiB envelope.WriterForReadleader 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/fileserviceGOWORK=off go vet -mod=readonly ./pkg/fileservicemo-cgo-test -count=1 -timeout=300s ./pkg/fileservice-race -count=100, including generation ownership, cancellation, no-deadline fallback, non-cache-producing leaders, and historical cheap-range fallbackpkg/fileservicepackage with-race -count=1