Repository navigation
Add libzstd-jna with the HDF5 Zstandard filter (id 32015) - #1629
Conversation
New JNA subproject on top of libzstd-native. LibZstd.decode follows H5Zzstd.c: one zstd frame per chunk, sized with ZSTD_findDecompressedSize and decoded with ZSTD_decompress. ZstdFilter is registered as a FilterProvider for id 32015 and name "zstd". Refs Unidata#1620 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Overall this looks good and is a welcome addition to filter support (read) in netCDF-Java. In terms of the questions:
For sure these should be added to
I was waiting for |
As requested in review: uicdm gets libzstd-jna and libzstd-native at runtime, and :libzstd-native joins the public artifacts list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for the review! I've added |
|
FWIW: Panoply 5.10.4 was released yesterday and includes the libzstd-native native code. (Which also meant I had to update my build process to codesign that native code, too, so that the Mac version of Panoply would pass notarization.) |
Thank you for setting up
libzstd-nativeso quickly. Here is thelibzstd-jnapart on top of it.Part of #1620 (HDF5 Zstandard filter, id 32015). With this PR, all three parts of #1620 are in.
Summary
Adds a new
libzstd-jnasubproject, followinglibblosc2-jna:LibZstd: JNA direct mapping of the five zstd functions needed for decoding. The library is loaded fromlibzstd-nativefirst and from the system second, the same way asLibBlosc2. JNA maps the namezstdtolibzstd.so/libzstd.dyliband tozstd.dll, which matches the files inlibzstd-native, so no platform special case is needed.LibZstd.decode(byte[])follows the decompression branch ofH5Zzstd.c(hdf5_plugins and netCDF-C): each HDF5 chunk is one zstd frame; the output size comes fromZSTD_findDecompressedSize, thenZSTD_decompress. Bad input fails withIOException: invalid or truncated data, a frame without a recorded size (the HDF5 filter also needs it), or a size mismatch after decoding.ZstdFilter+ZstdFilter.Provider, registered inMETA-INF/services/ucar.nc2.filter.FilterProviderwith id 32015 and namezstd. Decode only. The only filter parameter (cd_values[0]) is the compression level, which decoding does not need. Shuffle, when used, is a separate filter in the pipeline and is handled by the existingShufflefilter.size_tis mapped tolong; class initialization fails with a clear message on a 32-bit JVM (alllibzstd-nativeplatforms are 64-bit).Other changes:
settings.gradle.kts: include:libzstd-jna.ncj-base-conventions.gradle.kts: add:libzstd-jnato the public artifacts..github/workflows/test-native-compression-zstd.yml: copy of the blosc2 native workflow for the zstd modules.UsingNetcdfJava.md: one line in the zstd section.Tests
Test files are small (2.5 KB to 38 KB);
src/test/data/README.mdsays how they were made (netCDF-C 4.9.3, HDF5 1.14.6, zstd 1.5.7).TestLibZstd:TestZstdFilter:time(rank 1, zstd),temp(rank 3 float, shuffle + zstd) andcount(rank 2 int, zstd), compared with an uncompressed copy./gradlew spotlessCheck :libzstd-jna:testWithJdk25passes locally (Windows x86_64). I did not have JDK 8 or 11 toolchains locally.I also read 4 files from our project with this module (shuffle + zstd, written with netCDF-C/HDF5 by our MPI compressor) and compared every variable with the uncompressed originals: about 1.39 billion values, all bit-identical.
Questions
libzstd-jna/libzstd-nativetouicdmor thencIdvuber jar (wherelibblosc2-nativeis listed), since that is a packaging decision. I can add them here if you like.:libzstd-nativeis not in the public artifacts list inncj-base-conventions.gradle.kts, while:libaec-nativeand:libblosc2-nativeare. I left that as is in case it is intentional.🤖 Generated with Claude Code