Commit graph

16 commits

Author SHA1 Message Date
Simon Cooper
4aa33409a5
Backport systemd unreadable library path fix (#109419)
* Guard systemd library lookup from unreadable directories (#108931)

When scanning the library path we may come across directories that are
unreadable. If that happens, the recursive walk of the library path
directories will throw a fatal IOException. This commit guards the walk
of the library paths to first check for readability of each directory we
are about to traverse.

---------

Co-authored-by: Ryan Ernst <ryan@iernst.net>
2024-06-06 13:05:13 +01:00
Andrew Wilkins
733620d66a
nativeaccess: try to load all located libsystemds (#108238) (#108428)
Linux systems with multiarch (e.g. i386 & x86_64) libraries
may have libsystemd.0 in two subdirectories of an entry in
java.library.path. For example, libsystemd.so.0 may be found
in both /usr/lib/i386-linux-gnu and /usr/lib/x86_64-linux-gnu.

Instead of attempting to load any library found, attempt all
and stop as soon as one is successfully loaded.
2024-05-08 15:02:15 -04:00
Ryan Ernst
dacc0dbce1
Use direct method mapping for zstd (#108172) (#108205)
JNA supports two types of mapping to native methods, proxying and direct
method mapping. Proxying is nicer for unit testing, but unfortunately
the proxied methods are lazily loaded. NativeAccess expects that methods
are linked during static init, before SecurityManager is initialized.
For any native methods called after security manager init, the proxied
method will fail.

This commit changes the zstd bindings to use direct method mapping so
that calling zstd methods does not fail when using JNA (pre Java 21).

closes #107504
closes #107770
2024-05-02 12:51:17 -04:00
Chris Hegarty
6b52d7837b
Add an optimised int8 vector distance function for aarch64. (#106133)
This commit adds an optimised int8 vector distance implementation for aarch64. Additional platforms like, say, x64, will be added as a follow-up.

The vector distance implementation outperforms Lucene's Pamana Vector implementation for binary comparisons by approx 5x (depending on the number of dimensions). It does so by means of compiler intrinsics built into a separate native library and link by Panama's FFI. Comparisons are performed on off-heap mmap'ed vector data.

The implementation is currently only used during merging of scalar quantized segments, through a custom format ES814HnswScalarQuantizedVectorsFormat, but its usage will likely be expanded over time.

Co-authored-by: Benjamin Trent <ben.w.trent@gmail.com>
Co-authored-by: Lorenzo Dematté <lorenzo.dematte@elastic.co>
Co-authored-by: Mark Vieira <portugee@gmail.com>
Co-authored-by: Ryan Ernst <ryan@iernst.net>
2024-04-12 08:44:21 +01:00
Ryan Ernst
96230f7a7d
Use CloseableByteBuffer in compress/decompress signatures (#106724)
CloseableByteBuffer is backed by native memory segments, but the
interfaces for compress and decompress methods of zstd take ByteBuffer.
Although both Jna and the Jdk can deal with turning the native
ByteBuffer back into an address to pass to the native method, the jdk
may have a more significant cost to that action.

This commit changes the signature of compress and decompress to take in
CloseableByteBuffer so that each implementation can do its own
unwrapping to get the appropriate native address.

relates #103374
2024-03-25 14:30:27 -04:00
Ryan Ernst
2196576aed
Use confined arena for CloseableByteBuffer (#106723)
The jdk implementation of CloseableByteBuffer currently uses a shared
arena. The assumption was that a buffer might be shared across threads.
However, in practice for compression/decompression that is not true, and
the shared arena has a noticeable impact on deallocation when the buffer
is closed. This commit switches to a confined arena, limtting buffer
creation and compress/decompress calls to a single thread.

relates #103374
2024-03-25 13:26:45 -04:00
Ryan Ernst
55c3357c81
Move common mrjar forbidden apis configuration to plugin (#106385)
Since mrjars may use preview apis, forbidden apis must know about any
preview apis from the jdk. However, we do not run forbidden apis with
the preview enabled flag, nor in a separate jvm, so it does not know
about these classes. Thus we ignore missing classes on source sets added
by the mrjar plugin.

This commit configures all sourcesets added by mrjar plugin to ignore
forbidden apis missing classes.
2024-03-19 16:40:52 -04:00
Ryan Ernst
444866aec9
Set explicit directory and file permissions on native libraries (#106505)
The distributions already have correct permissions set on native
libraries copied to them. However, the build itself to extract the
native libs relies on the upstream file permissions. This commit sets
explicit permissions on the copy task which extracts native libraries.
2024-03-19 15:51:57 -04:00
Ryan Ernst
6731538bbe
Different string allocation on jdk 21/22 (#106492)
Similar to https://github.com/elastic/elasticsearch/pull/106360, the
methods for allocating a native string changed between Java 21 and 22.
This commit adds another util method to handle the differences and uses
it in the jdk systemd impl.
2024-03-19 13:09:18 -04:00
Ryan Ernst
1d7a0159d3
Support jdk22 in zstd bindings (#106360)
The foreign memory API changed between Java 21 and 22 in how to decode a
string from native memory. This commit adds an multi-release class to
handle the two different methods on MemorySegment to decode a string.
2024-03-14 10:30:14 -07:00
Rene Groeschke
0f9ebf268f
Mute ZstdTests (#106348)
failing on jdk22
2024-03-14 10:56:10 +01:00
Ryan Ernst
405b88b882
Add zstd to native access (#105715)
This commit makes zstd compression available to Elasticsearch. The
library is pulled in through maven in jar files for each platform, then
bundled in a new platform directory under lib. Access to the zstd
compression/decompression is through NativeAccess.
2024-03-13 09:45:12 -07:00
Ryan Ernst
10dcb8e8bd
Add systemd native access (#106151)
This commit moves systemd access to the NativeAccess lib.

relates #104876
2024-03-12 07:35:02 -07:00
Ryan Ernst
83585315fe
Only apply build to direct libs (#106101)
Sometimes libs have subprojects that may not be java projects. This commit adjusts the shared
configuration for libs to only affect direct subprojects of :lib.
2024-03-08 13:48:26 -08:00
Ryan Ernst
dd51f6b187
Add classpath based SPI for jna native provider (#105320)
Native lib provider is normally run modular, but since tests run on the
classpath it also needs to work with old style SPI.
2024-02-08 17:31:57 -08:00
Ryan Ernst
6375e9f443
Add native access library (#105100)
Elasticsearch requires access to some native functions. Historically
this has been achieved with the JNA library. However, JNA is a
complicated, magical library, and has caused various problems booting
Elasticsearch over the years. The new Java Foreign Function and Memory
API allows access to call native functions directly from Java. It also
has the advantage of tight integration with hotspot which can improve
performance of these functions (though performance of Elasticsearch's
native calls has never been much of an issue since they are mostly at
boot time).

This commit adds a new native lib that is internal to Elasticsearch. It
is built to use the foreign function api starting with Java 21, and
continue using JNA with Java versions below that.

Only one function, checking whether Elasticsearch is running as root, is
migrated. Future changes will migrate other native functions.
2024-02-07 18:27:09 -05:00