Adjust warning for heap size bootstrap check (#56565)

Today the heap size check warns the user about two issues why they might
care about the heap size check: resize pauses, and if memory locking is
enabled. Yet, we unconditionally make mention of the memory locking
reason, even if memory locking is not enabled. This can confuse some
users, so we adjust the warning about memory locking to only display if
memory locking is enabled.
This commit is contained in:
Jason Tedor 2020-05-12 14:30:45 -04:00
parent d247e8f7a6
commit f7b8f0b2f4
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
2 changed files with 34 additions and 2 deletions

View File

@ -226,12 +226,22 @@ final class BootstrapChecks {
final long initialHeapSize = getInitialHeapSize(); final long initialHeapSize = getInitialHeapSize();
final long maxHeapSize = getMaxHeapSize(); final long maxHeapSize = getMaxHeapSize();
if (initialHeapSize != 0 && maxHeapSize != 0 && initialHeapSize != maxHeapSize) { if (initialHeapSize != 0 && maxHeapSize != 0 && initialHeapSize != maxHeapSize) {
final String message = String.format( final String message;
if (isMemoryLocked()) {
message = String.format(
Locale.ROOT, Locale.ROOT,
"initial heap size [%d] not equal to maximum heap size [%d]; " + "initial heap size [%d] not equal to maximum heap size [%d]; " +
"this can cause resize pauses and prevents mlockall from locking the entire heap", "this can cause resize pauses and prevents memory locking from locking the entire heap",
getInitialHeapSize(), getInitialHeapSize(),
getMaxHeapSize()); getMaxHeapSize());
} else {
message = String.format(
Locale.ROOT,
"initial heap size [%d] not equal to maximum heap size [%d]; " +
"this can cause resize pauses",
getInitialHeapSize(),
getMaxHeapSize());
}
return BootstrapCheckResult.failure(message); return BootstrapCheckResult.failure(message);
} else { } else {
return BootstrapCheckResult.success(); return BootstrapCheckResult.success();
@ -248,6 +258,10 @@ final class BootstrapChecks {
return JvmInfo.jvmInfo().getConfiguredMaxHeapSize(); return JvmInfo.jvmInfo().getConfiguredMaxHeapSize();
} }
boolean isMemoryLocked() {
return Natives.isMemoryLocked();
}
} }
static class OsXFileDescriptorCheck extends FileDescriptorCheck { static class OsXFileDescriptorCheck extends FileDescriptorCheck {

View File

@ -32,6 +32,7 @@ import org.elasticsearch.discovery.SettingsBasedSeedHostsProvider;
import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.node.NodeValidationException; import org.elasticsearch.node.NodeValidationException;
import org.elasticsearch.test.AbstractBootstrapCheckTestCase; import org.elasticsearch.test.AbstractBootstrapCheckTestCase;
import org.hamcrest.Matcher;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
@ -51,6 +52,7 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -150,8 +152,10 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
final int max = randomIntBetween(initial + 1, Integer.MAX_VALUE); final int max = randomIntBetween(initial + 1, Integer.MAX_VALUE);
final AtomicLong initialHeapSize = new AtomicLong(initial); final AtomicLong initialHeapSize = new AtomicLong(initial);
final AtomicLong maxHeapSize = new AtomicLong(max); final AtomicLong maxHeapSize = new AtomicLong(max);
final boolean isMemoryLocked = randomBoolean();
final BootstrapChecks.HeapSizeCheck check = new BootstrapChecks.HeapSizeCheck() { final BootstrapChecks.HeapSizeCheck check = new BootstrapChecks.HeapSizeCheck() {
@Override @Override
long getInitialHeapSize() { long getInitialHeapSize() {
return initialHeapSize.get(); return initialHeapSize.get();
@ -161,6 +165,12 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
long getMaxHeapSize() { long getMaxHeapSize() {
return maxHeapSize.get(); return maxHeapSize.get();
} }
@Override
boolean isMemoryLocked() {
return isMemoryLocked;
}
}; };
final NodeValidationException e = final NodeValidationException e =
@ -171,6 +181,14 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
e.getMessage(), e.getMessage(),
containsString("initial heap size [" + initialHeapSize.get() + "] " + containsString("initial heap size [" + initialHeapSize.get() + "] " +
"not equal to maximum heap size [" + maxHeapSize.get() + "]")); "not equal to maximum heap size [" + maxHeapSize.get() + "]"));
final String memoryLockingMessage = "and prevents memory locking from locking the entire heap";
final Matcher<String> memoryLockingMatcher;
if (isMemoryLocked) {
memoryLockingMatcher = containsString(memoryLockingMessage);
} else {
memoryLockingMatcher = not(containsString(memoryLockingMessage));
}
assertThat(e.getMessage(), memoryLockingMatcher);
initialHeapSize.set(maxHeapSize.get()); initialHeapSize.set(maxHeapSize.get());