Skip to content

Commit

Permalink
Deprecate lack of waiting on shards on index close
Browse files Browse the repository at this point in the history
In 8.x the default for `?wait_for_active_shards` will change from `NONE`
to `DEFAULT` on calls to `POST /index/_close`. This commit adds a
deprecation warning in 7.x if this parameter is not specified to
encourage users to adopt the new behaviour before upgrading.

Closes elastic#66419
  • Loading branch information
DaveCTurner committed Dec 17, 2020
1 parent 9a9d480 commit a97b644
Show file tree
Hide file tree
Showing 29 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@
- do:
indices.close:
index: test_index
wait_for_active_shards: DEFAULT

- do:
cat.aliases:
Expand Down Expand Up @@ -432,6 +433,7 @@
- do:
indices.close:
index: test_index
wait_for_active_shards: DEFAULT

- do:
node_selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
- do:
indices.close:
index: index-2
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down Expand Up @@ -107,6 +108,7 @@
- do:
indices.close:
index: index-2
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down Expand Up @@ -249,6 +251,7 @@
- do:
indices.close:
index: bar
wait_for_active_shards: DEFAULT

- do:
cat.indices:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
- do:
indices.close:
index: index2
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
- do:
indices.close:
index: index1
wait_for_active_shards: DEFAULT

- do:
catch: bad_request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
- do:
indices.close:
index: test_closed
wait_for_active_shards: DEFAULT

- match: { acknowledged: true }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
- do:
indices.close:
index: index-2
wait_for_active_shards: DEFAULT
- is_true: acknowledged

# closing the index-2 turns the cluster health back to green
Expand Down Expand Up @@ -258,6 +259,7 @@
- do:
indices.close:
index: index-2
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ setup:
- do:
indices.close:
index: index-2
wait_for_active_shards: DEFAULT

- do:
cluster.health:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ setup:
- do:
indices.close:
index: test_close_index
wait_for_active_shards: DEFAULT

---
"Test expand_wildcards parameter on closed, open indices and both":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ setup:
- do:
indices.close:
index: test_index_3
wait_for_active_shards: DEFAULT

- do:
cluster.health:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ setup:
- do:
indices.close:
index: test_index_3
wait_for_active_shards: DEFAULT

- do:
cluster.health:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ setup:
- do:
indices.close:
index: test_index_2
wait_for_active_shards: DEFAULT

- do:
indices.get_alias:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ setup:
- do:
indices.close:
index: test-xyy
wait_for_active_shards: DEFAULT

- do:
cluster.health:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- do:
indices.close:
index: test_index
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down Expand Up @@ -52,6 +53,7 @@
- do:
indices.close:
index: test_index
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down Expand Up @@ -83,6 +85,27 @@
- match: { acknowledged: true }
- match: { shards_acknowledged: true }
---
"Close index without specifying wait_for_active_shards":
- skip:
version: " - 7.1.99"
reason: "closed indices are replicated starting version 7.2.0"
features: ["warnings", "node_selector"]

- do:
indices.create:
index: test_index
body:
settings:
number_of_replicas: 0

- do:
indices.close:
index: test_index
warnings:
- "When closing an index in 8.0 the default behaviour will change from ?wait_for_active_shards=NONE to ?wait_for_active_shards=DEFAULT. To opt-in to the new default, set ?wait_for_active_shards=DEFAULT when closing indices."
node_selector:
version: "7.12.0 - "
---
"Close index response with result per index":
- skip:
version: " - 7.2.99"
Expand Down Expand Up @@ -112,6 +135,7 @@
- do:
indices.close:
index: "index_*"
wait_for_active_shards: DEFAULT

- match: { acknowledged: true }
- match: { shards_acknowledged: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ setup:
- do:
indices.close:
index: _all
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down Expand Up @@ -53,6 +54,7 @@ setup:
- do:
indices.close:
index: test_*
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down Expand Up @@ -80,6 +82,7 @@ setup:
- do:
indices.close:
index: '*'
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ setup:
- do:
indices.close:
index: test-index
wait_for_active_shards: DEFAULT

- do:
indices.put_settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- do:
indices.close:
index: test_2
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ setup:
- do:
indices.close:
index: test_index2
wait_for_active_shards: DEFAULT

- do:
indices.create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- do:
indices.close:
index: index1
wait_for_active_shards: DEFAULT

- do:
catch: bad_request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- do:
indices.close:
index: index_closed
wait_for_active_shards: DEFAULT

- do:
catch: /index_closed_exception/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ setup:
- do:
indices.close:
index : test_index
wait_for_active_shards: DEFAULT

- do:
snapshot.restore:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -37,6 +38,8 @@

public class RestCloseIndexAction extends BaseRestHandler {

private static final DeprecationLogger logger = DeprecationLogger.getLogger(RestCloseIndexAction.class);

@Override
public List<Route> routes() {
return unmodifiableList(asList(
Expand All @@ -55,8 +58,12 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
closeIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", closeIndexRequest.masterNodeTimeout()));
closeIndexRequest.timeout(request.paramAsTime("timeout", closeIndexRequest.timeout()));
closeIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, closeIndexRequest.indicesOptions()));
String waitForActiveShards = request.param("wait_for_active_shards");
if (waitForActiveShards != null) {
final String waitForActiveShards = request.param("wait_for_active_shards");
if (waitForActiveShards == null) {
logger.deprecate("close-index-wait-for-active-shards", "When closing an index in 8.0 the default behaviour will change from " +
"?wait_for_active_shards=NONE to ?wait_for_active_shards=DEFAULT. To opt-in to the new default, set " +
"?wait_for_active_shards=DEFAULT when closing indices.");
} else {
closeIndexRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
}
return channel -> client.admin().indices().close(closeIndexRequest, new RestToXContentListener<>(channel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- do:
indices.close:
index: logs-*
wait_for_active_shards: DEFAULT
- is_true: acknowledged
- length: { indices: 0 }

Expand Down Expand Up @@ -165,6 +166,7 @@
catch: bad_request
indices.close:
index: ".ds-simple-data-stream1-*000001"
wait_for_active_shards: DEFAULT

- do:
indices.delete_data_stream:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ teardown:
- do:
indices.close:
index: ".ds-simple-data-stream1-*000001,.ds-simple-data-stream1-*000002"
wait_for_active_shards: DEFAULT
- is_true: acknowledged

- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ setup:
- do:
indices.close:
index: test_index2
wait_for_active_shards: DEFAULT

- do:
indices.create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
- do:
indices.close:
index: test-close
wait_for_active_shards: DEFAULT

- do:
indices.freeze:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@
- do:
indices.close:
index: ".ml-anomalies-shared"
wait_for_active_shards: DEFAULT

- do:
catch: /Cannot create job \[closed-results-job\] as it requires closed index \[\.ml-anomalies-shared\]/
Expand Down Expand Up @@ -1250,6 +1251,7 @@
- do:
indices.close:
index: ".ml-state-000001"
wait_for_active_shards: DEFAULT

- do:
catch: /Cannot create job \[closed-results-job\] as it requires closed index \[\.ml-state-000001\]/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
- do:
indices.close:
index: .monitoring-beats-*
wait_for_active_shards: DEFAULT

- do:
catch: /export_exception/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ setup:
- do:
indices.close:
index: index3
wait_for_active_shards: DEFAULT

---
teardown:
Expand Down Expand Up @@ -150,6 +151,7 @@ teardown:
- do:
indices.close:
index: index_to_monitor
wait_for_active_shards: DEFAULT

- do:
headers: { Authorization: "Basic Y2F0X3VzZXI6Y2F0X3Bhc3N3b3Jk" } # cat_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ setup:
- do:
indices.close:
index : test_index
wait_for_active_shards: DEFAULT

- do:
snapshot.restore:
Expand Down

0 comments on commit a97b644

Please sign in to comment.