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

cuvs-java: Rework the api to be Java 21 friendly #628

Open
wants to merge 13 commits into
base: branch-25.02
Choose a base branch
from

Conversation

ChrisHegarty
Copy link

@ChrisHegarty ChrisHegarty commented Jan 30, 2025

This change reworks the api to allow it to be used with Java 21. The implementation is moved to an internal package, compiled with JDK 22, and packaged as an mrjar. The benefit of this structure is that the api can be used in environments that compile to a minimum of Java 21, but run on more recent JDKs like 22 and 23 - which is exactly what Elasticsearch and Lucene do. In fact, a minimum compilation target of Java 21 is common, since 21, at the time of writing, is the most recent LTS Java release.

The most significant change is that the non-trivial api types are now, for the most part, interfaces. Instance can be created by one of the factory methods, which lookup an spi to find the implementation. If on a release greater than Java 21, then a functioning implementation is returned. Otherwise, a no-op implementation is returned. This is a reasonably standard way for a Java api to behave, and allows the developer to handle the case where the platform does not have a functioning implementation.

This change also refactors the native downcall method handles so that they are static final constants - which optimise better by the JVM. It's also the generally accepted pattern, where the handles are tied to the lifetime of class which effectively mediates access - by virtue of reachability.

Another thing that I added is the ability to programmatically set the temporary directory used for intermediate operations - this is important to how both Lucene and Elasticsearch work - since they commonly only have permission to write to certain parts of the disk.

Additionally,

  1. the error codes from native calls are plumbed in and checked. As well as cuvsGetLastErrorText.
  2. a state is added to any classes that hold a reference to native resources that could be released.
  3. a local arena is used for memory allocation only needed per downcall invocation, e.g. the return value.
  4. I moved the tests to be integration tests, since they need to run on the jar (rather than the exploded classes). They can be run by any of; mvn verify, or mvn integration-test, or mvn -Dit.test="*Hnsw*" verify
  5. I refactored the entry-points to the api to be static methods and added an spi layer. You can see the minimal impact on the tests.
  6. Move the native library out of the top-level directory in the jar and into an os/arch position in the META-INF.
  7. add service provider support for custom implementations.

Copy link

copy-pr-bot bot commented Jan 30, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cjnolet cjnolet added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Jan 30, 2025
@cjnolet
Copy link
Member

cjnolet commented Jan 30, 2025

/ok to test

@ChrisHegarty ChrisHegarty changed the title cuvs-java: Refactor method handle usage and separate out local areas from long held cuvs-java: Rework the api to only use Java 21 types Feb 1, 2025
@cjnolet
Copy link
Member

cjnolet commented Feb 1, 2025

/ok to test

@ChrisHegarty ChrisHegarty requested a review from a team as a code owner February 2, 2025 14:48
@cjnolet
Copy link
Member

cjnolet commented Feb 2, 2025

/ok to test

@ChrisHegarty ChrisHegarty changed the title cuvs-java: Rework the api to only use Java 21 types cuvs-java: Rework the api to be Java 21 friendly Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants