Skip to content

Commit 4a4e3d7

Browse files
authored
Default to one shard (#30539)
This commit changes the default out-of-the-box configuration for the number of shards from five to one. We think this will help address a common problem of oversharding. For users with time-based indices that need a different default, this can be managed with index templates. For users with non-time-based indices that find they need to re-shard with the split API in place they no longer need to resort only to reindexing. Since this has the impact of changing the default number of shards used in REST tests, we want to ensure that we still have coverage for issues that could arise from multiple shards. As such, we randomize (rarely) the default number of shards in REST tests to two. This is managed via a global index template. However, some tests check the templates that are in the cluster state during the test. Since this template is randomly there, we need a way for tests to skip adding the template used to set the number of shards to two. For this we add the default_shards feature skip. To avoid having to write our docs in a complicated way because sometimes they might be behind one shard, and sometimes they might be behind two shards we apply the default_shards feature skip to all docs tests. That is, these tests will always run with the default number of shards (one).
1 parent af10fd6 commit 4a4e3d7

File tree

43 files changed

+232
-157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+232
-157
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
225225
* warning every time. */
226226
current.println(" - skip:")
227227
current.println(" features: ")
228+
current.println(" - default_shards")
228229
current.println(" - stash_in_key")
229230
current.println(" - stash_in_path")
230231
current.println(" - stash_path_replace")

client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,14 @@ public void testSearchWithMatrixStats() throws IOException {
312312
MatrixStats matrixStats = searchResponse.getAggregations().get("agg1");
313313
assertEquals(5, matrixStats.getFieldCount("num"));
314314
assertEquals(56d, matrixStats.getMean("num"), 0d);
315-
assertEquals(1830d, matrixStats.getVariance("num"), 0d);
316-
assertEquals(0.09340198804973046, matrixStats.getSkewness("num"), 0d);
315+
assertEquals(1830.0000000000002, matrixStats.getVariance("num"), 0d);
316+
assertEquals(0.09340198804973039, matrixStats.getSkewness("num"), 0d);
317317
assertEquals(1.2741646510794589, matrixStats.getKurtosis("num"), 0d);
318318
assertEquals(5, matrixStats.getFieldCount("num2"));
319319
assertEquals(29d, matrixStats.getMean("num2"), 0d);
320320
assertEquals(330d, matrixStats.getVariance("num2"), 0d);
321321
assertEquals(-0.13568039346585542, matrixStats.getSkewness("num2"), 1.0e-16);
322-
assertEquals(1.3517561983471074, matrixStats.getKurtosis("num2"), 0d);
322+
assertEquals(1.3517561983471071, matrixStats.getKurtosis("num2"), 0d);
323323
assertEquals(-767.5, matrixStats.getCovariance("num", "num2"), 0d);
324324
assertEquals(-0.9876336291667923, matrixStats.getCorrelation("num", "num2"), 0d);
325325
}

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ public void testRankEval() throws Exception {
800800
double qualityLevel = evalQuality.getQualityLevel(); // <3>
801801
assertEquals(1.0 / 3.0, qualityLevel, 0.0);
802802
List<RatedSearchHit> hitsAndRatings = evalQuality.getHitsAndRatings();
803-
RatedSearchHit ratedSearchHit = hitsAndRatings.get(0);
803+
RatedSearchHit ratedSearchHit = hitsAndRatings.get(2);
804804
assertEquals("3", ratedSearchHit.getSearchHit().getId()); // <4>
805805
assertFalse(ratedSearchHit.getRating().isPresent()); // <5>
806806
MetricDetail metricDetails = evalQuality.getMetricDetails();

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/CreatedLocationHeaderIT.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@
2121

2222
import org.apache.http.entity.ContentType;
2323
import org.apache.http.entity.StringEntity;
24+
import org.elasticsearch.client.Request;
2425
import org.elasticsearch.client.Response;
26+
import org.junit.Before;
2527

2628
import java.io.IOException;
2729

2830
import static java.util.Collections.emptyMap;
2931
import static java.util.Collections.singletonMap;
32+
import static org.hamcrest.Matchers.equalTo;
3033
import static org.hamcrest.Matchers.startsWith;
3134

3235
/**
3336
* Tests for the "Location" header returned when returning {@code 201 CREATED}.
3437
*/
3538
public class CreatedLocationHeaderIT extends ESRestTestCase {
39+
3640
public void testCreate() throws IOException {
3741
locationTestCase("PUT", "test/test/1");
3842
}
@@ -54,8 +58,11 @@ public void testUpsert() throws IOException {
5458
private void locationTestCase(String method, String url) throws IOException {
5559
locationTestCase(client().performRequest(method, url, emptyMap(),
5660
new StringEntity("{\"test\": \"test\"}", ContentType.APPLICATION_JSON)));
61+
// we have to delete the index otherwise the second indexing request will route to the single shard and not produce a 201
62+
final Response response = client().performRequest(new Request("DELETE", "test"));
63+
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
5764
locationTestCase(client().performRequest(method, url + "?routing=cat", emptyMap(),
58-
new StringEntity("{\"test\": \"test\"}", ContentType.APPLICATION_JSON)));
65+
new StringEntity("{\"test\": \"test\"}", ContentType.APPLICATION_JSON)));
5966
}
6067

6168
private void locationTestCase(Response response) throws IOException {
@@ -65,4 +72,5 @@ private void locationTestCase(Response response) throws IOException {
6572
Response getResponse = client().performRequest("GET", location);
6673
assertEquals(singletonMap("test", "test"), entityAsMap(getResponse).get("_source"));
6774
}
75+
6876
}

docs/reference/aggregations/bucket/children-aggregation.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ Possible response:
137137
"took": 25,
138138
"timed_out": false,
139139
"_shards": {
140-
"total": 5,
141-
"successful": 5,
140+
"total": 1,
141+
"successful": 1,
142142
"skipped" : 0,
143143
"failed": 0
144144
},

docs/reference/aggregations/metrics/geocentroid-aggregation.asciidoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ The response for the above aggregation:
6060
"aggregations": {
6161
"centroid": {
6262
"location": {
63-
"lat": 51.00982963806018,
64-
"lon": 3.9662131061777472
63+
"lat": 51.009829603135586,
64+
"lon": 3.9662130642682314
6565
},
6666
"count": 6
6767
}
@@ -113,8 +113,8 @@ The response for the above aggregation:
113113
"doc_count": 3,
114114
"centroid": {
115115
"location": {
116-
"lat": 52.371655656024814,
117-
"lon": 4.909563297405839
116+
"lat": 52.371655642054975,
117+
"lon": 4.9095632415264845
118118
},
119119
"count": 3
120120
}
@@ -125,7 +125,7 @@ The response for the above aggregation:
125125
"centroid": {
126126
"location": {
127127
"lat": 48.86055548675358,
128-
"lon": 2.3316944623366
128+
"lon": 2.331694420427084
129129
},
130130
"count": 2
131131
}

docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ The output from the above is:
235235
"timed_out": false,
236236
"took": $body.took,
237237
"_shards": {
238-
"total": 5,
239-
"successful": 5,
238+
"total": 1,
239+
"successful": 1,
240240
"skipped" : 0,
241241
"failed": 0
242242
},

docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ GET my_index/_search
294294
"took": $body.took,
295295
"timed_out": false,
296296
"_shards": {
297-
"total": 5,
298-
"successful": 5,
297+
"total": 1,
298+
"successful": 1,
299299
"skipped" : 0,
300300
"failed": 0
301301
},

docs/reference/api-conventions.asciidoc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,7 @@ Responds:
300300
"indices": {
301301
"twitter": {
302302
"shards": {
303-
"0": [{"state": "STARTED"}, {"state": "UNASSIGNED"}],
304-
"1": [{"state": "STARTED"}, {"state": "UNASSIGNED"}],
305-
"2": [{"state": "STARTED"}, {"state": "UNASSIGNED"}],
306-
"3": [{"state": "STARTED"}, {"state": "UNASSIGNED"}],
307-
"4": [{"state": "STARTED"}, {"state": "UNASSIGNED"}]
303+
"0": [{"state": "STARTED"}, {"state": "UNASSIGNED"}]
308304
}
309305
}
310306
}

docs/reference/cat/allocation.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Might respond with:
1616
[source,txt]
1717
--------------------------------------------------
1818
shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
19-
5 260b 47.3gb 43.4gb 100.7gb 46 127.0.0.1 127.0.0.1 CSUXak2
19+
1 260b 47.3gb 43.4gb 100.7gb 46 127.0.0.1 127.0.0.1 CSUXak2
2020
--------------------------------------------------
2121
// TESTRESPONSE[s/\d+(\.\d+)?[tgmk]?b/\\d+(\\.\\d+)?[tgmk]?b/ s/46/\\d+/]
2222
// TESTRESPONSE[s/CSUXak2/.+/ _cat]

0 commit comments

Comments
 (0)