]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8088 Reduce number of shards for users and rules indices
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 16 Sep 2016 12:37:28 +0000 (14:37 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 16 Sep 2016 13:27:52 +0000 (15:27 +0200)
12 files changed:
server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.java
server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java

index fdcb12991c04a5e35bd110d2a6601f8d287881ee..6683df588d16f0291329e38a4feca8a766eadb44 100644 (file)
@@ -40,8 +40,6 @@ import static org.sonar.server.es.BaseIndex.SORT_SUFFIX;
 
 public class NewIndex {
 
-  public static final int DEFAULT_NUMBER_OF_SHARDS = 5;
-
   private final String indexName;
   private final Settings.Builder settings = DefaultIndexSettings.defaults();
   private final Map<String, NewIndexType> types = new LinkedHashMap<>();
@@ -73,11 +71,11 @@ public class NewIndex {
     return types;
   }
 
-  public void configureShards(org.sonar.api.config.Settings settings) {
+  public void configureShards(org.sonar.api.config.Settings settings, int defaultNbOfShards) {
     boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ENABLED);
     int shards = settings.getInt(format("sonar.search.%s.shards", indexName));
     if (shards == 0) {
-      shards = DEFAULT_NUMBER_OF_SHARDS;
+      shards = defaultNbOfShards;
     }
     int replicas = settings.getInt(format("sonar.search.%s.replicas", indexName));
     if (replicas == 0) {
index 5bd35dbf275aac15d7f42058a3ae6a5e8c9f72ba..bd37ad5738ada8ff1b868e311e76bd2c3ba38cac 100644 (file)
@@ -91,7 +91,7 @@ public class IssueIndexDefinition implements IndexDefinition {
     NewIndex index = context.create(INDEX);
 
     index.refreshHandledByIndexer();
-    index.configureShards(settings);
+    index.configureShards(settings, 5);
 
     // type "issue"
     NewIndex.NewIndexType issueMapping = index.createType(TYPE_ISSUE);
index 2c74c668d60496256a07d5dee20c92aa3ec5d3c9..2bc703823aaa48b61242aa89cc32bf7dcfd7d771 100644 (file)
@@ -81,7 +81,7 @@ public class RuleIndexDefinition implements IndexDefinition {
     NewIndex index = context.create(INDEX);
 
     index.refreshHandledByIndexer();
-    index.configureShards(settings);
+    index.configureShards(settings, 1);
 
     // Active rule type
     NewIndex.NewIndexType activeRuleMapping = index.createType(RuleIndexDefinition.TYPE_ACTIVE_RULE);
index f5c8569d1ea058c4a3718283924d7f2430c72341..47d8569e5f8b608886ad4e9dbcb616f565315630 100644 (file)
@@ -51,7 +51,7 @@ public class TestIndexDefinition implements IndexDefinition {
     NewIndex index = context.create(INDEX);
 
     index.refreshHandledByIndexer();
-    index.configureShards(settings);
+    index.configureShards(settings, 5);
 
     NewIndex.NewIndexType mapping = index.createType(TYPE);
     mapping.setAttribute("_routing", ImmutableMap.of("required", true));
index 7b7074b2f60f692a35859e92790cf35483d40d36..9dae781355bc82fa60b1abe40b47d2191ec8f6b2 100644 (file)
@@ -54,7 +54,7 @@ public class UserIndexDefinition implements IndexDefinition {
   public void define(IndexDefinitionContext context) {
     NewIndex index = context.create(INDEX);
 
-    index.configureShards(settings);
+    index.configureShards(settings, 1);
 
     index.getSettings()
       // NGram filter (not edge) for logins and names
index 937e489d87ac1111d58211c9ca7f1b0fdbf17082..8edce90f7299db372fae27668d43e3e255b25152 100644 (file)
@@ -45,7 +45,7 @@ public class ViewIndexDefinition implements IndexDefinition {
   public void define(IndexDefinitionContext context) {
     NewIndex index = context.create(INDEX);
 
-    index.configureShards(settings);
+    index.configureShards(settings, 5);
 
     // type "view"
     NewIndex.NewIndexType mapping = index.createType(TYPE_VIEW);
index 17547dc0110aeebf202916c9db7563ab0f902891..2f105eda24d49227bdb5677360fda57c2c7db02d 100644 (file)
@@ -125,8 +125,8 @@ public class NewIndexTest {
   @Test
   public void default_shards_and_replicas() {
     NewIndex index = new NewIndex("issues");
-    index.configureShards(new MapSettings());
-    assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
+    index.configureShards(new MapSettings(), 5);
+    assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("5");
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("0");
   }
 
@@ -135,8 +135,8 @@ public class NewIndexTest {
     NewIndex index = new NewIndex("issues");
     MapSettings settings = new MapSettings();
     settings.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
-    index.configureShards(settings);
-    assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
+    index.configureShards(settings, 5);
+    assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("5");
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("1");
   }
 
@@ -145,7 +145,7 @@ public class NewIndexTest {
     NewIndex index = new NewIndex("issues");
     MapSettings settings = new MapSettings();
     settings.setProperty("sonar.search.issues.shards", "3");
-    index.configureShards(settings);
+    index.configureShards(settings, 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("3");
     // keep default value
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("0");
@@ -157,7 +157,7 @@ public class NewIndexTest {
     MapSettings settings = new MapSettings();
     settings.setProperty("sonar.search.issues.shards", "3");
     settings.setProperty("sonar.search.issues.replicas", "1");
-    index.configureShards(settings);
+    index.configureShards(settings, 5);
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("3");
     assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("1");
   }
index 4e4f125f21ecab34b5971ebc59be02f0341e11a7..f781da432adc8fa06eb86a1560a2249ccdf9f938 100644 (file)
@@ -41,7 +41,7 @@ public class IssueIndexDefinitionTest {
     assertThat(issuesIndex.getTypes().keySet()).containsOnly("issue", "authorization");
 
     // no cluster by default
-    assertThat(issuesIndex.getSettings().get("index.number_of_shards")).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
+    assertThat(issuesIndex.getSettings().get("index.number_of_shards")).isEqualTo("5");
     assertThat(issuesIndex.getSettings().get("index.number_of_replicas")).isEqualTo("0");
   }
 }
index 4232eff33faf33a9996048747a436143430dff7a..5ccbbd0001543a850876e44d303b6a1cfe8e85ad 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.MapSettings;
 import org.sonar.server.es.EsTester;
-import org.sonar.server.es.NewIndex;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -71,7 +70,7 @@ public class EsMonitorTest {
     assertThat(indicesAttributes).hasSize(1);
     Map indexAttributes = (Map) indicesAttributes.values().iterator().next();
     assertThat(indexAttributes.get("Docs")).isEqualTo(0L);
-    assertThat(indexAttributes.get("Shards")).isEqualTo(NewIndex.DEFAULT_NUMBER_OF_SHARDS);
+    assertThat((int) indexAttributes.get("Shards")).isGreaterThan(0);
     assertThat(indexAttributes.get("Store Size")).isNotNull();
   }
 }
index c6d7dc6d217c02e36ac3477ec1244def7fff32fb..2e98aa5afd554a1eadea3bd6c20d345934bcf2da 100644 (file)
@@ -57,7 +57,7 @@ public class RuleIndexDefinitionTest {
     assertThat(ruleIndex.getTypes().keySet()).containsOnly("rule", "activeRule");
 
     // no cluster by default
-    assertThat(ruleIndex.getSettings().get("index.number_of_shards")).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
+    assertThat(ruleIndex.getSettings().get("index.number_of_shards")).isEqualTo("1");
     assertThat(ruleIndex.getSettings().get("index.number_of_replicas")).isEqualTo("0");
   }
 
index d50fc0ce5520b045666fd31f75f648ea544708a3..add9d3bb697d9e4154bd7a89c16cefbe45385599 100644 (file)
@@ -41,7 +41,7 @@ public class UserIndexDefinitionTest {
     assertThat(index.getTypes().keySet()).containsOnly("user");
 
     // no cluster by default
-    assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
+    assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo("1");
     assertThat(index.getSettings().get("index.number_of_replicas")).isEqualTo("0");
   }
 }
index 34db1eac5191eb55ae3e4016e0dee96d839e1967..bbe951dbba8909e4f05e1412b223cba5c4040ca8 100644 (file)
@@ -40,7 +40,7 @@ public class ViewIndexDefinitionTest {
     assertThat(index).isNotNull();
     assertThat(index.getTypes().keySet()).containsOnly("view");
 
-    assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
+    assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo("5");
     assertThat(index.getSettings().get("index.number_of_replicas")).isEqualTo("0");
   }
 }