aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-main/src/main/java/org/sonar
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2020-01-09 09:57:58 +0100
committersonartech <sonartech@sonarsource.com>2020-11-05 20:06:21 +0000
commit191a19739e294985caf5c6dbce7766443533d86c (patch)
tree2c51c72474397ed3505cf6cc0c2f569d19991534 /server/sonar-main/src/main/java/org/sonar
parentcf4841fb3415b02ae3a421bece48631b2fde9118 (diff)
downloadsonarqube-191a19739e294985caf5c6dbce7766443533d86c.tar.gz
sonarqube-191a19739e294985caf5c6dbce7766443533d86c.zip
SONAR-12686 update JVM options to match defaults in ES 7.X
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
Diffstat (limited to 'server/sonar-main/src/main/java/org/sonar')
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java96
1 files changed, 54 insertions, 42 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java b/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
index 85a7cc05da2..4447f1b7293 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
@@ -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) {