Skip to content

Better bytes skipping in FsBlobContainer #54333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

tlrx
Copy link
Member

@tlrx tlrx commented Mar 27, 2020

This pull request is addressing a // NORELEASE tag in FsBlobContainer where the InputStream opened by the readBlob(String) does not efficiently skip bytes under hood.

This method uses the Files.newInputStream(resolvedPath) which uses the Files.newByteChannel() which returns a SeekableByteChannel instance that allows to efficiently skip bytes but sadly this channel is then wrapped using Channels.newInputStream() into a ChannelInputStream instance that delegates the skip() method execution to the default InputStream implementation which reads bytes.

This pull request changes the implementation of the readBlob(String, long, long) to use a more effective manner to skip bytes and adds a test to verify that only the required number of bytes are read. It also swaps how the buffered and limit streams are combined so that the underlying stream is limited first and the buffered stream will not try to buffer more bytes than necessary.

@tlrx tlrx added >enhancement :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs labels Mar 27, 2020
@tlrx tlrx requested a review from DaveCTurner March 27, 2020 12:34
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (:Distributed/Snapshot/Restore)

@tlrx
Copy link
Member Author

tlrx commented Mar 27, 2020

@elasticmachine update branch

@tlrx
Copy link
Member Author

tlrx commented Mar 27, 2020

@elasticmachine update branch

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Taught me about a whole other layer of mocking that I didn't know about yet :)

@tlrx tlrx merged commit e20f16e into elastic:feature/searchable-snapshots Mar 27, 2020
@tlrx tlrx deleted the fsblobcontainer-bytes-skip branch March 27, 2020 15:37
@tlrx
Copy link
Member Author

tlrx commented Mar 27, 2020

Thanks David

Taught me about a whole other layer of mocking that I didn't know about yet :)

Like an onion: the more you peel it the more you cry :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants