Skip to content

Commit 8660e8d

Browse files
authored
Warn of change of default of wait_for_active_shards (#67246)
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 #67158 Closes #66419
1 parent 345dd82 commit 8660e8d

File tree

58 files changed

+308
-42
lines changed

Some content is hidden

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

58 files changed

+308
-42
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
3939
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
4040
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
41+
import org.elasticsearch.action.support.ActiveShardCount;
4142
import org.elasticsearch.client.indices.AnalyzeRequest;
4243
import org.elasticsearch.client.indices.CloseIndexRequest;
4344
import org.elasticsearch.client.indices.CreateDataStreamRequest;
@@ -140,6 +141,13 @@ static Request closeIndex(CloseIndexRequest closeIndexRequest) {
140141
parameters.withTimeout(closeIndexRequest.timeout());
141142
parameters.withMasterTimeout(closeIndexRequest.masterNodeTimeout());
142143
parameters.withIndicesOptions(closeIndexRequest.indicesOptions());
144+
145+
final ActiveShardCount activeShardCount = closeIndexRequest.waitForActiveShards();
146+
if (activeShardCount == ActiveShardCount.DEFAULT) {
147+
request.addParameter("wait_for_active_shards", "index-setting");
148+
} else {
149+
parameters.withWaitForActiveShards(activeShardCount);
150+
}
143151
request.addParameters(parameters.asMap());
144152
return request;
145153
}

client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CloseIndexRequest.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.client.indices;
2121

22-
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
2322
import org.elasticsearch.action.support.ActiveShardCount;
2423
import org.elasticsearch.action.support.IndicesOptions;
2524
import org.elasticsearch.client.TimedRequest;
@@ -35,7 +34,7 @@ public class CloseIndexRequest extends TimedRequest implements Validatable {
3534

3635
private String[] indices;
3736
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
38-
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT;
37+
private ActiveShardCount waitForActiveShards = null;
3938

4039
/**
4140
* Creates a new close index request
@@ -82,16 +81,14 @@ public ActiveShardCount waitForActiveShards() {
8281
}
8382

8483
/**
85-
* Sets the number of shard copies that should be active for indices opening to return.
86-
* Defaults to {@link ActiveShardCount#DEFAULT}, which will wait for one shard copy
87-
* (the primary) to become active. Set this value to {@link ActiveShardCount#ALL} to
88-
* wait for all shards (primary and all replicas) to be active before returning.
89-
* Otherwise, use {@link ActiveShardCount#from(int)} to set this value to any
90-
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
91-
* to wait for the desired amount of shard copies to become active before returning.
92-
* Indices opening will only wait up until the timeout value for the number of shard copies
93-
* to be active before returning. Check {@link OpenIndexResponse#isShardsAcknowledged()} to
94-
* determine if the requisite shard copies were all started before returning or timing out.
84+
* Sets the number of shard copies that should be active before a close-index request returns. Defaults to {@code null}, which means not
85+
* to wait. However the default behaviour is deprecated and will change in version 8. You can opt-in to the new default behaviour now by
86+
* setting this to {@link ActiveShardCount#DEFAULT}, which will wait according to the setting {@code index.write.wait_for_active_shards}
87+
* which by default will wait for one shard, the primary. Set this value to {@link ActiveShardCount#ALL} to wait for all shards (primary
88+
* and all replicas) to be active before returning. Otherwise, use {@link ActiveShardCount#from(int)} to set this value to any
89+
* non-negative integer up to the number of copies per shard (number of replicas + 1), to wait for the desired amount of shard copies
90+
* to become active before returning. To explicitly preserve today's default behaviour and suppress the deprecation warning, set this
91+
* property to {@code ActiveShardCount.from(0)}.
9592
*
9693
* @param waitForActiveShards number of active shard copies to wait on
9794
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public void testIndexFollowing() throws Exception {
188188

189189
// Need to close index prior to unfollowing it:
190190
CloseIndexRequest closeIndexRequest = new CloseIndexRequest("follower");
191+
closeIndexRequest.waitForActiveShards(ActiveShardCount.from(0));
191192
org.elasticsearch.action.support.master.AcknowledgedResponse closeIndexReponse =
192193
highLevelClient().indices().close(closeIndexRequest, RequestOptions.DEFAULT);
193194
assertThat(closeIndexReponse.isAcknowledged(), is(true));

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
5151
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
5252
import org.elasticsearch.action.index.IndexRequest;
53+
import org.elasticsearch.action.support.ActiveShardCount;
5354
import org.elasticsearch.action.support.IndicesOptions;
5455
import org.elasticsearch.action.support.WriteRequest;
5556
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
@@ -904,6 +905,7 @@ public void testCloseExistingIndex() throws IOException {
904905
}
905906

906907
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);
908+
closeIndexRequest.waitForActiveShards(ActiveShardCount.from(0));
907909
CloseIndexResponse closeIndexResponse = execute(closeIndexRequest,
908910
highLevelClient().indices()::close, highLevelClient().indices()::closeAsync);
909911
assertTrue(closeIndexResponse.isAcknowledged());
@@ -926,6 +928,7 @@ public void testCloseNonExistentIndex() throws IOException {
926928
assertFalse(indexExists(nonExistentIndex));
927929

928930
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndex);
931+
closeIndexRequest.waitForActiveShards(ActiveShardCount.from(0));
929932
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
930933
() -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
931934
assertEquals(RestStatus.NOT_FOUND, exception.status());
@@ -934,6 +937,7 @@ public void testCloseNonExistentIndex() throws IOException {
934937
public void testCloseEmptyOrNullIndex() {
935938
String[] indices = randomBoolean() ? Strings.EMPTY_ARRAY : null;
936939
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);
940+
closeIndexRequest.waitForActiveShards(ActiveShardCount.from(0));
937941
org.elasticsearch.client.ValidationException exception = expectThrows(org.elasticsearch.client.ValidationException.class,
938942
() -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
939943
assertThat(exception.validationErrors().get(0), equalTo("index is missing"));

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
4242
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
4343
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
44+
import org.elasticsearch.action.support.ActiveShardCount;
4445
import org.elasticsearch.action.support.master.AcknowledgedRequest;
4546
import org.elasticsearch.client.indices.AnalyzeRequest;
4647
import org.elasticsearch.client.indices.CloseIndexRequest;
@@ -641,6 +642,22 @@ public void testCloseIndex() {
641642
RequestConvertersTests.setRandomMasterTimeout(closeIndexRequest, expectedParams);
642643
RequestConvertersTests.setRandomIndicesOptions(closeIndexRequest::indicesOptions, closeIndexRequest::indicesOptions,
643644
expectedParams);
645+
switch (between(0, 3)) {
646+
case 0:
647+
break;
648+
case 1:
649+
closeIndexRequest.waitForActiveShards(ActiveShardCount.DEFAULT);
650+
expectedParams.put("wait_for_active_shards", "index-setting");
651+
break;
652+
case 2:
653+
closeIndexRequest.waitForActiveShards(ActiveShardCount.ALL);
654+
expectedParams.put("wait_for_active_shards", "all");
655+
break;
656+
case 3:
657+
closeIndexRequest.waitForActiveShards(ActiveShardCount.from(1));
658+
expectedParams.put("wait_for_active_shards", "1");
659+
break;
660+
}
644661

645662
Request request = IndicesRequestConverters.closeIndex(closeIndexRequest);
646663
StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_close");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void testRankEvalRequest() throws IOException {
108108
}
109109

110110
// now try this when test2 is closed
111-
client().performRequest(new Request("POST", "index2/_close"));
111+
closeIndex("index2");
112112
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
113113
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
114114
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ public void testUnfollow() throws Exception {
321321
assertThat(unfollowResponse.isAcknowledged(), is(true));
322322

323323
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followIndex);
324+
closeIndexRequest.waitForActiveShards(ActiveShardCount.from(0));
324325
assertThat(client.indices().close(closeIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true));
325326
}
326327

@@ -353,6 +354,7 @@ public void testUnfollow() throws Exception {
353354
assertThat(unfollowResponse.isAcknowledged(), is(true));
354355

355356
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followIndex);
357+
closeIndexRequest.waitForActiveShards(ActiveShardCount.from(0));
356358
assertThat(client.indices().close(closeIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true));
357359
}
358360

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,8 @@ public void testCloseIndex() throws Exception {
14691469
CloseIndexRequest request = new CloseIndexRequest("index"); // <1>
14701470
// end::close-index-request
14711471

1472+
request.waitForActiveShards(ActiveShardCount.from(0));
1473+
14721474
// tag::close-index-request-timeout
14731475
request.setTimeout(TimeValue.timeValueMinutes(2)); // <1>
14741476
// end::close-index-request-timeout

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ private void closeWhileListenerEngaged(ActionFuture<String> future) throws Excep
9797
});
9898

9999
// Close the index. That should flush the listener.
100-
client().performRequest(new Request("POST", "/test/_close"));
100+
final Request closeRequest = new Request("POST", "/test/_close");
101+
closeRequest.addParameter("wait_for_active_shards", "0");
102+
client().performRequest(closeRequest);
101103

102104
/*
103105
* The request may fail, but we really, really, really want to make

docs/reference/ccr/apis/follow/post-unfollow.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PUT /follower_index/_ccr/follow?wait_for_active_shards=1
2323
2424
POST /follower_index/_ccr/pause_follow
2525
26-
POST /follower_index/_close
26+
POST /follower_index/_close?wait_for_active_shards=0
2727
--------------------------------------------------
2828
// TESTSETUP
2929
// TEST[setup:remote_cluster_and_leader_index]

docs/reference/ccr/getting-started.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ replication
243243
--------------------------------------------------
244244
POST /server-metrics-follower/_ccr/pause_follow
245245
246-
POST /server-metrics-follower/_close
246+
POST /server-metrics-follower/_close?wait_for_active_shards=0
247247
248248
POST /server-metrics-follower/_ccr/unfollow
249249
--------------------------------------------------

docs/reference/ccr/managing.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ process. Then, close the follower index and recreate it. For example:
127127
----------------------------------------------------------------------
128128
POST /follower_index/_ccr/pause_follow
129129
130-
POST /follower_index/_close
130+
POST /follower_index/_close?wait_for_active_shards=0
131131
132132
PUT /follower_index/_ccr/follow?wait_for_active_shards=1
133133
{

docs/reference/index-modules/similarity.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ request and <<indices-open-close,open>> it again afterwards:
540540

541541
[source,console]
542542
--------------------------------------------------
543-
POST /index/_close
543+
POST /index/_close?wait_for_active_shards=0
544544
545545
PUT /index/_settings
546546
{

docs/reference/indices/close.asciidoc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Closes an index.
1111
POST /my-index-000001/_close
1212
--------------------------------------------------
1313
// TEST[setup:my_index]
14+
// TEST[warning: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]
1415

1516

1617
[[close-index-api-request]]
@@ -52,7 +53,18 @@ Defaults to `open`.
5253

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

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

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

@@ -66,7 +78,8 @@ The following example shows how to close an index:
6678
--------------------------------------------------
6779
POST /my-index-000001/_close
6880
--------------------------------------------------
69-
// TEST[s/^/PUT my-index-000001\n/]
81+
// TEST[setup:my_index]
82+
// TEST[warning: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]
7083

7184
The API returns following response:
7285

docs/reference/indices/open-close.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ opens any closed backing indices.
1212
POST /my-index-000001/_open
1313
--------------------------------------------------
1414
// TEST[setup:my_index]
15-
// TEST[s/^/POST \/my-index-000001\/_close\n/]
15+
// TEST[s/^/POST \/my-index-000001\/_close?wait_for_active_shards=0\n/]
1616

1717

1818
[[open-index-api-request]]
@@ -122,7 +122,7 @@ The following request re-opens a closed index named `my-index-000001`.
122122
--------------------------------------------------
123123
POST /my-index-000001/_open
124124
--------------------------------------------------
125-
// TEST[s/^/PUT my-index-000001\nPOST my-index-000001\/_close\n/]
125+
// TEST[s/^/PUT my-index-000001\nPOST my-index-000001\/_close?wait_for_active_shards=0\n/]
126126

127127
The API returns the following response:
128128

docs/reference/indices/resolve.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ supported.
1313
----
1414
PUT /foo_closed
1515
16-
POST /foo_closed/_close
16+
POST /foo_closed/_close?wait_for_active_shards=0
1717
1818
PUT /remotecluster-bar-01
1919

docs/reference/indices/update-settings.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ the following commands add the `content` analyzer to the `my-index-000001` index
167167

168168
[source,console]
169169
--------------------------------------------------
170-
POST /my-index-000001/_close
170+
POST /my-index-000001/_close?wait_for_active_shards=0
171171
172172
PUT /my-index-000001/_settings
173173
{

docs/reference/snapshot-restore/apis/restore-snapshot-api.asciidoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ PUT _snapshot/my_repository/snapshot_2?wait_for_completion=true
3838
}
3939
}
4040
41-
POST /index_1/_close
41+
POST /index_1/_close?wait_for_active_shards=0
4242
43-
POST /index_2/_close
43+
POST /index_2/_close?wait_for_active_shards=0
4444
45-
POST /index_3/_close
45+
POST /index_3/_close?wait_for_active_shards=0
4646
47-
POST /index_4/_close
47+
POST /index_4/_close?wait_for_active_shards=0
4848
4949
----
5050
// TESTSETUP

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
---
66
"Create a snapshot and then restore it":
7+
- skip:
8+
features: ["allowed_warnings"]
79

810
# Create repository
911
- do:
@@ -47,6 +49,8 @@
4749
- do:
4850
indices.close:
4951
index : test_index
52+
allowed_warnings:
53+
- "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"
5054

5155
# Restore index
5256
- do:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
---
66
"Create a snapshot and then restore it":
7+
- skip:
8+
features: ["allowed_warnings"]
79

810
# Create repository
911
- do:
@@ -49,6 +51,8 @@
4951
- do:
5052
indices.close:
5153
index : test_index
54+
allowed_warnings:
55+
- "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"
5256

5357
# Restore index
5458
- do:

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@
388388
- skip:
389389
version: " - 7.3.99"
390390
reason: "is_write_index is shown in cat.aliases starting version 7.4.0"
391+
features: ["allowed_warnings"]
391392

392393
- do:
393394
indices.create:
@@ -399,6 +400,8 @@
399400
- do:
400401
indices.close:
401402
index: test_index
403+
allowed_warnings:
404+
- "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"
402405

403406
- do:
404407
cat.aliases:
@@ -419,7 +422,7 @@
419422
"Alias against closed index (pre 7.4.0)":
420423
- skip:
421424
version: "7.4.0 - "
422-
features: node_selector
425+
features: ["node_selector", "allowed_warnings"]
423426
reason: "is_write_index is shown in cat.aliases starting version 7.4.0"
424427

425428
- do:
@@ -432,6 +435,8 @@
432435
- do:
433436
indices.close:
434437
index: test_index
438+
allowed_warnings:
439+
- "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"
435440

436441
- do:
437442
node_selector:

0 commit comments

Comments
 (0)