From c501961bff6b7407bdb98b3949f6c133096dfaee Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 9 Jan 2020 12:21:04 +0100 Subject: [PATCH] SONAR-12686 use node.store.allow_mmap instead of node.store.allow_mmapfs node.store.allow_mmapfs was deprecated and is now dropped in 7.5.1 --- .../org/sonar/application/es/EsSettings.java | 8 +++-- .../sonar/application/es/EsSettingsTest.java | 31 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java index db4fd0a90f7..a867b3df408 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.process.MessageException; import org.sonar.process.Props; import org.sonar.process.System2; @@ -45,7 +46,7 @@ public class EsSettings { private static final Logger LOGGER = LoggerFactory.getLogger(EsSettings.class); private static final String STANDALONE_NODE_NAME = "sonarqube"; private static final String SECCOMP_PROPERTY = "bootstrap.system_call_filter"; - private static final String ALLOW_MMAP = "node.store.allow_mmapfs"; + private static final String ALLOW_MMAP = "node.store.allow_mmap"; private final Props props; private final EsInstallation fileSystem; @@ -153,7 +154,10 @@ public class EsSettings { builder.put(SECCOMP_PROPERTY, "false"); } - // to be used with HA QA, where we can't easily set mmap size when running with docker. + if (props.value("sonar.search.javaAdditionalOpts", "").contains("-Dnode.store.allow_mmapfs=false")) { + throw new MessageException("Property 'node.store.allow_mmapfs' is no longer supported. Use 'node.store.allow_mmap' instead."); + } + if (props.value("sonar.search.javaAdditionalOpts", "").contains("-D" + ALLOW_MMAP + "=false")) { builder.put(ALLOW_MMAP, "false"); } diff --git a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java index 12c8d55db7e..7717edd8f14 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java @@ -21,6 +21,9 @@ package org.sonar.application.es; import ch.qos.logback.classic.spi.ILoggingEvent; import com.google.common.collect.ImmutableSet; +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.io.File; import java.io.IOException; import java.util.Map; @@ -31,8 +34,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; import org.sonar.application.logging.ListAppender; import org.sonar.core.extension.ServiceLoaderWrapper; +import org.sonar.process.MessageException; import org.sonar.process.ProcessProperties; import org.sonar.process.ProcessProperties.Property; import org.sonar.process.Props; @@ -40,6 +45,7 @@ import org.sonar.process.System2; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME; @@ -55,6 +61,7 @@ import static org.sonar.process.ProcessProperties.Property.SEARCH_INITIAL_STATE_ import static org.sonar.process.ProcessProperties.Property.SEARCH_MINIMUM_MASTER_NODES; import static org.sonar.process.ProcessProperties.Property.SEARCH_PORT; +@RunWith(DataProviderRunner.class) public class EsSettingsTest { private static final boolean CLUSTER_ENABLED = true; @@ -332,10 +339,30 @@ public class EsSettingsTest { @Test public void disable_mmap_if_configured_in_search_additional_props() throws Exception { Props props = minProps(CLUSTER_DISABLED); - props.set("sonar.search.javaAdditionalOpts", "-Dnode.store.allow_mmapfs=false"); + props.set("sonar.search.javaAdditionalOpts", "-Dnode.store.allow_mmap=false"); Map settings = new EsSettings(props, new EsInstallation(props), system).build(); - assertThat(settings.get("node.store.allow_mmapfs")).isEqualTo("false"); + assertThat(settings).containsEntry("node.store.allow_mmap", "false"); + } + + @Test + @UseDataProvider("clusterEnabledOrNot") + public void throw_exception_if_old_mmap_property_is_used(boolean clusterEnabled) throws Exception { + Props props = minProps(clusterEnabled); + props.set("sonar.search.javaAdditionalOpts", "-Dnode.store.allow_mmapfs=false"); + EsSettings settings = new EsSettings(props, new EsInstallation(props), system); + + assertThatThrownBy(settings::build) + .isInstanceOf(MessageException.class) + .hasMessage("Property 'node.store.allow_mmapfs' is no longer supported. Use 'node.store.allow_mmap' instead."); + } + + @DataProvider + public static Object[][] clusterEnabledOrNot() { + return new Object[][] { + {false}, + {true} + }; } private Props minProps(boolean cluster) throws IOException { -- 2.39.5