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<>();
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) {
NewIndex index = context.create(INDEX);
index.refreshHandledByIndexer();
- index.configureShards(settings);
+ index.configureShards(settings, 5);
// type "issue"
NewIndex.NewIndexType issueMapping = index.createType(TYPE_ISSUE);
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);
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));
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
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);
@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");
}
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");
}
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");
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");
}
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");
}
}
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;
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();
}
}
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");
}
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");
}
}
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");
}
}