Skip to content

Commit

Permalink
Add replay diagnostic dir to system jvm options (elastic#103535)
Browse files Browse the repository at this point in the history
When hotspot encounters an error, it will emite a log file which can be
used for reproducing the error. This file is dumped to /tmp by default.
This commit configures the replay file to be alongside the hs_err file.
  • Loading branch information
rjernst authored Feb 6, 2024
1 parent b1e2cb8 commit 2a298a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
final class SystemJvmOptions {

static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, String> sysprops) {
String distroType = sysprops.get("es.distribution.type");
boolean isHotspot = sysprops.getOrDefault("sun.management.compiler", "").contains("HotSpot");
return Stream.of(
/*
* Cache ttl in seconds for positive DNS lookups noting that this overrides the JDK security property networkaddress.cache.ttl;
Expand Down Expand Up @@ -65,10 +67,11 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
* explore alternatives. See org.elasticsearch.xpack.searchablesnapshots.preallocate.Preallocate.
*/
"--add-opens=java.base/java.io=org.elasticsearch.preallocate",
maybeOverrideDockerCgroup(),
maybeOverrideDockerCgroup(distroType),
maybeSetActiveProcessorCount(nodeSettings),
setReplayFile(distroType, isHotspot),
// Pass through distribution type
"-Des.distribution.type=" + sysprops.get("es.distribution.type")
"-Des.distribution.type=" + distroType
).filter(e -> e.isEmpty() == false).collect(Collectors.toList());
}

Expand All @@ -86,13 +89,25 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
* that cgroup statistics are available for the container this process
* will run in.
*/
private static String maybeOverrideDockerCgroup() {
if ("docker".equals(System.getProperty("es.distribution.type"))) {
private static String maybeOverrideDockerCgroup(String distroType) {
if ("docker".equals(distroType)) {
return "-Des.cgroups.hierarchy.override=/";
}
return "";
}

private static String setReplayFile(String distroType, boolean isHotspot) {
if (isHotspot == false) {
// the replay file option is only guaranteed for hotspot vms
return "";
}
String replayDir = "logs";
if ("rpm".equals(distroType) || "deb".equals(distroType)) {
replayDir = "/var/log/elasticsearch";
}
return "-XX:ReplayDataFile=" + replayDir + "/replay_pid%p.log";
}

/*
* node.processors determines thread pool sizes for Elasticsearch. When it
* is set, we need to also tell the JVM to respect a different value
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/103535.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 103535
summary: Add replay diagnostic dir to system jvm options
area: Infra/CLI
type: enhancement
issues: []

0 comments on commit 2a298a7

Please sign in to comment.