From ab57d4a00291322af578a8841de6d0d54eb8f4df Mon Sep 17 00:00:00 2001 From: javanna Date: Sat, 30 Aug 2014 12:48:57 +0200 Subject: [PATCH] [TEST] Unify the randomization logic for number of shards and replicas We currently have two ways to randomize the number of shards and replicas: random index template, that stays the same for all indices created under the same scope, and the overridable `indexSettings` method, called by `createIndex` and `prepareCreate` which returns different values each time. Now that the `randomIndexTemplate` method is not static anymore, we can easily apply the same logic to both. Especially for number of replicas, we used to have slightly different behaviours, where more than one replicas were only rarely used through random index template, which gets now applied to the `indexSettings` method too (might speed up the tests a bit) Side note: `randomIndexTemplate` had its own logic which didn't depend on `numberOfReplicas` or `maximumNumberOfReplicas`, which was causing bw comp tests failures since in some cases too many copies of the data are requested, which cannot be allocated to older nodes, and the write consistency quorum cannot be met, thus indexing times out. Closes #7522 --- .../elasticsearch/test/ElasticsearchIntegrationTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 69b4d79d2e9..f7062a94994 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -334,9 +334,8 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase .put(SETTING_INDEX_SEED, getRandom().nextLong()); if (randomizeNumberOfShardsAndReplicas()) { - randomSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, between(DEFAULT_MIN_NUM_SHARDS, DEFAULT_MAX_NUM_SHARDS)) - //use either 0 or 1 replica, yet a higher amount when possible, but only rarely - .put(SETTING_NUMBER_OF_REPLICAS, between(0, getRandom().nextInt(10) > 0 ? 1 : cluster().numDataNodes() - 1)); + randomSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, numberOfShards()) + .put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas()); } XContentBuilder mappings = null; if (frequently() && randomDynamicTemplates()) { @@ -681,7 +680,9 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } protected int maximumNumberOfReplicas() { - return Math.max(0, cluster().numDataNodes() - 1); + //use either 0 or 1 replica, yet a higher amount when possible, but only rarely + int maxNumReplicas = Math.max(0, cluster().numDataNodes() - 1); + return frequently() ? Math.min(1, maxNumReplicas) : maxNumReplicas; } protected int numberOfReplicas() {