Skip to content

HDDS-16392. parse Proto2Codec values from the CodecBuffer instead of through an InputStream - #11233

Open
ss77892 wants to merge 2 commits into
apache:masterfrom
ss77892:HDDS-16392
Open

HDDS-16392. parse Proto2Codec values from the CodecBuffer instead of through an InputStream#11233
ss77892 wants to merge 2 commits into
apache:masterfrom
ss77892:HDDS-16392

Conversation

@ss77892

@ss77892 ss77892 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

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.

…through an InputStream

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the patch! @ss77892 +1 LGTM

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Could we drop this comment? Proto3Codec does the same without one, and the Jira already records why.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for looking into it @chihsuan . I've removed the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants