You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ss...@apache.org on 2023/12/12 01:10:52 UTC

(phoenix-queryserver) branch master updated: PHOENIX-7143 Detect JVM version and add the necessary module flags in startup scripts (#142)

This is an automated email from the ASF dual-hosted git repository.

ssa pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix-queryserver.git


The following commit(s) were added to refs/heads/master by this push:
     new da71f55  PHOENIX-7143 Detect JVM version and add the necessary module flags in startup scripts (#142)
da71f55 is described below

commit da71f55dcf4216024b659126d1258ded2e2d19ef
Author: Istvan Toth <st...@apache.org>
AuthorDate: Tue Dec 12 02:10:47 2023 +0100

    PHOENIX-7143 Detect JVM version and add the necessary module flags in startup scripts (#142)
---
 bin/phoenix_queryserver_utils.py | 81 ++++++++++++++++++++++++++++++++++++++++
 bin/queryserver.py               | 47 +++++++++--------------
 bin/sqlline-thin.py              |  3 +-
 3 files changed, 100 insertions(+), 31 deletions(-)

diff --git a/bin/phoenix_queryserver_utils.py b/bin/phoenix_queryserver_utils.py
index 840c1ad..2d66435 100755
--- a/bin/phoenix_queryserver_utils.py
+++ b/bin/phoenix_queryserver_utils.py
@@ -21,6 +21,7 @@
 
 import os
 import fnmatch
+import re
 import subprocess
 
 def find(pattern, classPaths):
@@ -172,6 +173,81 @@ def setPath():
         logging_jar += ":"+findFileInPathWithoutRecursion(LOGGING_JAR_PATTERN2, os.path.join(current_dir, "..","lib"))
         logging_jar += ":"+findFileInPathWithoutRecursion(LOGGING_JAR_PATTERN3, os.path.join(current_dir, "..","lib"))
 
+    __set_java_home()
+    __set_jvm_flags()
+    return ""
+
+
+def __set_java_home():
+    global hbase_env
+    global java_home
+    global java
+    java_home = os.getenv('JAVA_HOME')
+    java = 'java'
+
+    # HBase configuration folder path (where hbase-site.xml reside) for
+    # HBase/Phoenix client side property override
+    hbase_config_path = hbase_conf_dir
+
+    # load hbase-env.??? to extract JAVA_HOME, HBASE_PID_DIR, HBASE_LOG_DIR
+    hbase_env_path = None
+    hbase_env_cmd  = None
+    if os.name == 'posix':
+        hbase_env_path = os.path.join(hbase_config_path, 'hbase-env.sh')
+        hbase_env_cmd = ['bash', '-c', 'source %s && env' % hbase_env_path]
+    elif os.name == 'nt':
+        hbase_env_path = os.path.join(hbase_config_path, 'hbase-env.cmd')
+        hbase_env_cmd = ['cmd.exe', '/c', 'call %s & set' % hbase_env_path]
+    if not hbase_env_path or not hbase_env_cmd:
+        sys.stderr.write("hbase-env file unknown on platform {}{}".format(os.name, os.linesep))
+        sys.exit(-1)
+
+    hbase_env = {}
+    if os.path.isfile(hbase_env_path):
+        p = subprocess.Popen(hbase_env_cmd, stdout = subprocess.PIPE)
+        for x in p.stdout:
+            (k, _, v) = tryDecode(x).partition('=')
+            hbase_env[k.strip()] = v.strip()
+
+    if 'JAVA_HOME' in hbase_env:
+        java_home = hbase_env['JAVA_HOME']
+
+    if java_home:
+        java = os.path.join(java_home, 'bin', 'java')
+
+    return ""
+
+
+def __set_jvm_flags():
+    global jvm_module_flags
+    jvm_module_flags = ""
+    # This should be ASCII
+    version_output = subprocess.check_output([java, "-version"], stderr=subprocess.STDOUT).decode()
+    version_output = tryDecode(version_output)
+    m = re.search(r'version\s"(\d+)\.(\d+)', version_output)
+    if (m is None):
+        # Could not find version
+        return ""
+    major = m.group(1)
+    minor = m.group(2)
+    if (major is None or minor is None):
+        #Could not identify version
+        return ""
+    if (minor == "1"):
+        major = minor
+    if (int(major) >= 11):
+        # Copied from hbase startup script
+        jvm_module_flags = "-Dorg.apache.hbase.thirdparty.io.netty.tryReflectionSetAccessible=true \
+--add-modules jdk.unsupported \
+--add-opens java.base/java.nio=ALL-UNNAMED \
+--add-opens java.base/sun.nio.ch=ALL-UNNAMED \
+--add-opens java.base/java.lang=ALL-UNNAMED \
+--add-opens java.base/jdk.internal.ref=ALL-UNNAMED \
+--add-opens java.base/java.lang.reflect=ALL-UNNAMED \
+--add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
+--add-exports java.security.jgss/sun.security.krb5=ALL-UNNAMED \
+--add-exports java.base/sun.net.dns=ALL-UNNAMED \
+--add-exports java.base/sun.net.util=ALL-UNNAMED"
     return ""
 
 def shell_quote(args):
@@ -208,3 +284,8 @@ if __name__ == "__main__":
     print("phoenix_thin_client_jar:", phoenix_thin_client_jar)
     print("sqlline_with_deps_jar", sqlline_with_deps_jar)
     print("slf4j_backend_jar:", slf4j_backend_jar)
+    print("java_home:", java_home)
+    print("java:", java)
+    print("jvm_module_flags:", jvm_module_flags)
+    print("hbase_env:", hbase_env)
+
diff --git a/bin/queryserver.py b/bin/queryserver.py
index 9609157..8120d9b 100755
--- a/bin/queryserver.py
+++ b/bin/queryserver.py
@@ -82,33 +82,8 @@ phoenix_log_file = '%s.log' % phoenix_file_basename
 phoenix_out_file = '%s.out' % phoenix_file_basename
 phoenix_pid_file = '%s.pid' % phoenix_file_basename
 
-# load hbase-env.??? to extract JAVA_HOME, HBASE_PID_DIR, HBASE_LOG_DIR
-hbase_env_path = None
-hbase_env_cmd  = None
-if os.name == 'posix':
-    hbase_env_path = os.path.join(hbase_conf_dir, 'hbase-env.sh')
-    hbase_env_cmd = ['bash', '-c', 'source %s && env' % hbase_env_path]
-elif os.name == 'nt':
-    hbase_env_path = os.path.join(hbase_conf_dir, 'hbase-env.cmd')
-    hbase_env_cmd = ['cmd.exe', '/c', 'call %s & set' % hbase_env_path]
-if not hbase_env_path or not hbase_env_cmd:
-    sys.stderr.write("hbase-env file unknown on platform {}{}".format(os.name, os.linesep))
-    sys.exit(-1)
-
-hbase_env = {}
-if os.path.isfile(hbase_env_path):
-    p = subprocess.Popen(hbase_env_cmd, stdout = subprocess.PIPE)
-    for x in p.stdout:
-        (k, _, v) = tryDecode(x).partition('=')
-        hbase_env[k.strip()] = v.strip()
-
-java_home = hbase_env.get('JAVA_HOME') or os.getenv('JAVA_HOME')
-if java_home:
-    java = os.path.join(java_home, 'bin', 'java')
-else:
-    java = 'java'
-
 tmp_dir = os.path.join(tempfile.gettempdir(), 'phoenix')
+hbase_env = phoenix_queryserver_utils.hbase_env
 opts = os.getenv('PHOENIX_QUERYSERVER_OPTS') or hbase_env.get('PHOENIX_QUERYSERVER_OPTS') or ''
 pid_dir = os.getenv('PHOENIX_QUERYSERVER_PID_DIR') or hbase_env.get('HBASE_PID_DIR') or tmp_dir
 log_dir = os.getenv('PHOENIX_QUERYSERVER_LOG_DIR') or hbase_env.get('HBASE_LOG_DIR') or tmp_dir
@@ -120,7 +95,7 @@ out_file_path = os.path.join(log_dir, phoenix_out_file)
 #    " -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true" + \
 
 # The command is run through subprocess so environment variables are automatically inherited
-java_cmd = '%(java)s -cp ' +\
+java_cmd = '%(java)s %(jvm_module_flags)s -cp ' +\
     hbase_conf_dir + os.pathsep + \
     hadoop_conf_dir + os.pathsep + \
     phoenix_queryserver_utils.slf4j_backend_jar + os.pathsep + \
@@ -137,7 +112,11 @@ java_cmd = '%(java)s -cp ' +\
     " org.apache.phoenix.queryserver.server.QueryServer " + args
 
 if command == 'makeWinServiceDesc':
-    cmd = java_cmd % {'java': java, 'root_logger': 'INFO,DRFA,console', 'log_dir': log_dir, 'log_file': phoenix_log_file}
+    cmd = (java_cmd % {'java': phoenix_queryserver_utils.java,
+                      'jvm_module_flags':phoenix_queryserver_utils.jvm_module_flags,
+                      'root_logger': 'INFO,DRFA,console',
+                      'log_dir': log_dir,
+                      'log_file': phoenix_log_file})
     slices = cmd.split(' ')
 
     print("<service>")
@@ -174,7 +153,11 @@ if command == 'start':
         with context:
             # this block is the main() for the forked daemon process
             child = None
-            cmd = java_cmd % {'java': java, 'root_logger': 'INFO,DRFA', 'log_dir': log_dir, 'log_file': phoenix_log_file}
+            cmd = (java_cmd % {'java': phoenix_queryserver_utils.java,
+                      'jvm_module_flags':phoenix_queryserver_utils.jvm_module_flags,
+                      'root_logger': 'INFO,DRFA',
+                      'log_dir': log_dir,
+                      'log_file': phoenix_log_file})
 
             # notify the child when we're killed
             def handler(signum, frame):
@@ -215,6 +198,10 @@ elif command == 'stop':
 
 else:
     # run in the foreground using defaults from log4j.properties
-    cmd = java_cmd % {'java': java, 'root_logger': 'INFO,console', 'log_dir': '.', 'log_file': 'psql.log'}
+    cmd = (java_cmd % {'java': phoenix_queryserver_utils.java,
+                      'jvm_module_flags':phoenix_queryserver_utils.jvm_module_flags,
+                      'root_logger': 'INFO,console',
+                      'log_dir': '.',
+                      'log_file': 'psql.log'})
     splitcmd = cmd.split()
     os.execvp(splitcmd[0], splitcmd)
diff --git a/bin/sqlline-thin.py b/bin/sqlline-thin.py
index 1575886..af76434 100755
--- a/bin/sqlline-thin.py
+++ b/bin/sqlline-thin.py
@@ -208,7 +208,8 @@ if (get_hbase_authentication() == 'kerberos' and get_spnego_auth_disabled() == '
    and 'authentication=' not in jdbc_url and 'avatica_user=' not in jdbc_url):
     jdbc_url += ';authentication=SPNEGO'
 
-java_cmd = java + ' $PHOENIX_OPTS ' + \
+java_cmd = phoenix_queryserver_utils.java + ' ' + phoenix_queryserver_utils.jvm_module_flags + \
+    ' $PHOENIX_OPTS ' + \
     ' -cp "' + phoenix_queryserver_utils.sqlline_with_deps_jar + os.pathsep + \
     phoenix_queryserver_utils.phoenix_thin_client_jar + os.pathsep + \
     phoenix_queryserver_utils.slf4j_backend_jar + os.pathsep + \