Browse Source

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.
Jason Tedor 5 years ago
parent
commit
09a649b9bc

+ 16 - 2
server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java

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

+ 18 - 0
server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java

@@ -32,6 +32,7 @@ import org.elasticsearch.discovery.SettingsBasedSeedHostsProvider;
 import org.elasticsearch.monitor.jvm.JvmInfo;
 import org.elasticsearch.node.NodeValidationException;
 import org.elasticsearch.test.AbstractBootstrapCheckTestCase;
+import org.hamcrest.Matcher;
 
 import java.net.InetAddress;
 import java.util.ArrayList;
@@ -50,6 +51,7 @@ import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.Matchers.hasToString;
+import static org.hamcrest.Matchers.not;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -149,8 +151,10 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
         final int max = randomIntBetween(initial + 1, Integer.MAX_VALUE);
         final AtomicLong initialHeapSize = new AtomicLong(initial);
         final AtomicLong maxHeapSize = new AtomicLong(max);
+        final boolean isMemoryLocked = randomBoolean();
 
         final BootstrapChecks.HeapSizeCheck check = new BootstrapChecks.HeapSizeCheck() {
+
             @Override
             long getInitialHeapSize() {
                 return initialHeapSize.get();
@@ -160,6 +164,12 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
             long getMaxHeapSize() {
                 return maxHeapSize.get();
             }
+
+            @Override
+            boolean isMemoryLocked() {
+                return isMemoryLocked;
+            }
+
         };
 
         final NodeValidationException e =
@@ -170,6 +180,14 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
                 e.getMessage(),
                 containsString("initial heap size [" + initialHeapSize.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());