fstree: never copy to io.Discard unless dealing with compression#4016
fstree: never copy to io.Discard unless dealing with compression#4016roman-khimov wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4016 +/- ##
==========================================
- Coverage 27.79% 27.75% -0.04%
==========================================
Files 681 681
Lines 46797 46942 +145
==========================================
+ Hits 13006 13031 +25
- Misses 32553 32669 +116
- Partials 1238 1242 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors FSTree read/range-stream handling to avoid falling back to io.CopyN(io.Discard, ...) when skipping data for non-compressed objects, by switching internal readers to seek-capable wrappers.
Changes:
- Introduces seek-capable reader wrappers (
prefixedReadSeekCloser,limitedFileReader) and a zstdcompressedReader. - Changes internal object reading helpers to return
io.ReadSeekCloserto enable skipping viaSeek. - Updates payload prefix/range handling to use the new wrappers instead of
io.MultiReader+io.LimitReadercompositions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/local_object_storage/blobstor/fstree/util.go | Adds new reader wrapper types used to prefix/limit streams and handle compressed reads. |
| pkg/local_object_storage/blobstor/fstree/head.go | Switches internal read paths to return seek-capable readers and uses new prefix wrapper. |
| pkg/local_object_storage/blobstor/fstree/fstree.go | Updates range-shifting logic to use Seek and new limiting/prefix wrappers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -579,7 +579,7 @@ func (t *FSTree) readPayloadRange(addr oid.Address, off, ln uint64, getHdrBuf fu | |||
| return pldLen, stream, nil | |||
There was a problem hiding this comment.
True, but I don't want any additional wrappers. Current users are well known.
FSTree routinely creates io.MultiReader in many places and the probelm is that it does not and can not implement Seek(), so every time we're trying to get a range stream we're effectively reading and discarding everything which is not very productive. This patch introduces a new set of wrappers with Seek() implemented. These implementations are not complete, it's more of Skip() rather than Seek(), but that's the only thing we really need and this allows to reuse the same io.ReadSeekCloser everywhere (implemented natively by os.File). Signed-off-by: Roman Khimov <roman@nspcc.ru>
54ebd39 to
71faf77
Compare
This suggests compression is harmful, so it better be dropped. But that's subject to some subsequent PR.