]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12686 update JVM options to match defaults in ES 7.X
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 9 Jan 2020 08:57:58 +0000 (09:57 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 5 Nov 2020 20:06:21 +0000 (20:06 +0000)
Elastic introduced "system" JVM settings in 7.X:
 * "system" settings are set from Java code (class SystemJvmOptions)
 * which means these JVM settings are not defined in "jvm.options" file anymore

server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java

index 85a7cc05da258d648f88812841101398850388cb..4447f1b7293f07e0e0d9d2ce128638a5a38fcd9a 100644 (file)
@@ -43,48 +43,22 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
   // with some changes to fit running bundled in SQ
   private static Map<String, String> mandatoryOptions(File tmpDir, Props props) {
     Map<String, String> res = new LinkedHashMap<>(30);
+    fromJvmDotOptionsFile(tmpDir, res);
+    fromSystemJvmOptionsClass(res);
+
+    if (!props.value("sonar.jdbc.url", "").contains("jdbc:h2") && !props.valueAsBoolean("sonar.es.bootstrap.checks.disable")) {
+      res.put("-Des.enforce.bootstrap.checks=", "true");
+    }
+
+    return res;
+  }
+
+  private static void fromJvmDotOptionsFile(File tmpDir, Map<String, String> res) {
     // GC configuration
     res.put("-XX:+UseConcMarkSweepGC", "");
     res.put("-XX:CMSInitiatingOccupancyFraction=", "75");
     res.put("-XX:+UseCMSInitiatingOccupancyOnly", "");
 
-    // DNS cache policy
-    // cache ttl in seconds for positive DNS lookups noting that this overrides the
-    // JDK security property networkaddress.cache.ttl; set to -1 to cache forever
-    res.put("-Des.networkaddress.cache.ttl=", "60");
-    // cache ttl in seconds for negative DNS lookups noting that this overrides the
-    // JDK security property networkaddress.cache.negative ttl; set to -1 to cache
-    // forever
-    res.put("-Des.networkaddress.cache.negative.ttl=", "10");
-
-    // optimizations
-
-    // pre-touch memory pages used by the JVM during initialization
-    res.put("-XX:+AlwaysPreTouch", "");
-
-    // basic
-    // explicitly set the stack size
-    res.put("-Xss1m", "");
-    // set to headless, just in case
-    res.put("-Djava.awt.headless=", "true");
-    // ensure UTF-8 encoding by default (e.g. filenames)
-    res.put("-Dfile.encoding=", "UTF-8");
-    // use our provided JNA always versus the system one
-    res.put("-Djna.nosys=", "true");
-
-    // turn off a JDK optimization that throws away stack traces for common
-    // exceptions because stack traces are important for debugging
-    res.put("-XX:-OmitStackTraceInFastThrow", "");
-
-    // flags to configure Netty
-    res.put("-Dio.netty.noUnsafe=", "true");
-    res.put("-Dio.netty.noKeySetOptimization=", "true");
-    res.put("-Dio.netty.recycler.maxCapacityPerThread=", "0");
-
-    // log4j 2
-    res.put("-Dlog4j.shutdownHookEnabled=", "false");
-    res.put("-Dlog4j2.disable.jmx=", "true");
-
     // (by default ES 6.6.1 uses variable ${ES_TMPDIR} which is replaced by start scripts. Since we start JAR file
     // directly on windows, we specify absolute file as URL (to support space in path) instead
     res.put("-Djava.io.tmpdir=", tmpDir.getAbsolutePath());
@@ -110,12 +84,50 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
     // res.put("8:-XX:GCLogFileSize", "64m");
     // JDK 9+ GC logging
     // res.put("9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m", "");
+  }
 
-    if (!props.value("sonar.jdbc.url", "").contains("jdbc:h2") && !props.valueAsBoolean("sonar.es.bootstrap.checks.disable")) {
-      res.put("-Des.enforce.bootstrap.checks=", "true");
-    }
-
-    return res;
+  /**
+   * JVM options from class "org.elasticsearch.tools.launchers.SystemJvmOptions"
+   */
+  private static void fromSystemJvmOptionsClass(Map<String, String> res) {
+    /*
+     * Cache ttl in seconds for positive DNS lookups noting that this overrides the JDK security property networkaddress.cache.ttl;
+     * can be set to -1 to cache forever.
+     */
+    res.put("-Des.networkaddress.cache.ttl=", "60");
+    /*
+     * Cache ttl in seconds for negative DNS lookups noting that this overrides the JDK security property
+     * networkaddress.cache.negative ttl; set to -1 to cache forever.
+     */
+    res.put("-Des.networkaddress.cache.negative.ttl=", "10");
+    // pre-touch JVM emory pages during initialization
+    res.put("-XX:+AlwaysPreTouch", "");
+    // explicitly set the stack size
+    res.put("-Xss1m", "");
+    // set to headless, just in case,
+    res.put("-Djava.awt.headless=", "true");
+    // ensure UTF-8 encoding by default (e.g., filenames)
+    res.put("-Dfile.encoding=", "UTF-8");
+    // use our provided JNA always versus the system one
+    res.put("-Djna.nosys=", "true");
+    /*
+     * Turn off a JDK optimization that throws away stack traces for common exceptions because stack traces are important for
+     * debugging.
+     */
+    res.put("-XX:-OmitStackTraceInFastThrow", "");
+    // flags to configure Netty
+    res.put("-Dio.netty.noUnsafe=", "true");
+    res.put("-Dio.netty.noKeySetOptimization=", "true");
+    res.put("-Dio.netty.recycler.maxCapacityPerThread=", "0");
+    res.put("-Dio.netty.allocator.numDirectArenas=", "0");
+    // log4j 2
+    res.put("-Dlog4j.shutdownHookEnabled=", "false");
+    res.put("-Dlog4j2.disable.jmx=", "true");
+    /*
+     * Due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise time/date
+     * parsing will break in an incompatible way for some date patterns and locales.
+     */
+    res.put("-Djava.locale.providers=", "COMPAT");
   }
 
   public void writeToJvmOptionFile(File file) {
index 751f188d0cddf2725c3460e123dfde7fcfafb58e..2d51a0f540354448552ae5b5a30c2bb9e9c5efdc 100644 (file)
@@ -44,7 +44,7 @@ public class EsJvmOptionsTest {
   private Properties properties = new Properties();
 
   @Test
-  public void constructor_sets_mandatory_JVM_options_on_Java_11() throws IOException {
+  public void constructor_sets_mandatory_JVM_options() throws IOException {
     File tmpDir = temporaryFolder.newFolder();
     EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
 
@@ -53,6 +53,8 @@ public class EsJvmOptionsTest {
         "-XX:+UseConcMarkSweepGC",
         "-XX:CMSInitiatingOccupancyFraction=75",
         "-XX:+UseCMSInitiatingOccupancyOnly",
+        "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
+        "-XX:ErrorFile=../logs/es_hs_err_pid%p.log",
         "-Des.networkaddress.cache.ttl=60",
         "-Des.networkaddress.cache.negative.ttl=10",
         "-XX:+AlwaysPreTouch",
@@ -64,10 +66,10 @@ public class EsJvmOptionsTest {
         "-Dio.netty.noUnsafe=true",
         "-Dio.netty.noKeySetOptimization=true",
         "-Dio.netty.recycler.maxCapacityPerThread=0",
+        "-Dio.netty.allocator.numDirectArenas=0",
         "-Dlog4j.shutdownHookEnabled=false",
         "-Dlog4j2.disable.jmx=true",
-        "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
-        "-XX:ErrorFile=../logs/es_hs_err_pid%p.log",
+        "-Djava.locale.providers=COMPAT",
         "-Des.enforce.bootstrap.checks=true");
   }
 
@@ -132,6 +134,8 @@ public class EsJvmOptionsTest {
         "-XX:+UseConcMarkSweepGC\n" +
         "-XX:CMSInitiatingOccupancyFraction=75\n" +
         "-XX:+UseCMSInitiatingOccupancyOnly\n" +
+        "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath() + "\n" +
+        "-XX:ErrorFile=../logs/es_hs_err_pid%p.log\n" +
         "-Des.networkaddress.cache.ttl=60\n" +
         "-Des.networkaddress.cache.negative.ttl=10\n" +
         "-XX:+AlwaysPreTouch\n" +
@@ -143,10 +147,10 @@ public class EsJvmOptionsTest {
         "-Dio.netty.noUnsafe=true\n" +
         "-Dio.netty.noKeySetOptimization=true\n" +
         "-Dio.netty.recycler.maxCapacityPerThread=0\n" +
+        "-Dio.netty.allocator.numDirectArenas=0\n" +
         "-Dlog4j.shutdownHookEnabled=false\n" +
         "-Dlog4j2.disable.jmx=true\n" +
-        "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath() + "\n" +
-        "-XX:ErrorFile=../logs/es_hs_err_pid%p.log\n" +
+        "-Djava.locale.providers=COMPAT\n" +
         "-Des.enforce.bootstrap.checks=true\n" +
         "-foo\n" +
         "-bar");