Skip to content

Deprecate lack of waiting on shards on index close #66542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public void testRankEvalRequest() throws IOException {
}

// now try this when test2 is closed
client().performRequest(new Request("POST", "index2/_close"));
final Request closeRequest = new Request("POST", "index2/_close");
closeRequest.addParameter("wait_for_active_shards", "DEFAULT");
client().performRequest(closeRequest);
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ private void closeWhileListenerEngaged(ActionFuture<String> future) throws Excep
});

// Close the index. That should flush the listener.
client().performRequest(new Request("POST", "/test/_close"));
final Request closeRequest = new Request("POST", "/test/_close");
closeRequest.addParameter("wait_for_active_shards", "DEFAULT");
client().performRequest(closeRequest);

/*
* The request may fail, but we really, really, really want to make
Expand Down
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 @@ -1225,7 +1225,9 @@ protected static boolean indexExists(String index) throws IOException {
}

protected static void closeIndex(String index) throws IOException {
Response response = client().performRequest(new Request("POST", "/" + index + "/_close"));
final Request closeRequest = new Request("POST", "/" + index + "/_close");
closeRequest.addParameter("wait_for_active_shards", "DEFAULT");
Response response = client().performRequest(closeRequest);
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testFollowIndex() throws Exception {
assertBusy(() -> verifyCcrMonitoring(leaderIndexName, followIndexName), 30, TimeUnit.SECONDS);

pauseFollow(followIndexName);
assertOK(client().performRequest(new Request("POST", "/" + followIndexName + "/_close")));
closeIndex(followIndexName);
assertOK(client().performRequest(new Request("POST", "/" + followIndexName + "/_ccr/unfollow")));
Exception e = expectThrows(ResponseException.class, () -> resumeFollow(followIndexName));
assertThat(e.getMessage(), containsString("follow index [" + followIndexName + "] does not have ccr metadata"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testFollowIndex() throws Exception {
assertThat(countCcrNodeTasks(), equalTo(0));
});

assertOK(client().performRequest(new Request("POST", "/" + allowedIndex + "/_close")));
closeIndex(allowedIndex);
assertOK(client().performRequest(new Request("POST", "/" + allowedIndex + "/_ccr/unfollow")));
Exception e = expectThrows(ResponseException.class, () -> resumeFollow(allowedIndex));
assertThat(e.getMessage(), containsString("follow index [" + allowedIndex + "] does not have ccr metadata"));
Expand Down Expand Up @@ -124,7 +124,7 @@ public void testFollowIndex() throws Exception {
e = expectThrows(ResponseException.class,
() -> client().performRequest(new Request("POST", "/" + unallowedIndex + "/_ccr/unfollow")));
assertThat(e.getMessage(), containsString("action [indices:admin/xpack/ccr/unfollow] is unauthorized for user [test_ccr]"));
assertOK(adminClient().performRequest(new Request("POST", "/" + unallowedIndex + "/_close")));
closeIndex(unallowedIndex);
assertOK(adminClient().performRequest(new Request("POST", "/" + unallowedIndex + "/_ccr/unfollow")));
assertBusy(() -> assertThat(countCcrNodeTasks(), equalTo(0)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void testSearchResultsWhenFrozen() throws Exception {
public void testCloseAndReopen() throws Exception {
runSearchableSnapshotsTest((restoredIndexName, numDocs) -> {
final Request closeRequest = new Request(HttpPost.METHOD_NAME, restoredIndexName + "/_close");
closeRequest.addParameter("wait_for_active_shards", "DEFAULT");
assertOK(client().performRequest(closeRequest));
ensureGreen(restoredIndexName);

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
Loading