]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4899 Tune default replication settings on ES indices
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 22 Nov 2013 16:33:56 +0000 (17:33 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 22 Nov 2013 16:33:56 +0000 (17:33 +0100)
sonar-server/src/main/java/org/sonar/server/search/SearchIndex.java
sonar-server/src/main/java/org/sonar/server/search/SearchNode.java

index 880abf212a62f9fc2490117fc17fddbdf6cd9766..9912a933b97491b153959e36f7ea3a7d2644aa54 100644 (file)
@@ -34,6 +34,8 @@ import org.elasticsearch.client.Client;
 import org.elasticsearch.client.IndicesAdminClient;
 import org.elasticsearch.client.Requests;
 import org.elasticsearch.common.io.BytesStream;
+import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.search.SearchHit;
 import org.slf4j.Logger;
@@ -51,6 +53,11 @@ public class SearchIndex {
 
   private static final Logger LOG = LoggerFactory.getLogger(SearchIndex.class);
 
+  private static final Settings INDEX_DEFAULT_SETTINGS = ImmutableSettings.builder()
+    .put("index.number_of_shards", 1)
+    .put("index.number_of_replicas", 0)
+    .build();
+
   private SearchNode searchNode;
   private Client client;
 
@@ -129,7 +136,9 @@ public class SearchIndex {
     try {
       if (! indices.exists(new IndicesExistsRequest(index)).get().isExists()) {
         profiler.start(format("create index '%s'", index));
-        indices.prepareCreate(index).execute().actionGet();
+        indices.prepareCreate(index)
+          .setSettings(INDEX_DEFAULT_SETTINGS)
+          .execute().actionGet();
       }
     } catch (Exception e) {
       LOG.error("While checking for index existence", e);
index d928543fc12a603304a292a4fd230c080e35fadc..cda82469da38f7da5ab50338e7f7924b4a1c8961 100644 (file)
@@ -66,10 +66,7 @@ public class SearchNode {
       .put("node.path.data", nodeDir)
       .put("node.path.work", nodeDir)
       .put("node.path.logs", nodeDir)
-      .put("gateway.type", "none")
-      .put("index.store.type", "ram")
-      .put("index.number_of_shards", 1)
-      .put("index.number_of_replicas", 0);
+      .put("gateway.type", "none");
 
     String httpHost = settings.getString("sonar.es.http.host");
     String httpPort = settings.getString("sonar.es.http.port");