Repository navigation
blob: add Bucket.SetDefaultReaderOptions - #3820
Merged
Merged
Conversation
Let applications set bucket-wide default ReaderOptions once instead of passing them on every Download/NewReader call. When a read method is called with nil opts, a copy of the default is used in place of an empty ReaderOptions. Only performance-related fields may be defaulted (AllowParallelDownload, BufferSize, MaxConcurrency); setting BeforeRead returns an error, since it is a per-call concern. This lives entirely in the portable blob package and needs no driver changes. Alternative to the URL-parameter approach, per discussion on google#3818.
vangent
reviewed
Nov 2, 2026
| } | ||
| b.mu.Lock() | ||
| defer b.mu.Unlock() | ||
| cp := opts |
Contributor
There was a problem hiding this comment.
Nit: it should be OK to set b.defaultReaderOptions = &optshere, right?opts` is already a copy.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3820 +/- ##
==========================================
- Coverage 80.15% 80.14% -0.01%
==========================================
Files 104 104
Lines 12454 12464 +10
==========================================
+ Hits 9982 9989 +7
- Misses 2471 2474 +3
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
opts is a value parameter, so it is already a per-call copy; take its address directly instead of copying again.
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.
Implements the approach @vangent proposed in #3818, as an alternative to the URL-parameter PR #3819 (now closed).
What
Bucket.SetDefaultReaderOptions(ReaderOptions) errorlets an application set bucket-wide defaultReaderOptionsonce, instead of passing them on everyDownload/NewReader/NewRangeReadercall. When a read method is called withnilopts, a copy of the default is used in place of an emptyReaderOptions.How
defaultReaderOptions *ReaderOptionsfield toBucket(guarded by the existingb.mu).SetDefaultReaderOptionsstores a copy. Only performance-related fields may be defaulted; settingBeforeReadreturns anInvalidArgumenterror, since it's a per-call concern.readerOptionsOrDefaulthelper substitutes the default (a copy) whenopts == nil, applied inDownloadandnewRangeReader(the shared helper behindNewReader/NewRangeReader/ReadAll).This lives entirely in the portable
blobpackage and needs no driver changes — it just substitutes theReaderOptionsbefore the existing per-call plumbing (theAllowParallelDownloadgate and theBufferSize/MaxConcurrencyfields drivers already honor).Semantics
A
nilopts gets a copy of the default; a non-nil opts is used as-is (the default is not merged in), which avoids any unset-vs-zero ambiguity. Explicit per-call options therefore always win.Tests
TestSetDefaultReaderOptionscovers: theBeforeReadallowlist error; a default enabling the parallel path for a nil-optsDownload; part-size/concurrency defaults flowing to the driver; fallback to the reader with no default; and that an explicit opts does not inherit the default.go vet/gofmtclean; fullblob+ s3blob/gcsblob/azureblob suites pass (no driver changes).Follow-up
SetDefaultWriterOptions(with a smaller allowlist) is a natural follow-up.