[ 
https://issues.apache.org/jira/browse/KNOX-3246?focusedWorklogId=1002434&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1002434
 ]

ASF GitHub Bot logged work on KNOX-3246:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Jan/26 10:43
            Start Date: 29/Jan/26 10:43
    Worklog Time Spent: 10m 
      Work Description: smolnar82 opened a new pull request, #1141:
URL: https://github.com/apache/knox/pull/1141

   [KNOX-3246](https://issues.apache.org/jira/browse/KNOX-3246) - Make Java 
discovery deterministic on hosts with multiple JDKs
   
   ## What changes were proposed in this pull request?
   
   Extend JAVA_VERSION_PATTERNS to include modern JDK layouts and 
/usr/java/default. Follow symlinks during discovery and sort candidates to 
ensure deterministic Java selection on hosts with multiple JDKs installed.
   
   ## How was this patch tested?
   
   Tested on my cluster with mixed JDK versions.
   
   ```
   $ cat smolnar_test.sh 
   
   #!/usr/bin/env bash
   
   . /$KNOX_HOME/bin/knox-functions.sh
   
   setVerbose "$@"
   checkJava
   ```
   
   Prior to my changes:
   ```
   $ ./smolnar_test.sh --verbose
   Found Java at /usr/java/jdk1.11.70.15-z.0_lu/bin/java
   ```
   
   My changes included:
   ```
   $ ./smolnar_test.sh --verbose
   Found Java at /usr/java/default/bin/java
   
   $ /usr/java/default/bin/java -version
   openjdk version "17.0.11" 2024-04-16
   OpenJDK Runtime Environment OpenLogic-OpenJDK (build 
17.0.11+9-adhoc.root.jdk17u)
   OpenJDK 64-Bit Server VM OpenLogic-OpenJDK (build 
17.0.11+9-adhoc.root.jdk17u, mixed mode, sharing)
   ```
   
   ## Integration Tests
   This issue is hard to reproduce in the existing docker-based framework. It 
requires a multi JDK setup which usually happens at cluster upgrade time.
   
   ## UI changes
   None
   




Issue Time Tracking
-------------------

            Worklog Id:     (was: 1002434)
    Remaining Estimate: 0h
            Time Spent: 10m

> Make Java discovery deterministic on hosts with multiple JDKs
> -------------------------------------------------------------
>
>                 Key: KNOX-3246
>                 URL: https://issues.apache.org/jira/browse/KNOX-3246
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: Startup Scripts
>    Affects Versions: 2.1.0, 3.0.0
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Critical
>             Fix For: 3.0.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> h3. *Problem*
> Knox Java discovery is non-deterministic on hosts with multiple JDK 
> installations.
> In environments where both Java 11 and Java 17 are installed, neither version 
> is matched by the current {{{}JAVA_VERSION_PATTERNS{}}}. As a result, Java 
> detection falls back to the generic {{/bin/java$}} pattern and selects the 
> first match returned by {{{}find{}}}.
> Because the order of results from {{find}} is not guaranteed, different hosts 
> in the same cluster may select different Java versions, leading to 
> inconsistent and unpredictable behavior.
> ----
> h3. *Root Cause*
>  * {{JAVA_VERSION_PATTERNS}} does not include patterns for Java 11 or Java 17 
> installations.
>  * {{{}/usr/java/default/bin/java{}}}, commonly used to define the 
> system-preferred Java, is not recognized.
>  * {{find}} is executed without {{{}-L{}}}, so symlinks are not followed.
>  * The fallback selection uses {{head -n 1}} without stabilizing the result 
> order.
> ----
> h3. *Example*
> On different hosts in the same cluster:
> /usr/lib/jvm/jdk1.17.0.11.0-openjdk/bin/java
> /usr/java/jdk1.11.70.15-z.0_lu/bin/java
>  
> or
> /usr/java/jdk1.11.70.15-z.0_lu/bin/java
> /usr/lib/jvm/jdk1.17.0.11.0-openjdk/bin/java
>  
> Depending on the host, Knox may start with Java 11 or Java 17.
> ----
> h3. *Proposed Fix*
>  * Extend {{JAVA_VERSION_PATTERNS}} to explicitly recognize Java 11 and Java 
> 17 layouts.
>  * Add support for {{/usr/java/default/bin/java}} to honor the system default 
> Java.
>  * Use {{find -L}} to follow symlinks.
>  * Sort Java candidates before selecting the first match to ensure 
> deterministic behavior.
> ----
> h3. *Impact*
> Ensures consistent Java version selection across all nodes in a cluster, 
> prevents unpredictable startup behavior, and aligns Knox Java discovery with 
> common enterprise JDK layouts.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to