Skip to content

Add libzstd-jna with the HDF5 Zstandard filter (id 32015) - #1629

Merged
lesserwhirls merged 2 commits into
Unidata:maint-5.xfrom
djkwon26s:zstd-filter
Nov 25, 2026
Merged

lesserwhirls merged 2 commits into
Unidata:maint-5.xfrom
djkwon26s:zstd-filter

Conversation

@djkwon26s

Copy link
Copy Markdown
Contributor

Thank you for setting up libzstd-native so quickly. Here is the libzstd-jna part 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-jna subproject, following libblosc2-jna:

  • LibZstd: JNA direct mapping of the five zstd functions needed for decoding. The library is loaded from libzstd-native first and from the system second, the same way as LibBlosc2. JNA maps the name zstd to libzstd.so / libzstd.dylib and to zstd.dll, which matches the files in libzstd-native, so no platform special case is needed.
  • LibZstd.decode(byte[]) follows the decompression branch of H5Zzstd.c (hdf5_plugins and netCDF-C): each HDF5 chunk is one zstd frame; the output size comes from ZSTD_findDecompressedSize, then ZSTD_decompress. Bad input fails with IOException: 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 in META-INF/services/ucar.nc2.filter.FilterProvider with id 32015 and name zstd. 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 existing Shuffle filter.
  • size_t is mapped to long; class initialization fails with a clear message on a 32-bit JVM (all libzstd-native platforms are 64-bit).

Other changes:

  • settings.gradle.kts: include :libzstd-jna.
  • ncj-base-conventions.gradle.kts: add :libzstd-jna to 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.md says how they were made (netCDF-C 4.9.3, HDF5 1.14.6, zstd 1.5.7).

TestLibZstd:

  • one frame and two concatenated frames, compared with expected bytes
  • rejects a frame without a recorded size, truncated frames, a corrupted frame, and non-zstd input

TestZstdFilter:

  • provider lookup by id and by name
  • full read of time (rank 1, zstd), temp (rank 3 float, shuffle + zstd) and count (rank 2 int, zstd), compared with an uncompressed copy
  • subset read across partial edge chunks
  • 16 concurrent reads on 4 threads

./gradlew spotlessCheck :libzstd-jna:testWithJdk25 passes 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

  • I did not add libzstd-jna / libzstd-native to uicdm or the ncIdv uber jar (where libblosc2-native is listed), since that is a packaging decision. I can add them here if you like.
  • :libzstd-native is not in the public artifacts list in ncj-base-conventions.gradle.kts, while :libaec-native and :libblosc2-native are. I left that as is in case it is intentional.

🤖 Generated with Claude Code

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>
@lesserwhirls

Copy link
Copy Markdown
Member

Overall this looks good and is a welcome addition to filter support (read) in netCDF-Java. In terms of the questions:

I did not add libzstd-jna / libzstd-native to uicdm or the ncIdv uber jar (where libblosc2-native is listed), since that is a packaging decision. I can add them here if you like.

For sure these should be added to uicdm (that change can be added to this PR if you don't mind - thank you!), but I'll need to ask the lead developer of the IDV if he would like them added to ncIdv.

:libzstd-native is not in the public artifacts list in ncj-base-conventions.gradle.kts, while :libaec-native and :libblosc2-native are. I left that as is in case it is intentional.

I was waiting for libzstd-jna before adding libzstd-native to the list. That change can be added to this PR if you don't mind (thank you!).

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>
@djkwon26s

Copy link
Copy Markdown
Contributor Author

Thank you for the review! I've added libzstd-jna and libzstd-native to uicdm, and :libzstd-native to the public artifacts list.

@lesserwhirls
lesserwhirls merged commit 523073d into Unidata:maint-5.x Nov 25, 2026
22 of 32 checks passed
@rschmunk

Copy link
Copy Markdown
Contributor

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants