fix: support File payloads in ThrottledStore (fixes LocalFileSystem panic)#808
Closed
adriangb wants to merge 1 commit into
Closed
fix: support File payloads in ThrottledStore (fixes LocalFileSystem panic)#808adriangb wants to merge 1 commit into
adriangb wants to merge 1 commit into
Conversation
ThrottledStore panicked with unimplemented!() on the first get when wrapping a store that returns a GetResultPayload::File, such as LocalFileSystem, which is the obvious store to throttle for performance testing. The free function throttle_get funnels every result through a payload match whose File arm was unimplemented!(). Preserve the File fast path instead of forcing it into a byte stream: for a File payload, apply the per-byte throttle as a single up-front sleep computed from the known requested range (mirroring get_ranges), then return the payload untouched. When wait_get_per_byte is zero this is a no-op, so the common per-call-only case passes the File straight through. Stream throttling is unchanged. Adds a regression test wrapping a LocalFileSystem that panics on the previous code and passes now.
Contributor
Author
|
I decided it was better to make a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
No separate issue is filed; the bug and repro are described in full below.
Rationale for this change
ThrottledStoreis the crate's built-in wrapper for performance testing (it injectswait_get_per_callfirst-byte latency,wait_get_per_bytethroughput throttling, and so on). But it panics withnot implementedon the firstget/get_opts/headwhen it wraps a store that returns a file-backed payload, which is exactly whatLocalFileSystemdoes when thefsfeature is enabled, andLocalFileSystemis the obvious inner store you would want to throttle for perf testing.Every
get_optsresult is funnelled through the free functionthrottle_getinsrc/throttle.rs, whose payload match was:LocalFileSystem::get_optsreturnsGetResultPayload::File(..), so the first read hitsunimplemented!().Note that the fixed per-call latency already worked for File payloads (
sleep(wait_get_per_call)runs before the inner call inget_opts), andget_rangesalready worked (it delegates directly). Only the per-byte stream-wrapping step inthrottle_getpanicked.Minimal repro:
What changes are included in this PR?
throttle_getnow handles the File payload instead of panicking. The design preserves the local-file fast path rather than forcing every File read into a byte stream just so it can be throttled:Streampayload, behavior is byte-for-byte unchanged: the per-byte throttle is applied lazily per chunk as before.Filepayload, the per-byte component is applied as a single eager sleep computed from the known requested range (result.range), mirroring howget_rangesalready throttles a whole vectored read up front, and then the File payload is returned untouched. Becausesleepis a no-op on a zero duration, the common case where onlywait_get_per_callis set (andwait_get_per_byteis zero) passes the File payload straight through with no allocation or stream conversion.throttle_getbecomesasyncso the File-path sleep can be awaited; the single caller inget_optsawaits it.A regression test (
get_local_file_system) wraps a realLocalFileSystemin aThrottledStorewith non-zero per-call and per-byte waits, reads an object back, asserts the payload is still aFile(fast path preserved), and asserts the bytes are correct. This test panics on the previous code and passes now.Are there any user-facing changes?
Yes, a bug fix:
ThrottledStoreno longer panics when wrapping a store that returns aGetResultPayload::File(e.g.LocalFileSystem). No public API changes;throttle_getis a private function.