Skip to content

[GLUTEN-12392][CORE] Return early in JniLibLoader.loadAndCreateLink() when the library is already loaded#12393

Merged
jackylee-ch merged 1 commit into
apache:mainfrom
LuciferYang:gluten-jni-loader-early-return
Jun 30, 2026
Merged

[GLUTEN-12392][CORE] Return early in JniLibLoader.loadAndCreateLink() when the library is already loaded#12393
jackylee-ch merged 1 commit into
apache:mainfrom
LuciferYang:gluten-jni-loader-early-return

Conversation

@LuciferYang

@LuciferYang LuciferYang commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

JniLibLoader.loadAndCreateLink() had an early-skip log line for libraries already loaded by the instance, but the branch was missing a return; — so moveToWorkDir and the symlink rebuild ran anyway. The sibling load() does return; in the same branch, so the two methods diverged. This PR adds the missing return; so the method mirrors load(), plus a short Javadoc on loadAndCreateLink documenting the contract ("same as load, plus a symbolic link; returns immediately if already loaded") so the behaviour is pinned rather than only enforced by code-shape symmetry.

Why are the changes needed?

Closes #12392. Because System.load is deduped further down via LOADED_LIBRARY_PATHS, the bug does not cause a double native load — but every repeat call still re-extracts the library to the work directory and delete+recreates the symlink. That is wasted I/O at best, and a delete/recreate race against any concurrent reader of the work directory at worst.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

mvn -pl gluten-core -Pspark-3.5 spotless:check passes. Existing gluten-core tests (mvn -pl gluten-core -Pspark-3.5 test) still pass. The fix is a 1-line behavioural alignment with load() — a reflection-based unit test was considered and rejected to avoid coupling tests to the private loadedLibraries field; the contract is captured by Javadoc instead.

Copilot AI review requested due to automatic review settings June 29, 2026 11:52
@github-actions github-actions Bot added the CORE works for Gluten Core label Jun 29, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

try {
if (loadedLibraries.contains(libPath)) {
LOG.debug("Library {} has already been loaded, skipping", libPath);
return;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cc @jackylee-ch , a minor fix

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a behavioral bug in gluten-core’s JNI library extraction/linking path by making JniLibLoader.loadAndCreateLink() truly no-op when the same JniLibLoader instance has already loaded the requested library, aligning it with the existing behavior of load() and avoiding redundant extraction + symlink churn.

Changes:

  • Add the missing return; in loadAndCreateLink() when loadedLibraries already contains libPath.
  • Add Javadoc to document the method’s contract (mirrors load(), plus creates a symlink; returns immediately if already loaded).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jackylee-ch jackylee-ch merged commit ea57b1c into apache:main Jun 30, 2026
110 of 112 checks passed
@LuciferYang LuciferYang deleted the gluten-jni-loader-early-return branch June 30, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE works for Gluten Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JniLibLoader.loadAndCreateLink() does not skip work for an already-loaded library

3 participants