Skip to content

Commit e325ce1

Browse files
committed
Warn of change of default of wait_for_active_shards
In 7.x the close indices API defaults to `?wait_for_active_shards=0` but from 8.0 it will default to respecting the index settings instead. This commit introduces the `index-setting` value for this parameter on this API allowing users to opt-in to the future behaviour today, and starts to emit a deprecation warning for users that use the default. Relates elastic#67158 Closes elastic#66419
1 parent 47e3a0c commit e325ce1

File tree

38 files changed

+114
-5
lines changed

38 files changed

+114
-5
lines changed

docs/reference/indices/close.asciidoc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,18 @@ Defaults to `open`.
5252

5353
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
5454

55-
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
55+
`wait_for_active_shards`::
56+
+
57+
--
58+
(Optional, string) The number of shard copies that must be active before
59+
proceeding with the operation. Set to `all`, `index-setting`, or any positive
60+
integer up to the total number of shards in the index (`number_of_replicas+1`).
61+
The value `index-setting` means to wait according to the index setting
62+
`index.write.wait_for_active_shards`. Default: `0`, meaning do not wait for any
63+
shards to be ready.
64+
65+
See <<index-wait-for-active-shards>>.
66+
--
5667

5768
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
5869

plugins/repository-hdfs/src/test/resources/rest-api-spec/test/hdfs_repository/40_restore.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
# Close index
4747
- do:
4848
indices.close:
49+
wait_for_active_shards: 0
4950
index : test_index
5051

5152
# Restore index

plugins/repository-hdfs/src/test/resources/rest-api-spec/test/secure_hdfs_repository/40_restore.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
# Close index
4949
- do:
5050
indices.close:
51+
wait_for_active_shards: 0
5152
index : test_index
5253

5354
# Restore index

rest-api-spec/src/main/resources/rest-api-spec/api/indices.close.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
"wait_for_active_shards":{
5858
"type":"string",
59-
"description":"Sets the number of active shards to wait for before the operation returns."
59+
"description":"Sets the number of active shards to wait for before the operation returns. Set to `index-setting` to wait according to the index setting `index.write.wait_for_active_shards`, or `all` to wait for all shards, or an integer. Defaults to `0`."
6060
}
6161
}
6262
}

rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@
398398

399399
- do:
400400
indices.close:
401+
wait_for_active_shards: 0
401402
index: test_index
402403

403404
- do:
@@ -431,6 +432,7 @@
431432

432433
- do:
433434
indices.close:
435+
wait_for_active_shards: 0
434436
index: test_index
435437

436438
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
- do:
6767
indices.close:
68+
wait_for_active_shards: 0
6869
index: index-2
6970
- is_true: acknowledged
7071

@@ -106,6 +107,7 @@
106107

107108
- do:
108109
indices.close:
110+
wait_for_active_shards: 0
109111
index: index-2
110112
- is_true: acknowledged
111113

@@ -248,6 +250,7 @@
248250

249251
- do:
250252
indices.close:
253+
wait_for_active_shards: 0
251254
index: bar
252255

253256
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/cat.recovery/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292

9393
- do:
9494
indices.close:
95+
wait_for_active_shards: 0
9596
index: index2
9697
- is_true: acknowledged
9798

rest-api-spec/src/main/resources/rest-api-spec/test/cat.segments/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494

9595
- do:
9696
indices.close:
97+
wait_for_active_shards: 0
9798
index: index1
9899

99100
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
- do:
6969
indices.close:
70+
wait_for_active_shards: 0
7071
index: test_closed
7172

7273
- match: { acknowledged: true }

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.health/10_basic.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182

183183
- do:
184184
indices.close:
185+
wait_for_active_shards: 0
185186
index: index-2
186187
- is_true: acknowledged
187188

@@ -257,6 +258,7 @@
257258
# closing the index-2 does not change the cluster health with replicated closed indices
258259
- do:
259260
indices.close:
261+
wait_for_active_shards: 0
260262
index: index-2
261263
- is_true: acknowledged
262264

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.health/30_indices_options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ setup:
2222

2323
- do:
2424
indices.close:
25+
wait_for_active_shards: 0
2526
index: index-2
2627

2728
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.state/30_expand_wildcards.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ setup:
2424

2525
- do:
2626
indices.close:
27+
wait_for_active_shards: 0
2728
index: test_close_index
2829

2930
---

rest-api-spec/src/main/resources/rest-api-spec/test/indices.get/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ setup:
3737

3838
- do:
3939
indices.close:
40+
wait_for_active_shards: 0
4041
index: test_index_3
4142

4243
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.get/11_basic_with_types.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ setup:
3636

3737
- do:
3838
indices.close:
39+
wait_for_active_shards: 0
3940
index: test_index_3
4041

4142
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_alias/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ setup:
306306

307307
- do:
308308
indices.close:
309+
wait_for_active_shards: 0
309310
index: test_index_2
310311

311312
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_mapping/50_wildcard_expansion.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ setup:
5151

5252
- do:
5353
indices.close:
54+
wait_for_active_shards: 0
5455
index: test-xyy
5556

5657
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- do:
1515
indices.close:
16+
wait_for_active_shards: 0
1617
index: test_index
1718
- is_true: acknowledged
1819

@@ -51,6 +52,7 @@
5152

5253
- do:
5354
indices.close:
55+
wait_for_active_shards: 0
5456
index: test_index
5557
- is_true: acknowledged
5658

@@ -111,10 +113,54 @@
111113

112114
- do:
113115
indices.close:
116+
wait_for_active_shards: 0
114117
index: "index_*"
115118

116119
- match: { acknowledged: true }
117120
- match: { shards_acknowledged: true }
118121
- match: { indices.index_1.closed: true }
119122
- match: { indices.index_2.closed: true }
120123
- match: { indices.index_3.closed: true }
124+
125+
---
126+
"?wait_for_active_shards=index-setting":
127+
- skip:
128+
version: " - 7.11.99"
129+
reason: "?wait_for_active_shards=index-setting support added in 7.12"
130+
features: ["node_selector"]
131+
132+
- do:
133+
indices.create:
134+
index: index_1
135+
body:
136+
settings:
137+
number_of_replicas: 0
138+
139+
- do:
140+
indices.close:
141+
index: "index_*"
142+
wait_for_active_shards: "index-setting"
143+
node_selector:
144+
version: "7.12.0 - "
145+
146+
---
147+
"?wait_for_active_shards default is deprecated":
148+
- skip:
149+
version: " - 7.11.99"
150+
reason: "required deprecation warning is only emitted in 7.12 and later"
151+
features: ["warnings", "node_selector"]
152+
153+
- do:
154+
indices.create:
155+
index: index_1
156+
body:
157+
settings:
158+
number_of_replicas: 0
159+
160+
- do:
161+
indices.close:
162+
index: "index_*"
163+
node_selector:
164+
version: "7.12.0 - "
165+
warnings:
166+
- "the default value for the ?wait_for_active_shards parameter will change from '0' to 'index-setting' in version 8; specify '?wait_for_active_shards=index-setting' to adopt the future default behaviour, or '?wait_for_active_shards=0' to preserve today's behaviour"

rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/20_multiple_indices.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ setup:
2525
"All indices":
2626
- do:
2727
indices.close:
28+
wait_for_active_shards: 0
2829
index: _all
2930
- is_true: acknowledged
3031

@@ -52,6 +53,7 @@ setup:
5253
"Trailing wildcard":
5354
- do:
5455
indices.close:
56+
wait_for_active_shards: 0
5557
index: test_*
5658
- is_true: acknowledged
5759

@@ -79,6 +81,7 @@ setup:
7981
"Only wildcard":
8082
- do:
8183
indices.close:
84+
wait_for_active_shards: 0
8285
index: '*'
8386
- is_true: acknowledged
8487

rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_settings/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ setup:
8888

8989
- do:
9090
indices.close:
91+
wait_for_active_shards: 0
9192
index: test-index
9293

9394
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
- do:
5757
indices.close:
58+
wait_for_active_shards: 0
5859
index: test_2
5960
- is_true: acknowledged
6061

rest-api-spec/src/main/resources/rest-api-spec/test/indices.resolve_index/10_basic_resolve_index.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ setup:
2323

2424
- do:
2525
indices.close:
26+
wait_for_active_shards: 0
2627
index: test_index2
2728

2829
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.segments/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
- do:
6161
indices.close:
62+
wait_for_active_shards: 0
6263
index: index1
6364

6465
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/search/80_indices_options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
- do:
3535
indices.close:
36+
wait_for_active_shards: 0
3637
index: index_closed
3738

3839
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.restore/10_basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ setup:
3939

4040
- do:
4141
indices.close:
42+
wait_for_active_shards: 0
4243
index : test_index
4344

4445
- do:

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.action.support.IndicesOptions;
2525
import org.elasticsearch.client.node.NodeClient;
2626
import org.elasticsearch.common.Strings;
27+
import org.elasticsearch.common.logging.DeprecationLogger;
2728
import org.elasticsearch.rest.BaseRestHandler;
2829
import org.elasticsearch.rest.RestRequest;
2930
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -37,6 +38,8 @@
3738

3839
public class RestCloseIndexAction extends BaseRestHandler {
3940

41+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestCloseIndexAction.class);
42+
4043
@Override
4144
public List<Route> routes() {
4245
return unmodifiableList(asList(
@@ -56,7 +59,13 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
5659
closeIndexRequest.timeout(request.paramAsTime("timeout", closeIndexRequest.timeout()));
5760
closeIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, closeIndexRequest.indicesOptions()));
5861
String waitForActiveShards = request.param("wait_for_active_shards");
59-
if (waitForActiveShards != null) {
62+
if (waitForActiveShards == null) {
63+
deprecationLogger.deprecate("close-index-wait_for_active_shards-default", "the default value for the ?wait_for_active_shards " +
64+
"parameter will change from '0' to 'index-setting' in version 8; specify '?wait_for_active_shards=index-setting' " +
65+
"to adopt the future default behaviour, or '?wait_for_active_shards=0' to preserve today's behaviour");
66+
} else if ("index-setting".equalsIgnoreCase(waitForActiveShards)) {
67+
closeIndexRequest.waitForActiveShards(ActiveShardCount.DEFAULT);
68+
} else {
6069
closeIndexRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
6170
}
6271
return channel -> client.admin().indices().close(closeIndexRequest, new RestToXContentListener<>(channel));

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,9 @@ protected static boolean indexExists(String index) throws IOException {
12561256
}
12571257

12581258
protected static void closeIndex(String index) throws IOException {
1259-
Response response = client().performRequest(new Request("POST", "/" + index + "/_close"));
1260-
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
1259+
final Request closeRequest = new Request("POST", "/" + index + "/_close");
1260+
closeRequest.addParameter("wait_for_active_shards", "0");
1261+
assertOK(client().performRequest(closeRequest));
12611262
}
12621263

12631264
protected static void openIndex(String index) throws IOException {

x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
- do:
6363
indices.close:
64+
wait_for_active_shards: 0
6465
index: bar
6566
- is_true: acknowledged
6667

x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/forget_follower.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
- do:
7373
indices.close:
74+
wait_for_active_shards: 0
7475
index: follower_index
7576
- is_true: acknowledged
7677

x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/index_directly_into_follower_index.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
- do:
5959
indices.close:
60+
wait_for_active_shards: 0
6061
index: bar
6162
- is_true: acknowledged
6263

x-pack/plugin/src/test/resources/rest-api-spec/test/data_stream/20_unsupported_apis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# close request will not fail but will not match any data streams
4545
- do:
4646
indices.close:
47+
wait_for_active_shards: 0
4748
index: logs-*
4849
- is_true: acknowledged
4950
- length: { indices: 0 }
@@ -164,6 +165,7 @@
164165
- do:
165166
catch: bad_request
166167
indices.close:
168+
wait_for_active_shards: 0
167169
index: ".ds-simple-data-stream1-*000001"
168170

169171
- do:

0 commit comments

Comments
 (0)