Skip to content

fix(conf): auto-detect native libs in jlink runtime#6493

Merged
bluestreak01 merged 4 commits intomasterfrom
jh_auto_detect_lib_dir
Jan 5, 2026
Merged

fix(conf): auto-detect native libs in jlink runtime#6493
bluestreak01 merged 4 commits intomasterfrom
jh_auto_detect_lib_dir

Conversation

@jerrinot
Copy link
Copy Markdown
Contributor

@jerrinot jerrinot commented Dec 3, 2025

Improvements for native library loading:

  • Auto-detect native libraries in jlink-ed runtime images
  • Uses java.home to locate a directory with native libs
  • Only activates when running from jrt: protocol (jlink runtime)
  • Eliminates the need for -Dquestdb.libs.dir in a start script

Improvements for native library loading:
 - Auto-detect native libraries in jlink-ed runtime images
 - Uses java.home to locate a directory with native libs
 - Only activates when running from jrt: protocol (jlink runtime)
 - Eliminates the need for -Dquestdb.libs.dir in a start script
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 3, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Added a new public method Os.getNativeLibsDir(String libName) that determines the directory for native library loading, supporting explicit system property configuration and JLink runtime detection. Introduced a helper method isJlinkRuntime() to identify JLink environments and integrated the new logic into the library detection flow.

Changes

Cohort / File(s) Summary
Native library directory detection
core/src/main/java/io/questdb/std/Os.java
Added public method getNativeLibsDir(String libName) to determine native library directory, preferring questdb.libs.dir system property or resolving library path in JLink runtime. Added helper method isJlinkRuntime() for JLink detection. Updated library loading flow to use new method. Added imports for URL and CodeSource classes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the new getNativeLibsDir() logic for correctness in system property handling and JLink detection
  • Verify the isJlinkRuntime() helper correctly identifies JLink environments via CodeSource protocol inspection
  • Validate integration with tryLoadFromDistribution() and existing library loading behavior
  • Confirm null-safety and proper handling of edge cases when native library directory is unavailable

Suggested reviewers

  • bluestreak01

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: auto-detecting native libraries in jlink runtime, which directly aligns with the primary modification adding getNativeLibsDir() and isJlinkRuntime() methods.
Description check ✅ Passed The description is directly related to the changeset, explaining the improvements for native library loading, jlink runtime detection, and the use of java.home for library location discovery.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jerrinot
Copy link
Copy Markdown
Contributor Author

jerrinot commented Dec 3, 2025

@coderabbitai dear 🐰 , please review this little piggie.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 3, 2025

@jerrinot, I'll be happy to review this PR! 🐰 Let me take a look at the changes for auto-detecting native libraries in jlink runtime images.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
core/src/main/java/io/questdb/std/Os.java (3)

276-308: Add Javadoc and extract property name constant for public API clarity

The flow is correct and robust—it prefers explicit questdb.libs.dir when set, only attempts $java.home/lib/<libName> in jrt-based runtimes, and cleanly returns null to trigger fallback extraction. Two improvements would enhance maintainability:

  1. Add Javadoc – The public method lacks documentation explaining when it returns non-null, that null triggers embedded JAR libs fallback, and that libName is only used for auto-detection.

  2. Extract property constant – The hard-coded "questdb.libs.dir" string appears in three places (Os.java line 279, questdb.sh line 282, docker-entrypoint.sh line 12) and must stay synchronized. Define private static final String LIBS_DIR_PROP = "questdb.libs.dir"; to reduce drift risk.


266-274: Consider clarifying the method's actual scope: isJlinkRuntime() detects modular jrt: image runtimes in general, not exclusively custom jlink distributions. Stock JDK 9+ also uses the jrt: protocol.

Renaming to isJrtImageRuntime() or expanding the method comment to clarify this detects any modular image (stock JDK or custom jlink) would improve clarity. The implementation is safe—multiple validation checks ensure graceful fallback if assumptions don't hold—but the current name may mislead maintainers about its actual scope.


310-326: tryLoadFromDistribution behavior and partial‑load scenarios

The distribution loading helper is generally solid:

  • Respects the new getNativeLibsDir contract (returns early when null).
  • Uses absolute paths via Paths.get(libsDir, ...) for both C++ and Rust libs.
  • On any failure, logs once to System.err and returns false, letting the existing JAR‑based fallback run.

One subtle edge case to be aware of: if the C++ lib loads successfully from the distribution directory but the Rust lib fails, you'll:

  1. Have C++ already loaded from the distribution path.
  2. Fall back and attempt to load the same C++ library again from a temp file extracted from the JAR.

Per the JDK's Runtime.loadLibrary semantics, repeated loads of the same native library name in the same classloader are ignored, so this should be harmless in practice. Still, behavior here is a little non‑obvious.

If you want to tighten this up, one option would be:

  • First verify that both expected library files exist under libsDir (for the jlink case you already check the C++ lib in getNativeLibsDir; you could extend that check or add a parallel existence check for the Rust lib here) before calling System.load at all. That would avoid "partially loaded from distribution, then falling back" scenarios.

Not required for correctness, but would make failure modes and logging slightly cleaner.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41746c3 and 072e55a.

📒 Files selected for processing (1)
  • core/src/main/java/io/questdb/std/Os.java (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (36)
  • GitHub Check: New pull request (Hosted Running tests on windows-other-2)
  • GitHub Check: New pull request (Hosted Running tests on windows-other-1)
  • GitHub Check: New pull request (Hosted Running tests on windows-pgwire)
  • GitHub Check: New pull request (Hosted Running tests on windows-cairo-2)
  • GitHub Check: New pull request (Hosted Running tests on windows-cairo-1)
  • GitHub Check: New pull request (Hosted Running tests on windows-fuzz2)
  • GitHub Check: New pull request (Hosted Running tests on windows-fuzz1)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-other)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-pgwire)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-sub)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-sub)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-base)
  • GitHub Check: New pull request (Hosted Running tests on mac-other)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-root)
  • GitHub Check: New pull request (Hosted Running tests on mac-pgwire)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz2)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo-fuzz)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz1)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-sub)
  • GitHub Check: New pull request (Hosted Running tests on mac-griffin)
  • GitHub Check: New pull request (Rust Test and Lint on linux-jdk17)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x86-graal)
  • GitHub Check: New pull request (Trigger Enterprise CI Trigger Enterprise Pipeline)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-root)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-arm64)
  • GitHub Check: New pull request (Check Changes Check changes)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (3)
core/src/main/java/io/questdb/std/Os.java (3)

32-32: Nullability import use is appropriate

Using @Nullable for the new public method’s return improves the contract clarity for callers and matches how null is used to signal “fallback to JAR extraction”. No issues here.


39-42: New imports for URL/CodeSource are correct and scoped

The additional imports (URL, CodeSource) are the right primitives for runtime image detection, and you’ve avoided importing java.nio.file.Path to keep it distinct from io.questdb.std.str.Path, which is important for readability and ambiguity avoidance.


375-377: Integration into static initializer preserves previous fallback behavior

The new tryLoadFromDistribution(cxxLibName, rustLibName) call in the static initializer cleanly precedes the existing JAR/dev loading logic and only short‑circuits when both native libs are successfully loaded from a detected distribution directory. If detection fails or loading throws, you fall back to the prior JAR‑based path unchanged.

This aligns nicely with the PR goal (auto‑detect libs in jlink images / configured dists, but never regress the old behavior) and looks good to me.

@questdb-butler
Copy link
Copy Markdown

⚠️ Enterprise CI Failed

The enterprise test suite failed for this PR.

Build: View Details
Tested Commit: f4f7928887bacaedbb0b0f1b1a9f863e1208a0ee

Please investigate the failure before merging.

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😞 fail : 8 / 20 (40.00%)

file detail

path covered line new line coverage
🔵 io/questdb/std/Os.java 8 20 40.00%

@bluestreak01 bluestreak01 merged commit ec78fed into master Jan 5, 2026
40 checks passed
@bluestreak01 bluestreak01 deleted the jh_auto_detect_lib_dir branch January 5, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants