Skip to content
New issue

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

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

Already on GitHub? # to your account

SOLR-17562: Unify JAX-RS "raw response" endpoints #3032

Merged
merged 8 commits into from
Jan 19, 2025

Conversation

gerlowskija
Copy link
Contributor

@gerlowskija gerlowskija commented Jan 14, 2025

https://issues.apache.org/jira/browse/SOLR-17562

Description

Several v2 APIs return raw files or streams of data, including: ZooKeeperReadAPI, NodeFileStore, and CoreReplication.fetchFile.

But the APIs vary slightly in how they support this: ZooKeeperReadAPI uses the deprecated "ContentStream" with "RawResponseWriter", NodeFileStore directly attaches a "SolrCore.RawWriter" to the underlying SolrQueryResponse, and CoreReplication follows the JAX-RS best practice of using the "StreamingOutput" interface.

The biggest hurdle to aligning on a single approach is modifying the templates used by our SolrJ code generation to handle the new approach (and "big stream of data" style responses in general).

Solution

This PR tackles this by introducing a new SolrResponse implementation, InputStreamResponse, to wrap the NamedList produced by the existing InputStreamResponseParser. (InputStreamResponseParser creates a NamedList with two entries, "responseStatus" (an int) and "stream" (an InputStream)). The new SolrResponse type is used as the response type by our code-gen template for any "raw" responses annotated with a "rawOutput" tag introduced by this PR.

Docs are added in dev-docs/v2-api-conventions.adoc to highlight this setup.

NOTE: this PR provides a unified approach for "raw" API responses (e.g. index files returned by replication APIs, blobs stored in the filestore, etc.). Callers of these APIs essentially get a glorified InputStream to work with on the client side. The PR doesn't aim to handle other APIs that stream more structured data, e.g. the doc-stream returned by /export. We can likely do better than a "glorified InputStream" in these cases, but this PR makes no attempt to provide that.

Tests

New unit tests in InputStreamResponseTest. Rewrites ZookeeperReadAPITest to use generated client for ZK API calls. Existing tests for the ZK and replication APIs continue to pass.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation

Creates InputStreamResponse and corresponding tests to wrap the
NamedList produced by InputStreamResponseParser.  Modifies the codegen
mustache template to use this response type for any v2 APIs that are
tagged as producing 'rawOutput'.
This also switches the endpoint-definitions to be codegen compatible
using the new "rawOutput" property.
@github-actions github-actions bot added documentation Improvements or additions to documentation client:solrj tool:build tests cat:api labels Jan 14, 2025
Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

Didn't look too closely but I'm glad to see harmonization on a single approach. And there needed to be some constants for "stream" that you finally added.
Thanks.

inputStream.transferTo(baos);
return baos.toString(Charset.defaultCharset());
} finally {
ObjectReleaseTracker.release(inputStream);
Copy link
Contributor

Choose a reason for hiding this comment

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

I question that it's this method's job to use ObjectReleaseTracker

public class InputStreamResponseParser extends ResponseParser {

public static String STREAM_KEY = "stream";
public static String HTTP_STATUS_KEY = "responseStatus";
Copy link
Contributor

Choose a reason for hiding this comment

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

would httpStatus be a better name? (assuming it's 200 not 0 when things are good)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that "httpStatus" is much better name-wise, but changing the name of the key would break any SolrJ users that make use of InputStreamResponseParser.

We could tweak the 9.x backport of this PR to make the status-code available under both 'responseStatus' and 'httpStatus' (and "deprecate" the former). But that gets pretty far afield from the main goal of this PR, so I might skip it for reasons of scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay; not worth changing the name over.

public class InputStreamResponseParser extends ResponseParser {

public static String STREAM_KEY = "stream";
public static String HTTP_STATUS_KEY = "responseStatus";
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay; not worth changing the name over.

@gerlowskija gerlowskija merged commit 0937bb5 into apache:main Jan 19, 2025
4 checks passed
@gerlowskija gerlowskija deleted the SOLR-17562-unify-jaxrs-streaming branch January 19, 2025 15:25
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cat:api client:solrj documentation Improvements or additions to documentation tests tool:build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants