fstree: never copy to io.Discard unless dealing with compression#4016
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4016 +/- ##
==========================================
+ Coverage 26.97% 26.99% +0.01%
==========================================
Files 684 684
Lines 46520 46538 +18
==========================================
+ Hits 12549 12563 +14
- Misses 32787 32789 +2
- Partials 1184 1186 +2 ☔ 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.
54ebd39 to
71faf77
Compare
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>
71faf77 to
543550e
Compare
This suggests compression is harmful, so it better be dropped. But that's subject to some subsequent PR.