HDDS-16392. parse Proto2Codec values from the CodecBuffer instead of through an InputStream - #11233
Open
ss77892 wants to merge 2 commits into
Open
HDDS-16392. parse Proto2Codec values from the CodecBuffer instead of through an InputStream#11233ss77892 wants to merge 2 commits into
ss77892 wants to merge 2 commits into
Conversation
…through an InputStream Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
chihsuan
reviewed
Sep 12, 2026
| throws CodecException { | ||
| final InputStream in = buffer.getInputStream(); | ||
| // Parse the buffer directly, as Proto3Codec does: parsing through an InputStream makes protobuf | ||
| // allocate a 4 KB decoding buffer per call, on values which are typically a few hundred bytes. |
Contributor
There was a problem hiding this comment.
nit: Could we drop this comment? Proto3Codec does the same without one, and the Jira already records why.
Contributor
Author
There was a problem hiding this comment.
Thank you for looking into it @chihsuan . I've removed the comment.
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.
What changes were proposed in this pull request?
Proto2Codec.fromCodecBuffer parsed the value through buffer.getInputStream(). Protobuf allocates a 4 KB decoding buffer for every parse that goes through an InputStream. Most values stored in RocksDB tables are only a few hundred bytes, so the allocation is much larger than the value itself and it happens on every table get and every iterator step.
This change parses the message directly from buffer.asReadOnlyByteBuffer(), the same way Proto3Codec already does. The InputStream and the IOUtils.closeQuietly call are removed. Parse failures are still reported as CodecException with the InvalidProtocolBufferException as the cause.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-16392
How was this patch tested?
new UTs has been added.
CodecTestUtil.runTest now also round trips each value through a direct CodecBuffer, which is the buffer type used by table get and iterators. This covers all codecs that use runTest.