Skip to content

Commit ec08f92

Browse files
authored
Introduce ?wait_for_active_shards=index-setting (#67158)
In 7.x the close indices API defaulted to `?wait_for_active_shards=0` but from 8.0 it defaults 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 emits a deprecation warning indicating that the default no longer needs to be used and will be unsupported in future. In 7.x a follow up PR will introduce support for the same `index-setting` value for this parameter and will emit deprecation warnings if users try and use the default instead. Relates #66419
1 parent 1d2462e commit ec08f92

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

docs/reference/migration/migrate_8_0/indices.asciidoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,18 @@ Discontinue use of the `index.translog.retention.age` and
102102
`index.translog.retention.size` index settings. Requests that
103103
include these settings will return an error.
104104
====
105+
106+
.The default for the `?wait_for_active_shards` parameter on the close index API has changed.
107+
[%collapsible]
108+
====
109+
*Details* +
110+
When closing an index in earlier versions, by default {es} would not wait for
111+
the shards of the closed index to be properly assigned before returning. From
112+
version 8.0 onwards the default behaviour is to wait for shards to be assigned
113+
according to the <<index-wait-for-active-shards,index setting
114+
`index.write.wait_for_active_shards`>>.
115+
116+
*Impact* +
117+
Accept the new behaviour, or specify `?wait_for_active_shards=0` to preserve
118+
the old behaviour if needed.
119+
====

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@
8181
- match: { shards_acknowledged: true }
8282
---
8383
"Close index response with result per index":
84-
- skip:
85-
version: " - 7.2.99"
86-
reason: "close index response reports result per index starting version 7.3.0"
87-
8884
- do:
8985
indices.create:
9086
index: index_1
@@ -115,3 +111,26 @@
115111
- match: { indices.index_1.closed: true }
116112
- match: { indices.index_2.closed: true }
117113
- match: { indices.index_3.closed: true }
114+
115+
---
116+
"?wait_for_active_shards=index-setting is deprecated":
117+
- skip:
118+
version: " - 7.99.99"
119+
reason: "required deprecation warning is only emitted in 8.0 and later"
120+
features: ["warnings", "node_selector"]
121+
122+
- do:
123+
indices.create:
124+
index: index_1
125+
body:
126+
settings:
127+
number_of_replicas: 0
128+
129+
- do:
130+
indices.close:
131+
index: "index_*"
132+
wait_for_active_shards: index-setting
133+
node_selector:
134+
version: "8.0.0 - "
135+
warnings:
136+
- "?wait_for_active_shards=index-setting is now the default behaviour; the 'index-setting' value for this parameter should no longer be used since it will become unsupported in version 9"

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
package org.elasticsearch.rest.action.admin.indices;
2121

22+
import org.elasticsearch.Version;
2223
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
2324
import org.elasticsearch.action.support.ActiveShardCount;
2425
import org.elasticsearch.action.support.IndicesOptions;
2526
import org.elasticsearch.client.node.NodeClient;
2627
import org.elasticsearch.common.Strings;
28+
import org.elasticsearch.common.logging.DeprecationLogger;
2729
import org.elasticsearch.rest.BaseRestHandler;
2830
import org.elasticsearch.rest.RestRequest;
2931
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -35,6 +37,8 @@
3537

3638
public class RestCloseIndexAction extends BaseRestHandler {
3739

40+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestCloseIndexAction.class);
41+
3842
@Override
3943
public List<Route> routes() {
4044
return List.of(
@@ -54,7 +58,17 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
5458
closeIndexRequest.timeout(request.paramAsTime("timeout", closeIndexRequest.timeout()));
5559
closeIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, closeIndexRequest.indicesOptions()));
5660
String waitForActiveShards = request.param("wait_for_active_shards");
57-
if (waitForActiveShards != null) {
61+
if ("index-setting".equalsIgnoreCase(waitForActiveShards)) {
62+
deprecationLogger.deprecate("close-index-wait_for_active_shards-index-setting",
63+
"?wait_for_active_shards=index-setting is now the default behaviour; the 'index-setting' value for this parameter " +
64+
"should no longer be used since it will become unsupported in version " + (Version.V_7_0_0.major + 2));
65+
// TODO in v9:
66+
// - throw an IllegalArgumentException here
67+
// - record the removal of support for this value as a breaking change.
68+
// - mention Version.V_8_0_0 in the code to ensure that we revisit this in v10
69+
// TODO in v10:
70+
// - remove the IllegalArgumentException here
71+
} else if (waitForActiveShards != null) {
5872
closeIndexRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
5973
}
6074
return channel -> client.admin().indices().close(closeIndexRequest, new RestToXContentListener<>(channel));

0 commit comments

Comments
 (0)