Skip to content

Commit

Permalink
Remove leftover code from one shard by default (#42374)
Browse files Browse the repository at this point in the history
We had some logic to determine the number of shards, it was based on the
index version created. Now that master would only ever see index
versions created >= 7.0.0, this logic is no longer needed. This commit
removes this dead code.
  • Loading branch information
jasontedor authored May 23, 2019
1 parent 13dc1cf commit 733e589
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.cluster.metadata;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
Expand Down Expand Up @@ -386,8 +385,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
indexSettingsBuilder.put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(), createdVersion);
}
if (indexSettingsBuilder.get(SETTING_NUMBER_OF_SHARDS) == null) {
final int numberOfShards = getNumberOfShards(indexSettingsBuilder);
indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, settings.getAsInt(SETTING_NUMBER_OF_SHARDS, numberOfShards));
indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 1));
}
if (indexSettingsBuilder.get(SETTING_NUMBER_OF_REPLICAS) == null) {
indexSettingsBuilder.put(SETTING_NUMBER_OF_REPLICAS, settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
Expand Down Expand Up @@ -589,21 +587,6 @@ public ClusterState execute(ClusterState currentState) throws Exception {
}
}

static int getNumberOfShards(final Settings.Builder indexSettingsBuilder) {
// TODO: this logic can be removed when the current major version is 8
// TODO: https://github.com/elastic/elasticsearch/issues/38556
// assert Version.CURRENT.major == 7;
final int numberOfShards;
final Version indexVersionCreated =
Version.fromId(Integer.parseInt(indexSettingsBuilder.get(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey())));
if (indexVersionCreated.before(Version.V_7_0_0)) {
numberOfShards = 5;
} else {
numberOfShards = 1;
}
return numberOfShards;
}

@Override
public void onFailure(String source, Exception e) {
if (e instanceof ResourceAlreadyExistsException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ public static boolean isSplitable(int source, int target) {
return source * x == target;
}

public void testNumberOfShards() {
{
final Version versionCreated = VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.CURRENT);
final Settings.Builder indexSettingsBuilder = Settings.builder().put(SETTING_VERSION_CREATED, versionCreated);
assertThat(MetaDataCreateIndexService.IndexCreationTask.getNumberOfShards(indexSettingsBuilder), equalTo(1));
}
}

public void testValidateShrinkIndex() {
int numShards = randomIntBetween(2, 42);
ClusterState state = createClusterState("source", numShards, randomIntBetween(0, 10),
Expand Down

0 comments on commit 733e589

Please sign in to comment.