Skip to content

Automatically prepare indices for splitting #27451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
005215e
Automatically prepare indices for splitting
s1monw Nov 16, 2017
4072379
prevent automatic num routing shards for pre 7.0 indices
s1monw Nov 20, 2017
6ab582e
fix auto routing shards for 1 shard source indices
s1monw Nov 20, 2017
0e3fbbb
Merge branch 'master' into prepare_for_split
s1monw Nov 20, 2017
6d90ad8
add additional verification for broken split setups
s1monw Nov 20, 2017
e4da795
fix test:
s1monw Nov 21, 2017
033c6ad
Merge branch 'master' into prepare_for_split
s1monw Nov 21, 2017
fb13969
Improved index-split docs
clintongormley Nov 21, 2017
27a6d34
apply review comments
s1monw Nov 21, 2017
71f5c35
Merge pull request #3 from clintongormley/prepare_for_split
s1monw Nov 21, 2017
9262c9e
fix unittest
s1monw Nov 21, 2017
8482a60
stabelize SplitIndexIT
s1monw Nov 21, 2017
6fe2bff
Fix routing test to actually be sane
s1monw Nov 21, 2017
b02b9f3
fix SharedSignificantTermsTestMethods tests
s1monw Nov 21, 2017
8176378
fix SimpleRoutingIT again
s1monw Nov 22, 2017
1f46ce3
use a factor but incompatible one
s1monw Nov 22, 2017
a6616cd
bound num routing shards to 1024
s1monw Nov 22, 2017
b2a9a08
fix comments
s1monw Nov 22, 2017
dccad0b
fix tests for new hashing
s1monw Nov 22, 2017
36aca55
Merge branch 'master' into prepare_for_split
s1monw Nov 22, 2017
1cd9c78
Merge branch 'master' into prepare_for_split
s1monw Nov 22, 2017
e820289
Merge branch 'master' into prepare_for_split
s1monw Nov 22, 2017
791c2f1
Merge branch 'master' into prepare_for_split
s1monw Nov 23, 2017
4db1b97
add note to migration guide
s1monw Nov 23, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void testSearchWithMatrixStats() throws IOException {
assertEquals(5, matrixStats.getFieldCount("num"));
assertEquals(56d, matrixStats.getMean("num"), 0d);
assertEquals(1830d, matrixStats.getVariance("num"), 0d);
assertEquals(0.09340198804973057, matrixStats.getSkewness("num"), 0d);
assertEquals(0.09340198804973046, matrixStats.getSkewness("num"), 0d);
assertEquals(1.2741646510794589, matrixStats.getKurtosis("num"), 0d);
assertEquals(5, matrixStats.getFieldCount("num2"));
assertEquals(29d, matrixStats.getMean("num2"), 0d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1344,13 +1344,17 @@ public static ShardId selectSplitShard(int shardId, IndexMetaData sourceIndexMet
}
int routingFactor = getRoutingFactor(numSourceShards, numTargetShards);
// now we verify that the numRoutingShards is valid in the source index
int routingNumShards = sourceIndexMetadata.getRoutingNumShards();
// note: if the number of shards is 1 in the source index we can just assume it's correct since from 1 we can split into anything
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand ot's important here to bypass the assertions as we don't have any relationship between the source routing shards and the target one in the case where the source has only one physical shards. I think the "validate this in various places in the code" part is maybe a leftover from a previous iteration?

// this is important to special case here since we use this to validate this in various places in the code but allow to split form
// 1 to N but we never modify the sourceIndexMetadata to accommodate for that
int routingNumShards = numSourceShards == 1 ? numTargetShards : sourceIndexMetadata.getRoutingNumShards();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe do something like:

final int selectedShard;
if (numSourceShards == 1) {
  selectedShard = 0;
} else {
  ... the current logic...
  selectedShard = shardId/routingFactor;
}
return new ShardId(sourceIndexMetadata.getIndex(), selectedShard);

will be easier to read , I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also s/form/from/

if (routingNumShards % numTargetShards != 0) {
throw new IllegalStateException("the number of routing shards ["
+ routingNumShards + "] must be a multiple of the target shards [" + numTargetShards + "]");
}
// this is just an additional assertion that ensures we are a factor of the routing num shards.
assert getRoutingFactor(numTargetShards, sourceIndexMetadata.getRoutingNumShards()) >= 0;
assert sourceIndexMetadata.getNumberOfShards() == 1 // special case - we can split into anything from 1 shard
|| getRoutingFactor(numTargetShards, routingNumShards) >= 0;
return new ShardId(sourceIndexMetadata.getIndex(), shardId/routingFactor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,28 @@ public ClusterState execute(ClusterState currentState) throws Exception {
indexSettingsBuilder.put(IndexMetaData.SETTING_INDEX_PROVIDED_NAME, request.getProvidedName());
indexSettingsBuilder.put(SETTING_INDEX_UUID, UUIDs.randomBase64UUID());
final IndexMetaData.Builder tmpImdBuilder = IndexMetaData.builder(request.index());

final Settings idxSettings = indexSettingsBuilder.build();
int numTargetShards = IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(idxSettings);
final int routingNumShards;
final Version indexVersionCreated = idxSettings.getAsVersion(IndexMetaData.SETTING_VERSION_CREATED, null);
if (recoverFromIndex == null) {
Settings idxSettings = indexSettingsBuilder.build();
routingNumShards = IndexMetaData.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.get(idxSettings);
if (IndexMetaData.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.exists(idxSettings)) {
routingNumShards = IndexMetaData.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.get(idxSettings);
} else {
routingNumShards = calculateNumRoutingShards(numTargetShards, indexVersionCreated);
}
} else {
assert IndexMetaData.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.exists(indexSettingsBuilder.build()) == false
: "index.number_of_routing_shards should be present on the target index on resize";
: "index.number_of_routing_shards should not be present on the target index on resize";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

final IndexMetaData sourceMetaData = currentState.metaData().getIndexSafe(recoverFromIndex);
routingNumShards = sourceMetaData.getRoutingNumShards();
if (shouldAutoCalculateNumRoutingShards(numTargetShards, sourceMetaData.getNumberOfShards(),
sourceMetaData.getRoutingNumShards())) {
// in this case we have a source index with 1 shard and without an explicit split factor
// or one that is valid in that case we can split into whatever and auto-generate a new factor.
routingNumShards = calculateNumRoutingShards(numTargetShards, indexVersionCreated);
} else {
routingNumShards = sourceMetaData.getRoutingNumShards();
}
}
// remove the setting it's temporary and is only relevant once we create the index
indexSettingsBuilder.remove(IndexMetaData.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey());
Expand Down Expand Up @@ -717,4 +729,37 @@ static void prepareResizeIndexSettings(ClusterState currentState, Set<String> ma
.put(IndexMetaData.INDEX_RESIZE_SOURCE_NAME.getKey(), resizeSourceIndex.getName())
.put(IndexMetaData.INDEX_RESIZE_SOURCE_UUID.getKey(), resizeSourceIndex.getUUID());
}

/**
* Returns a default number of routing shards based on the number of shards of the index. The default number of routing shards will
* allow any index to be split at least once and at most 10 times by a factor of two. The closer the number or shards gets to 1024
* the less default split operations are supported
*/
public static int calculateNumRoutingShards(int numShards, Version indexVersionCreated) {
if (indexVersionCreated.onOrAfter(Version.V_7_0_0_alpha1)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you clarify why this needs to be version dependent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a comment in the line below?!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I get this means we only do the new behavior until the cluster is fully upgraded, but I don't see why we care? I mean, if the master is a 7.0.0 master, we can start creating indices with a different hashing logic and not worry about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's mainly for testing purposes and BWC behavior being more predictable otherwise some rest tests will randomly fail

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh well :)

// only select this automatically for indices that are created on or after 7.0
int base = 10; // logBase2(1024)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth sharing the 1024 constant with the max value in buildNumberOfShardsSetting to be clearer where this comes from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how you envisioned this to work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking of having a public static final int DEFAULT_MAX_NUM_SHARDS = 1024 somewhere, and use it in buildNumberOfShardsSetting and here: int base = Math.log(DEFAULT_MAX_NUM_SHARDS)/Math.log(2)

return numShards * 1 << Math.max(1, (base - (int) (Math.log(numShards) / Math.log(2))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit weird to me that this will generate numbers that are greater than the maximum number of shards. Should we change the formula a bit so that the result is always in 513...1024 when the number of shards is in 1..512?

This probably deserves some comments as well, eg. I presume that the fact we do Math.max(1, ...) instead of Math.max(0, ...) is to make sure that we can always split at least once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I will do that.

} else {
return numShards;
}
}


/**
* Returns <code>true</code> iff the we should calculate the number of routing shards for the split index based on
* the source index. This only applies to source indices that have only 1 shards. We don't want to recalculate the num routing
* shards on indices that already have a valid number of routing shards.
*/
static boolean shouldAutoCalculateNumRoutingShards(int numTargetShards, int numSourceShards, int numSourceRoutingShards) {
if (numSourceShards == 1) {
if (numSourceRoutingShards < numTargetShards) {
// we have a source index that has less routing shards than our target shards -- we should reset
return true;
}
int factor = numSourceRoutingShards / numTargetShards;
return factor * numTargetShards != numSourceRoutingShards || factor <= 1;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public void testInvalidPartitionSize() {
response = prepareCreate("test_" + shards + "_" + partitionSize)
.setSettings(Settings.builder()
.put("index.number_of_shards", shards)
.put("index.number_of_routing_shards", shards)
.put("index.routing_partition_size", partitionSize))
.execute().actionGet();
} catch (IllegalStateException | IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.Murmur3HashFunction;
import org.elasticsearch.cluster.routing.ShardRouting;
Expand Down Expand Up @@ -66,7 +67,6 @@
import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.IntFunction;
import java.util.stream.IntStream;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
Expand All @@ -88,21 +88,31 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
}

public void testCreateSplitIndexToN() throws IOException {
int[][] possibleShardSplits = new int[][] {{2,4,8}, {3, 6, 12}, {1, 2, 4}};
int[][] possibleShardSplits = new int[][]{{2, 4, 8}, {3, 6, 12}, {1, 2, 4}};
int[] shardSplits = randomFrom(possibleShardSplits);
splitToN(shardSplits);
}

public void testSplitFromOneToN() {
splitToN(1, 5, 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you had an explicit reason not to have a shrink to one shard then split again test (where we can take values in the split that doesn't compute with the source index)? alternatively we can explicitly set the routing shards on the source index to something that doesn't make sense when we start.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand what you mean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test now start with 1 shard source and the split twice. both of these always have a valid number of routing shards in the source index. I think the interesting part of the test is see how we reset the number of routing shard. For example, start with a 3 shards index. Shrink to 1 (number of routing shards stays 3) then split to say, 2. Does that help?

client().admin().indices().prepareDelete("*").get();
int randomSplit = randomIntBetween(2, 6);
splitToN(1, randomSplit, randomSplit * 2);
}

private void splitToN(int... shardSplits) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why you did it this way as it was easier to refactor, but I think we should bite the bullet and give these proper variable names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, I will do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what woud you name it a, b, c :D I mean I can do step1, step2, step3 not sure how much it will by us ot's jiust a test

assertEquals(3, shardSplits.length);
assertEquals(shardSplits[0], (shardSplits[0] * shardSplits[1]) / shardSplits[1]);
assertEquals(shardSplits[1], (shardSplits[1] * shardSplits[2]) / shardSplits[2]);
internalCluster().ensureAtLeastNumDataNodes(2);
final boolean useRouting = randomBoolean();
final boolean useNested = randomBoolean();
final boolean useMixedRouting = useRouting ? randomBoolean() : false;
CreateIndexRequestBuilder createInitialIndex = prepareCreate("source");
final int routingShards = shardSplits[2] * randomIntBetween(1, 10);
Settings.Builder settings = Settings.builder().put(indexSettings())
.put("number_of_shards", shardSplits[0])
.put("index.number_of_routing_shards", routingShards);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we randomly still do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can.. I will do it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Settings.Builder settings = Settings.builder().put(indexSettings()).put("number_of_shards", shardSplits[0]);
if (useRouting && useMixedRouting == false && randomBoolean()) {
settings.put("index.routing_partition_size", randomIntBetween(1, routingShards - 1));
settings.put("index.routing_partition_size", randomIntBetween(1, MetaDataCreateIndexService.calculateNumRoutingShards
(shardSplits[0], Version.CURRENT) -1));
if (useNested) {
createInitialIndex.addMapping("t1", "_routing", "required=true", "nested1", "type=nested");
} else {
Expand Down Expand Up @@ -340,7 +350,6 @@ public void testCreateSplitIndex() {
prepareCreate("source").setSettings(Settings.builder().put(indexSettings())
.put("number_of_shards", 1)
.put("index.version.created", version)
.put("index.number_of_routing_shards", 2)
).get();
final int docs = randomIntBetween(0, 128);
for (int i = 0; i < docs; i++) {
Expand Down Expand Up @@ -443,7 +452,6 @@ public void testCreateSplitWithIndexSort() throws Exception {
Settings.builder()
.put(indexSettings())
.put("sort.field", "id")
.put("index.number_of_routing_shards", 16)
.put("sort.order", "desc")
.put("number_of_shards", 2)
.put("number_of_replicas", 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.ResourceAlreadyExistsException;
Expand Down Expand Up @@ -299,4 +298,39 @@ private void validateIndexName(String indexName, String errorMessage) {
.getDefault(Settings.EMPTY)).build()));
assertThat(e.getMessage(), endsWith(errorMessage));
}

public void testShouldAutoCalculateNumRoutingShards() {
assertTrue(MetaDataCreateIndexService.shouldAutoCalculateNumRoutingShards(2, 1, 1));
assertFalse(MetaDataCreateIndexService.shouldAutoCalculateNumRoutingShards(10, 1, 20));
assertTrue(MetaDataCreateIndexService.shouldAutoCalculateNumRoutingShards(10, 1, 5));
assertTrue(MetaDataCreateIndexService.shouldAutoCalculateNumRoutingShards(10, 1, 16));
assertFalse(MetaDataCreateIndexService.shouldAutoCalculateNumRoutingShards(2, 1, 8));
}

public void testCalculateNumRoutingShards() {
assertEquals(1024, MetaDataCreateIndexService.calculateNumRoutingShards(1, Version.CURRENT));
assertEquals(1024, MetaDataCreateIndexService.calculateNumRoutingShards(2, Version.CURRENT));
assertEquals(1536, MetaDataCreateIndexService.calculateNumRoutingShards(3, Version.CURRENT));
assertEquals(1152, MetaDataCreateIndexService.calculateNumRoutingShards(9, Version.CURRENT));
assertEquals(1024, MetaDataCreateIndexService.calculateNumRoutingShards(512, Version.CURRENT));
assertEquals(2048, MetaDataCreateIndexService.calculateNumRoutingShards(1024, Version.CURRENT));
assertEquals(4096, MetaDataCreateIndexService.calculateNumRoutingShards(2048, Version.CURRENT));

Version latestV6 = VersionUtils.getPreviousVersion(Version.V_7_0_0_alpha1);
int numShards = randomIntBetween(1, 1000);
assertEquals(numShards, MetaDataCreateIndexService.calculateNumRoutingShards(numShards, latestV6));
assertEquals(numShards, MetaDataCreateIndexService.calculateNumRoutingShards(numShards,
VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), latestV6)));

for (int i = 0; i < 1000; i++) {
int randomNumShards = randomIntBetween(1, 10000);
int numRoutingShards = MetaDataCreateIndexService.calculateNumRoutingShards(randomNumShards, Version.CURRENT);
double ratio = numRoutingShards / randomNumShards;
int intRatio = (int) ratio;
assertEquals(ratio, (double)(intRatio), 0.0d);
assertTrue(1 < ratio);
assertTrue(ratio <= 1024);
assertEquals(0, intRatio % 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we assert that intRatio is a power of two by checking that intRatio & (intRatio - 1) is zero? (or intRatio == Integer.highestOneBit(intRatio) if you find it easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

public class OperationRoutingTests extends ESTestCase{


public void testGenerateShardId() {
int[][] possibleValues = new int[][] {
{8,4,2}, {20, 10, 2}, {36, 12, 3}, {15,5,1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public void testQueryRewrite() throws Exception {
Client client = client();
assertAcked(client.admin().indices().prepareCreate("index").addMapping("type", "s", "type=date")
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)).get());
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5).put("index.number_of_routing_shards", 5)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)).get());
indexRandom(true, client.prepareIndex("index", "type", "1").setRouting("1").setSource("s", "2016-03-19"),
client.prepareIndex("index", "type", "2").setRouting("1").setSource("s", "2016-03-20"),
client.prepareIndex("index", "type", "3").setRouting("1").setSource("s", "2016-03-21"),
Expand Down Expand Up @@ -362,7 +363,8 @@ public void testQueryRewriteDatesWithNow() throws Exception {
public void testCanCache() throws Exception {
Client client = client();
Settings settings = Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2).put("index.number_of_routing_shards", 2)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
assertAcked(client.admin().indices().prepareCreate("index").addMapping("type", "s", "type=date")
.setSettings(settings)
.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,15 +840,17 @@ public void testPartitionedTemplate() throws Exception {
// create an index with too few shards
IllegalArgumentException eBadIndex = expectThrows(IllegalArgumentException.class,
() -> prepareCreate("test_bad", Settings.builder()
.put("index.number_of_shards", 5))
.put("index.number_of_shards", 5)
.put("index.number_of_routing_shards", 5))
.get());

assertThat(eBadIndex.getMessage(), containsString("partition size [6] should be a positive number "
+ "less than the number of shards [5]"));

// finally, create a valid index
prepareCreate("test_good", Settings.builder()
.put("index.number_of_shards", 7))
.put("index.number_of_shards", 7)
.put("index.number_of_routing_shards", 7))
.get();

GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test_good").get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.ESIntegTestCase;
Expand Down Expand Up @@ -196,6 +198,13 @@ public void testAliasSearchRouting() throws Exception {

}

@Override
public Settings indexSettings() {
Settings settings = super.indexSettings();
int numShards = IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(settings);
return Settings.builder().put(settings).put("index.number_of_routing_shards", numShards).build();
}

public void testAliasSearchRoutingWithTwoIndices() throws Exception {
createIndex("test-a");
createIndex("test-b");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void testVariousPartitionSizes() throws Exception {
client().admin().indices().prepareCreate(index)
.setSettings(Settings.builder()
.put("index.number_of_shards", shards)
.put("index.number_of_routing_shards", shards)
.put("index.routing_partition_size", partitionSize))
.addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON)
.execute().actionGet();
Expand All @@ -67,6 +68,7 @@ public void testShrinking() throws Exception {
client().admin().indices().prepareCreate(index)
.setSettings(Settings.builder()
.put("index.number_of_shards", currentShards)
.put("index.number_of_routing_shards", currentShards)
.put("index.number_of_replicas", numberOfReplicas())
.put("index.routing_partition_size", partitionSize))
.addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void testExplainWithRewriteValidateQuery() throws Exception {
public void testExplainWithRewriteValidateQueryAllShards() throws Exception {
client().admin().indices().prepareCreate("test")
.addMapping("type1", "field", "type=text,analyzer=whitespace")
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2)).get();
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put("index.number_of_routing_shards", 2)).get();
// We are relying on specific routing behaviors for the result to be right, so
// we cannot randomize the number of shards or change ids here.
client().prepareIndex("test", "type1", "1")
Expand Down
7 changes: 7 additions & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ buildRestTests.setups['sales'] = '''

// Dummy bank account data used by getting-started.asciidoc
buildRestTests.setups['bank'] = '''
- do:
indices.create:
index: bank
body:
settings:
number_of_shards: 5
number_of_routing_shards: 5
- do:
bulk:
index: bank
Expand Down
Loading