[GLUTEN-12392][CORE] Return early in JniLibLoader.loadAndCreateLink() when the library is already loaded#12393
Merged
jackylee-ch merged 1 commit intoJun 30, 2026
Conversation
… when the library is already loaded
|
Run Gluten Clickhouse CI on x86 |
LuciferYang
commented
Jun 29, 2026
| try { | ||
| if (loadedLibraries.contains(libPath)) { | ||
| LOG.debug("Library {} has already been loaded, skipping", libPath); | ||
| return; |
Contributor
There was a problem hiding this comment.
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;inloadAndCreateLink()whenloadedLibrariesalready containslibPath. - 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
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 areturn;— somoveToWorkDirand the symlink rebuild ran anyway. The siblingload()doesreturn;in the same branch, so the two methods diverged. This PR adds the missingreturn;so the method mirrorsload(), plus a short Javadoc onloadAndCreateLinkdocumenting the contract ("same asload, 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.loadis deduped further down viaLOADED_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:checkpasses. Existinggluten-coretests (mvn -pl gluten-core -Pspark-3.5 test) still pass. The fix is a 1-line behavioural alignment withload()— a reflection-based unit test was considered and rejected to avoid coupling tests to the privateloadedLibrariesfield; the contract is captured by Javadoc instead.