Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ static List<BootstrapCheck> checks(final Settings settings) {
checks.add(new SystemCallFilterCheck(BootstrapSettings.SYSTEM_CALL_FILTER_SETTING.get(settings)));
checks.add(new OnErrorCheck());
checks.add(new OnOutOfMemoryErrorCheck());
checks.add(new EarlyAccessCheck());
checks.add(new G1GCCheck());
return Collections.unmodifiableList(checks);
}
Expand Down Expand Up @@ -577,6 +578,34 @@ public String errorMessage() {

}

/**
* Bootstrap check for early-access builds from OpenJDK.
*/
static class EarlyAccessCheck implements BootstrapCheck {

@Override
public boolean check() {
return "Oracle Corporation".equals(jvmVendor()) && javaVersion().endsWith("-ea");
}

String jvmVendor() {
return Constants.JVM_VENDOR;
}

String javaVersion() {
return Constants.JAVA_VERSION;
}

@Override
public String errorMessage() {
return String.format(
Locale.ROOT,
"Java version [%s] is an early-access build, only use release builds",
javaVersion());
}

}

/**
* Bootstrap check for versions of HotSpot that are known to have issues that can lead to index corruption when G1GC is enabled.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,48 @@ private void runMightForkTest(
consumer.accept(e);
}

public void testEarlyAccessCheck() throws NodeValidationException {
final AtomicReference<String> javaVersion
= new AtomicReference<>(randomFrom("1.8.0_152-ea", "9-ea"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be an AtomicReference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I set it to a different value further down in the method to simulate a check where the Java version is not an early-access build.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++, i didn't realize it was just one instance of the EarlyAccessCheck

final BootstrapChecks.EarlyAccessCheck eaCheck = new BootstrapChecks.EarlyAccessCheck() {

@Override
String jvmVendor() {
return "Oracle Corporation";
}

@Override
String javaVersion() {
return javaVersion.get();
}

};

final List<BootstrapCheck> checks = Collections.singletonList(eaCheck);
final NodeValidationException e = expectThrows(
NodeValidationException.class,
() -> {
BootstrapChecks.check(true, checks, "testEarlyAccessCheck");
});
assertThat(
e.getMessage(),
containsString(
"Java version ["
+ javaVersion.get()
+ "] is an early-access build, only use release builds"));

// if not on an early-access build, nothing should happen
javaVersion.set(randomFrom("1.8.0_152", "9"));
BootstrapChecks.check(true, checks, "testEarlyAccessCheck");

}

public void testG1GCCheck() throws NodeValidationException {
final AtomicBoolean isG1GCEnabled = new AtomicBoolean(true);
final AtomicBoolean isJava8 = new AtomicBoolean(true);
final AtomicReference<String> jvmVersion =
new AtomicReference<>(String.format(Locale.ROOT, "25.%d-b%d", randomIntBetween(0, 39), randomIntBetween(1, 128)));
final BootstrapChecks.G1GCCheck oracleCheck = new BootstrapChecks.G1GCCheck() {
final BootstrapChecks.G1GCCheck g1GCCheck = new BootstrapChecks.G1GCCheck() {

@Override
String jvmVendor() {
Expand All @@ -592,20 +628,20 @@ boolean isJava8() {
final NodeValidationException e =
expectThrows(
NodeValidationException.class,
() -> BootstrapChecks.check(true, Collections.singletonList(oracleCheck), "testG1GCCheck"));
() -> BootstrapChecks.check(true, Collections.singletonList(g1GCCheck), "testG1GCCheck"));
assertThat(
e.getMessage(),
containsString(
"JVM version [" + jvmVersion.get() + "] can cause data corruption when used with G1GC; upgrade to at least Java 8u40"));

// if G1GC is disabled, nothing should happen
isG1GCEnabled.set(false);
BootstrapChecks.check(true, Collections.singletonList(oracleCheck), "testG1GCCheck");
BootstrapChecks.check(true, Collections.singletonList(g1GCCheck), "testG1GCCheck");

// if on or after update 40, nothing should happen independent of whether or not G1GC is enabled
isG1GCEnabled.set(randomBoolean());
jvmVersion.set(String.format(Locale.ROOT, "25.%d-b%d", randomIntBetween(40, 112), randomIntBetween(1, 128)));
BootstrapChecks.check(true, Collections.singletonList(oracleCheck), "testG1GCCheck");
BootstrapChecks.check(true, Collections.singletonList(g1GCCheck), "testG1GCCheck");

final BootstrapChecks.G1GCCheck nonOracleCheck = new BootstrapChecks.G1GCCheck() {

Expand Down
7 changes: 7 additions & 0 deletions docs/reference/setup/bootstrap-checks.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ use the JVM flag `ExitOnOutOfMemoryError`. While this does not have the
full capabilities of `OnError` nor `OnOutOfMemoryError`, arbitrary
forking will not be supported with seccomp enabled.

=== Early-access check

The OpenJDK project provides early-access snapshots of upcoming releases. These
releases are not suitable for production. The early-access check detects these
early-access snapshots. To pass this check, you must start Elasticsearch on a
release build of the JVM.

=== G1GC check

Early versions of the HotSpot JVM that shipped with JDK 8 are known to have
Expand Down