Skip to content

Initial commit to refactor the OutputCodec to support a Writer per OutputStream#5606

Merged
dlvenable merged 3 commits into
opensearch-project:mainfrom
dlvenable:output-codec-refactor
Apr 28, 2025
Merged

Initial commit to refactor the OutputCodec to support a Writer per OutputStream#5606
dlvenable merged 3 commits into
opensearch-project:mainfrom
dlvenable:output-codec-refactor

Conversation

@dlvenable
Copy link
Copy Markdown
Member

Description

The OutputCodec implementations have members that are often bound to a specific OutputStream. This prevents them from being thread-safe and may also hide other issues if shared across multiple OutputStreams. In particular, this is presenting visible bugs when used with the new size estimation API.

See this comment for some context: #5593 (comment)

The change provided is to create a single OutputCodec.Writer for each OutputStream. This will ensure that the members used are bound to the OutputContext.

This change adds partial support to get the work going. It specifically has these changes:

  • Adds the new APIs for OutputCodec.
  • Deprecates the old APIs.
  • Adds a default implementation that mimics the corresponding behavior.
  • Implements the new API in JsonOutputCodec.
  • Retains support for the old APIs in JsonOutputCodec.

Issues Resolved

N/A

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…s bound to a specific OutputStream. This supports backward compatibility with the existing APIs and an update to the JsonOutputCodec to start the migration.

Signed-off-by: David Venable <dlv@amazon.com>
private JsonWriter(final OutputStream outputStream, final OutputCodecContext codecContext) throws IOException {
this.outputStream = outputStream;
this.codecContext = codecContext;
generator = JSON_FACTORY.createGenerator(outputStream, JsonEncoding.UTF8);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

getEstimatedSize() is called millions of times. Is it a good idea to create a new generator each time?

…or NdjsonOutputCodec.

Signed-off-by: David Venable <dlv@amazon.com>
kkondaka
kkondaka previously approved these changes Apr 25, 2025
…ault createWriter implementation in OutputCodec.

Signed-off-by: David Venable <dlv@amazon.com>
@dlvenable dlvenable marked this pull request as ready for review April 28, 2025 12:02
@dlvenable dlvenable merged commit bc4039d into opensearch-project:main Apr 28, 2025
45 of 47 checks passed
@dlvenable dlvenable deleted the output-codec-refactor branch May 1, 2026 21:48
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.

3 participants