From 8cdee7d30f96e87b8bb7ec55fdfd8101ab717dfd Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 16 Jan 2020 11:05:55 +0100 Subject: [PATCH] SONAR-12686 enforce index rebuilding by changing ES data directory --- server/sonar-docs/src/pages/faq.md | 2 +- server/sonar-docs/src/pages/setup/troubleshooting.md | 4 ++-- .../java/org/sonar/application/es/EsInstallation.java | 9 ++++++--- .../org/sonar/application/es/EsInstallationTest.java | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/server/sonar-docs/src/pages/faq.md b/server/sonar-docs/src/pages/faq.md index 7e2fe09d32c..5061733e951 100644 --- a/server/sonar-docs/src/pages/faq.md +++ b/server/sonar-docs/src/pages/faq.md @@ -20,7 +20,7 @@ This can be automated by using the corresponding Web API: `api/projects/bulk_del Currently, the only way to force a reindex is to: * Stop your server -* Remove the contents of the $SQ_HOME/data/es6 directory +* Remove the contents of the $SQ_HOME/data/es7 directory * Start your server Before doing this, you should be aware first that processes are in place on the SonarQube side that out-of-sync indices are detected and corrected, and second that a full re-index can be quite lengthy depending on the size of your instance. diff --git a/server/sonar-docs/src/pages/setup/troubleshooting.md b/server/sonar-docs/src/pages/setup/troubleshooting.md index a58929c3b34..866db7fa41b 100644 --- a/server/sonar-docs/src/pages/setup/troubleshooting.md +++ b/server/sonar-docs/src/pages/setup/troubleshooting.md @@ -59,13 +59,13 @@ If you still have inconsistencies, you'll need to rebuild the indices (this oper **non-DCE:** 1. Stop SonarQube -1. Delete the data/es6 directory +1. Delete the data/es7 directory 1. Restart SonarQube **DCE:** 1. Stop the whole cluster (ES and application nodes) -1. Delete the data/es6 directory on each ES node +1. Delete the data/es7 directory on each ES node 1. Restart the whole cluster **Note:** See [Configure & Operate a Cluster](/setup/operate-cluster/) for information on stopping and starting a cluster. diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java index 6926c1054ad..6d084d23cba 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java +++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java @@ -20,11 +20,12 @@ package org.sonar.application.es; import java.io.File; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Properties; +import java.util.stream.Stream; import org.sonar.application.command.EsJvmOptions; +import org.sonar.core.util.stream.MoreCollectors; import org.sonar.process.Props; import static org.sonar.process.ProcessProperties.Property.PATH_DATA; @@ -65,12 +66,14 @@ public class EsInstallation { private static List buildOutdatedSearchDirs(Props props) { String dataPath = props.nonNullValue(PATH_DATA.getKey()); - return Arrays.asList(new File(dataPath, "es"), new File(dataPath, "es5")); + return Stream.of("es", "es5", "es6") + .map(t -> new File(dataPath, t)) + .collect(MoreCollectors.toList()); } private static File buildDataDir(Props props) { String dataPath = props.nonNullValue(PATH_DATA.getKey()); - return new File(dataPath, "es6"); + return new File(dataPath, "es7"); } private static File buildLogPath(Props props) { diff --git a/server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java b/server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java index 445fce74baf..b2e70b77b29 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java @@ -102,7 +102,7 @@ public class EsInstallationTest { EsInstallation underTest = new EsInstallation(props); - assertThat(underTest.getDataDirectory()).isEqualTo(new File(dataDir, "es6")); + assertThat(underTest.getDataDirectory()).isEqualTo(new File(dataDir, "es7")); } @Test @@ -133,8 +133,8 @@ public class EsInstallationTest { EsInstallation underTest = new EsInstallation(props); assertThat(underTest.getOutdatedSearchDirectories()) - .extracting(t -> t.getName()) - .containsOnly("es", "es5"); + .extracting(File::getName) + .containsExactlyInAnyOrder("es", "es5", "es6"); } @Test -- 2.39.5