Skip to content

Commit

Permalink
[7.x] Deprecate freeze index API (#74702)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann committed Jun 29, 2021
1 parent c27eeb2 commit 3f8e41b
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
.setWarningsHandler(warnings ->
org.elasticsearch.core.List.of(RestPutIndexTemplateAction.DEPRECATION_WARNING).equals(warnings) == false).build();

public static final String FROZEN_INDICES_DEPRECATION_WARNING = "Frozen indices are deprecated because they provide no benefit given " +
"improvements in heap memory utilization. They will be removed in a future release.";

public void testIndicesExists() throws IOException {
// Index present
{
Expand Down Expand Up @@ -2002,13 +2005,18 @@ public void testFreezeAndUnfreeze() throws IOException {
createIndex("test", Settings.EMPTY);
RestHighLevelClient client = highLevelClient();

final RequestOptions freezeIndexOptions = RequestOptions.DEFAULT.toBuilder()
.setWarningsHandler(
warnings -> org.elasticsearch.core.List.of(FROZEN_INDICES_DEPRECATION_WARNING).equals(warnings) == false
).build();

ShardsAcknowledgedResponse freeze = execute(new FreezeIndexRequest("test"), client.indices()::freeze,
client.indices()::freezeAsync);
client.indices()::freezeAsync, freezeIndexOptions);
assertTrue(freeze.isShardsAcknowledged());
assertTrue(freeze.isAcknowledged());

ShardsAcknowledgedResponse unfreeze = execute(new UnfreezeIndexRequest("test"), client.indices()::unfreeze,
client.indices()::unfreezeAsync);
client.indices()::unfreezeAsync, freezeIndexOptions);
assertTrue(unfreeze.isShardsAcknowledged());
assertTrue(unfreeze.isAcknowledged());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static org.elasticsearch.client.IndicesClientIT.FROZEN_INDICES_DEPRECATION_WARNING;
import static org.elasticsearch.client.IndicesClientIT.LEGACY_TEMPLATE_OPTIONS;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -2984,8 +2985,14 @@ public void testFreezeIndex() throws Exception {
request.setIndicesOptions(IndicesOptions.strictExpandOpen()); // <1>
// end::freeze-index-request-indicesOptions

final RequestOptions freezeIndexOptions = RequestOptions.DEFAULT.toBuilder()
.setWarningsHandler(
warnings -> org.elasticsearch.core.List.of(FROZEN_INDICES_DEPRECATION_WARNING).equals(warnings) == false
)
.build();

// tag::freeze-index-execute
ShardsAcknowledgedResponse openIndexResponse = client.indices().freeze(request, RequestOptions.DEFAULT);
ShardsAcknowledgedResponse openIndexResponse = client.indices().freeze(request, freezeIndexOptions);
// end::freeze-index-execute

// tag::freeze-index-response
Expand Down Expand Up @@ -3063,7 +3070,12 @@ public void testUnfreezeIndex() throws Exception {
// end::unfreeze-index-request-indicesOptions

// tag::unfreeze-index-execute
ShardsAcknowledgedResponse openIndexResponse = client.indices().unfreeze(request, RequestOptions.DEFAULT);
final RequestOptions unfreezeIndexOptions = RequestOptions.DEFAULT.toBuilder()
.setWarningsHandler(
warnings -> org.elasticsearch.core.List.of(FROZEN_INDICES_DEPRECATION_WARNING).equals(warnings) == false
)
.build();
ShardsAcknowledgedResponse openIndexResponse = client.indices().unfreeze(request, unfreezeIndexOptions);
// end::unfreeze-index-execute

// tag::unfreeze-index-response
Expand Down
1 change: 1 addition & 0 deletions docs/reference/indices/apis/freeze.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ The following example freezes and unfreezes an index:
POST /my-index-000001/_freeze
POST /my-index-000001/_unfreeze
--------------------------------------------------
// TEST[skip:unable to ignore deprecation warning]
// TEST[s/^/PUT my-index-000001\n/]

3 changes: 2 additions & 1 deletion docs/reference/indices/apis/unfreeze.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Unfreezes an index.
[[unfreeze-index-api-desc]]
==== {api-description-title}

When a frozen index is unfrozen, the index goes through the normal recovery
When a frozen index is unfrozen, the index goes through the normal recovery
process and becomes writeable again. See <<freeze-index-api>>.

IMPORTANT: Freezing an index will close the index and reopen it within the same
Expand All @@ -47,3 +47,4 @@ POST /my-index-000001/_freeze
POST /my-index-000001/_unfreeze
--------------------------------------------------
// TEST[s/^/PUT my-index-000001\n/]
// TEST[skip:unable to ignore deprecation warning]
1 change: 1 addition & 0 deletions docs/reference/indices/resolve.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ DELETE /_index_template/foo_data_stream
----
GET /_resolve/index/my-index-*
----
// TEST[skip:unable to ignore deprecation warning]

[[resolve-index-api-request]]
==== {api-request-title}
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ tasks.named("yamlRestTest").configure {
*/
systemProperty 'es.set.netty.runtime.available.processors', 'false'


// TODO: fix this rest test to not depend on a hardcoded port!
def blacklist = ['getting_started/10_monitor_cluster_health/*']
if (BuildParams.isSnapshotBuild() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.protocol.xpack.frozen.FreezeRequest;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
Expand All @@ -17,15 +18,19 @@

import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.rest.RestRequest.Method.POST;

public final class RestFreezeIndexAction extends XPackRestHandler {

public static final String DEPRECATION_WARNING = "Frozen indices are deprecated because they provide no benefit given improvements "
+ "in heap memory utilization. They will be removed in a future release.";

@Override
public List<Route> routes() {
return unmodifiableList(asList(new Route(POST, "/{index}/_freeze"), new Route(POST, "/{index}/_unfreeze")));
return org.elasticsearch.core.List.of(
Route.builder(POST, "/{index}/_freeze").deprecated(DEPRECATION_WARNING, RestApiVersion.V_7).build(),
Route.builder(POST, "/{index}/_unfreeze").deprecated(DEPRECATION_WARNING, RestApiVersion.V_7).build()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

public abstract class AbstractSearchableSnapshotsRestTestCase extends ESRestTestCase {

public static final String FROZEN_INDICES_WARNING = "Frozen indices are deprecated because they provide no benefit given "
+ "improvements in heap memory utilization. They will be removed in a future release.";

private static final String WRITE_REPOSITORY_NAME = "repository";
private static final String READ_REPOSITORY_NAME = "read-repository";
private static final String SNAPSHOT_NAME = "searchable-snapshot";
Expand Down Expand Up @@ -177,6 +180,7 @@ public void testSearchResults() throws Exception {
public void testSearchResultsWhenFrozen() throws Exception {
runSearchableSnapshotsTest((restoredIndexName, numDocs) -> {
final Request freezeRequest = new Request(HttpPost.METHOD_NAME, restoredIndexName + "/_freeze");
freezeRequest.setOptions(expectWarnings(FROZEN_INDICES_WARNING));
assertOK(client().performRequest(freezeRequest));
ensureGreen(restoredIndexName);
assertSearchResults(restoredIndexName, numDocs, Boolean.FALSE);
Expand All @@ -186,6 +190,7 @@ public void testSearchResultsWhenFrozen() throws Exception {
assertThat(Boolean.valueOf(extractValue(frozenIndexSettings, "index.blocks.write")), equalTo(true));

final Request unfreezeRequest = new Request(HttpPost.METHOD_NAME, restoredIndexName + "/_unfreeze");
unfreezeRequest.setOptions(expectWarnings(FROZEN_INDICES_WARNING));
assertOK(client().performRequest(unfreezeRequest));
ensureGreen(restoredIndexName);
assertSearchResults(restoredIndexName, numDocs, Boolean.FALSE);
Expand Down Expand Up @@ -289,6 +294,7 @@ public void testSnapshotOfSearchableSnapshot() throws Exception {
if (frozen) {
logger.info("--> freezing index [{}]", restoredIndexName);
final Request freezeRequest = new Request(HttpPost.METHOD_NAME, restoredIndexName + "/_freeze");
freezeRequest.setOptions(expectWarnings(FROZEN_INDICES_WARNING));
assertOK(client().performRequest(freezeRequest));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.List;
import java.util.Map;

import static org.elasticsearch.test.rest.ESRestTestCase.expectWarnings;

public class DataLoader {

public static void main(String[] args) throws Exception {
Expand Down Expand Up @@ -402,7 +404,14 @@ public static void makeAlias(RestClient client, String aliasName, String... indi

protected static void freeze(RestClient client, String... indices) throws Exception {
for (String index : indices) {
client.performRequest(new Request("POST", "/" + index + "/_freeze"));
Request freezeRequest = new Request("POST", "/" + index + "/_freeze");
freezeRequest.setOptions(
expectWarnings(
"Frozen indices are deprecated because they provide no benefit given improvements in "
+ "heap memory utilization. They will be removed in a future release."
)
);
client.performRequest(freezeRequest);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
"Basic":

- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
features: [ "warnings" ]

- do:
index:
Expand All @@ -17,6 +17,8 @@
body: { "foo": "Hello: 2" }

- do:
warnings:
- "Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release."
indices.freeze:
index: test

Expand All @@ -34,6 +36,8 @@

# unfreeze
- do:
warnings:
- "Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release."
indices.unfreeze:
index: test

Expand All @@ -56,6 +60,8 @@


- do:
warnings:
- "Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release."
indices.freeze:
index: test*

Expand Down Expand Up @@ -88,7 +94,7 @@
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
features: ["allowed_warnings"]
features: ["allowed_warnings", "warnings"]

- do:
index:
Expand All @@ -109,6 +115,8 @@
- "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"

- do:
warnings:
- "Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release."
indices.freeze:
index: test*,not_available
ignore_unavailable: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setup:
---
"Translog stats on frozen indices":
- skip:
features: warnings
version: " - 7.3.99"
reason: "start ignoring translog retention policy with soft-deletes enabled in 7.4"

Expand Down Expand Up @@ -39,6 +40,8 @@ setup:

# freeze index
- do:
warnings:
- "Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release."
indices.freeze:
index: test
wait_for_active_shards: 1
Expand All @@ -52,6 +55,8 @@ setup:

# unfreeze index
- do:
warnings:
- "Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release."
indices.unfreeze:
index: test
wait_for_active_shards: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setup:
---
"Usage stats on frozen indices":
- skip:
features: [ "warnings" ]
version: " - 7.3.99"
reason: "frozen indices have usage stats starting in version 7.4"

Expand Down Expand Up @@ -38,6 +39,8 @@ setup:

# freeze index
- do:
warnings:
- "Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release."
indices.freeze:
index: test
- is_true: acknowledged
Expand All @@ -50,6 +53,8 @@ setup:

# unfreeze index
- do:
warnings:
- "Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release."
indices.unfreeze:
index: test
- is_true: acknowledged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,14 +935,28 @@ public void testFrozenIndexAfterRestarted() throws Exception {
ensureGreen(index);
final int totalHits = (int) XContentMapValues.extractValue("hits.total.value",
entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search"))));
assertOK(client().performRequest(new Request("POST", index + "/_freeze")));
Request freezeRequest = new Request("POST", index + "/_freeze");
freezeRequest.setOptions(
expectWarnings(
"Frozen indices are deprecated because they provide no benefit given "
+ "improvements in heap memory utilization. They will be removed in a future release."
)
);
assertOK(client().performRequest(freezeRequest));
ensureGreen(index);
assertNoFileBasedRecovery(index, n -> true);
final Request request = new Request("GET", "/" + index + "/_search");
request.addParameter("ignore_throttled", "false");
assertThat(XContentMapValues.extractValue("hits.total.value", entityAsMap(client().performRequest(request))),
equalTo(totalHits));
assertOK(client().performRequest(new Request("POST", index + "/_unfreeze")));
final Request unfreezeRequest = new Request("POST", index + "/_unfreeze");
unfreezeRequest.setOptions(
expectWarnings(
"Frozen indices are deprecated because they provide no benefit given "
+ "improvements in heap memory utilization. They will be removed in a future release."
)
);
assertOK(client().performRequest(unfreezeRequest));
ensureGreen(index);
assertNoFileBasedRecovery(index, n -> true);
}
Expand Down

0 comments on commit 3f8e41b

Please sign in to comment.