Skip to content
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

SOLR-17302: Convert remaining filestore APIs to JAX-RS #2532

Merged

Conversation

gerlowskija
Copy link
Contributor

@gerlowskija gerlowskija commented Jun 24, 2024

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

Description

PR #2470 converted a few file store APIs (those available under the /api/cluster path) to JAX-RS. But the PR didn't touch several other APIs, which still needed JAX-RS conversion, including:

  • Fetch filestore file
  • Fetch filestore metadata
  • Delete "local" filestore entry (internal API)

Solution

This PR migrates the remaining filestore APIs to JAX-RS. This migration is largely done "as-is", avoiding any cosmetic changes to the APIs. IMO cosmetic improvements are much needed here (see SOLR-17302 for more details), but I've skipped those here because despite being "experimental" v2 APIs, these APIs are the only way to access Solr's filestore, so we might need to be a little more careful about changes. I've started a discussion around this in SOLR-17302 for a hopefully wider audience to chime in.

One exception to this is the internal "local-delete" API, which is used internally by Solr. It's not documented, nor does it have any use from an end-user perspective, so changing this API seemed a little more clear-cut. This functionality can now be triggered via a localDelete parameter on the existing filestore delete API (e.g. DELETE /cluster/files/somePath.txt?localDelete=true)

We utilize "RawResponseWriter" for serializing the raw file data when fetching filestore files, to match the approach taken by the existing ZooKeeperReadAPI code.

Tests

Existing filestore tests continue to pass, as this is mostly a refactor. Additional unit tests in V2ApiUtils and elsewhere.

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)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.

One small step in aligning all filestore APIs on the '/cluster/files/'
HTTP path.
Plausibly works on the server-side, though the generated SolrRequest
implementation will almost surely NOT work.

Finally, this commit changes the path for these APIs to be
/cluster/files (instead of the previously used `/node/files`).  I need
to think through the backcompat implications of this a bit more
thoroughly.  I probably need a version of these APIs also available at
the original path.
TestDistribFileStore passes; ship it.
Copy link
Contributor

@epugh epugh left a comment

Choose a reason for hiding this comment

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

Great work here moving things forward... Out of curisoity, do the existing tests then cover this all with no change? amazing?

/**
* V2 APIs for fetching filestore files, syncing them across nodes, or fetching related metadata.
*
* @see MergeIndexesRequestBody
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this do the magic linking? the @see?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not doing anything "magic" for our code-generation, etc. - it's just something the Javadoc syntax supports.

And in this case, it's there by copy/paste error 😛 Thanks for pointing it out haha!

@@ -109,7 +108,7 @@ enum FileType {
METADATA
}

interface FileDetails extends MapWriter {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this!

this.fileStore = fileStore;
}

// TODO - this single "get" operation actually supports several different chunks of functionality:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish we had JIRA's that referenced the "Todo" work...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nice. I think the lack of a JIRA reference in this case reflects my own uncertainty about how to proceed.

In theory SOLR-17302 is already sortof meant to cover this type of "cosmetic improvement" change. That's how many of our v2 tickets are setup - to cover both JAX-RS conversion and "cosmetic changes" all in one.

But in practice I'm not sure whether it's safe/responsible to modify the appearance of these particular v2 endpoints. They're technically "experimental", but they're the only way to access the filestore - there's no v1 equivalent that we can recommend to folks.

I'm going to start a discussion on SOLR-17302 about this, which will hopefully draw some more eyes and get us some clarity on how to proceed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually - small correction - apparently when I wrote up SOLR-17302 I worded it in such a way that it only covers migration to JAX-RS.

So there's no ticket (yet) for breaking up this API into more manageable chunks. I'll file a separate ticket for this and reference it here (and in the code) when its ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (path == null) {
path = "";
}
FileStore.FileType typ = fileStore.getType(path, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

"type"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something that carried over from the existing code, and I'm leery of getting sucked into larger improvements to that code. There's a lot that could be done there.
But I can change it since it's a small modification.

} else { // User wants to get the "raw" file
// TODO Should we be trying to json-ify otherwise "raw" files in this way? It seems like a
// pretty sketchy idea, esp. for code with very little test coverage. Consider removing
final var pathCopy2 = path;
Copy link
Contributor

Choose a reason for hiding this comment

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

pathCopy2???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something that carried over from the existing code, and I'm leery of getting sucked into larger improvements to that code. There's a lot that could be done there.
But I can change it since it's a small modification.

req.setParams(SolrParams.wrapDefaults(solrParams, req.getParams()));
rsp.add(
CONTENT,
(SolrCore.RawWriter)
Copy link
Contributor

Choose a reason for hiding this comment

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

wow!

} else if (obj != null && (obj instanceof SolrCore.RawWriter)) {
final var rawWriter = (SolrCore.RawWriter) obj;
rawWriter.write(out);
if (rawWriter instanceof Closeable) ((Closeable) rawWriter).close();
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a { and }?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something that carried over from existing code.

I've agreed to a few variable renames above in code that preexists this PR, but I'll probably skip this change. IMO this code could use lots of reformatting/restructuring attention, but we need to draw the line somewhere.

@gerlowskija
Copy link
Contributor Author

Looks like PackageToolTest is still failing with this change, will need to figure that out prior to merging...

@gerlowskija
Copy link
Contributor Author

The PackageToolTest failure actually surfaced an interesting little v2 API bug - the v2 authz code wasn't properly detecting when a request had been authenticated as the special PKI principal '$'. This PR now fixes that bug as well, using code similar to what we use in the v1 case. With this fixed I'm marking the PR as "ready for review"!

@gerlowskija gerlowskija marked this pull request as ready for review June 26, 2024 14:52
@epugh
Copy link
Contributor

epugh commented Jun 26, 2024

The PackageToolTest failure actually surfaced an interesting little v2 API bug - the v2 authz code wasn't properly detecting when a request had been authenticated as the special PKI principal '$'. This PR now fixes that bug as well, using code similar to what we use in the v1 case. With this fixed I'm marking the PR as "ready for review"!

Gnarly little fix there!

Copy link
Contributor

@epugh epugh left a comment

Choose a reason for hiding this comment

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

Some great work here!

@gerlowskija gerlowskija merged commit d0aad69 into apache:main Jul 1, 2024
4 checks passed
@gerlowskija gerlowskija deleted the SOLR-17302-convert-local-delete-to-jax-rs branch July 1, 2024 14:48
gerlowskija added a commit that referenced this pull request Jul 1, 2024
This migrates the remainder of Solr's "filestore" APIs to the JAX-RS framework.
No cosmetic changes were made in the process, with the small exception of
folding the internal "local delete" functionality into the existing delete API using
a new `localDelete` boolean query param.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants