diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index a7cfa410b6c17..a38d26f5ea756 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -42,7 +42,6 @@ import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.action.support.broadcast.BroadcastResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.client.core.ShardsAcknowledgedResponse; import org.elasticsearch.client.indices.AnalyzeRequest; import org.elasticsearch.client.indices.AnalyzeResponse; import org.elasticsearch.client.indices.CloseIndexRequest; @@ -58,7 +57,6 @@ import org.elasticsearch.client.indices.DeleteAliasRequest; import org.elasticsearch.client.indices.DeleteComposableIndexTemplateRequest; import org.elasticsearch.client.indices.DeleteDataStreamRequest; -import org.elasticsearch.client.indices.FreezeIndexRequest; import org.elasticsearch.client.indices.GetComposableIndexTemplateRequest; import org.elasticsearch.client.indices.GetComposableIndexTemplatesResponse; import org.elasticsearch.client.indices.GetDataStreamRequest; @@ -80,7 +78,6 @@ import org.elasticsearch.client.indices.ReloadAnalyzersResponse; import org.elasticsearch.client.indices.SimulateIndexTemplateRequest; import org.elasticsearch.client.indices.SimulateIndexTemplateResponse; -import org.elasticsearch.client.indices.UnfreezeIndexRequest; import org.elasticsearch.client.indices.rollover.RolloverRequest; import org.elasticsearch.client.indices.rollover.RolloverResponse; import org.elasticsearch.cluster.metadata.AliasMetadata; @@ -95,11 +92,11 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.support.XContentMapValues; +import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; @@ -1533,24 +1530,6 @@ public void testAnalyze() throws Exception { assertNotNull(detailsResponse.detail()); } - public void testFreezeAndUnfreeze() throws IOException { - createIndex("test", Settings.EMPTY); - RestHighLevelClient client = highLevelClient(); - - final RequestOptions freezeIndexOptions = RequestOptions.DEFAULT.toBuilder() - .setWarningsHandler(warnings -> List.of(FROZEN_INDICES_DEPRECATION_WARNING).equals(warnings) == false).build(); - - ShardsAcknowledgedResponse freeze = execute(new FreezeIndexRequest("test"), client.indices()::freeze, - client.indices()::freezeAsync, freezeIndexOptions); - assertTrue(freeze.isShardsAcknowledged()); - assertTrue(freeze.isAcknowledged()); - - ShardsAcknowledgedResponse unfreeze = execute(new UnfreezeIndexRequest("test"), client.indices()::unfreeze, - client.indices()::unfreezeAsync, freezeIndexOptions); - assertTrue(unfreeze.isShardsAcknowledged()); - assertTrue(unfreeze.isAcknowledged()); - } - public void testReloadAnalyzer() throws IOException { createIndex("test", Settings.EMPTY); RestHighLevelClient client = highLevelClient(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java index 88e8192f7a271..8b80cfbad045a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java @@ -55,22 +55,21 @@ import org.elasticsearch.client.indices.DeleteAliasRequest; import org.elasticsearch.client.indices.DeleteComposableIndexTemplateRequest; import org.elasticsearch.client.indices.DetailAnalyzeResponse; -import org.elasticsearch.client.indices.FreezeIndexRequest; +import org.elasticsearch.client.indices.GetComposableIndexTemplateRequest; +import org.elasticsearch.client.indices.GetComposableIndexTemplatesResponse; import org.elasticsearch.client.indices.GetFieldMappingsRequest; import org.elasticsearch.client.indices.GetFieldMappingsResponse; import org.elasticsearch.client.indices.GetIndexRequest; import org.elasticsearch.client.indices.GetIndexResponse; -import org.elasticsearch.client.indices.GetComposableIndexTemplateRequest; import org.elasticsearch.client.indices.GetIndexTemplatesRequest; import org.elasticsearch.client.indices.GetIndexTemplatesResponse; -import org.elasticsearch.client.indices.GetComposableIndexTemplatesResponse; import org.elasticsearch.client.indices.GetMappingsRequest; import org.elasticsearch.client.indices.GetMappingsResponse; import org.elasticsearch.client.indices.IndexTemplateMetadata; import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutComponentTemplateRequest; -import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutComposableIndexTemplateRequest; +import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; import org.elasticsearch.client.indices.ReloadAnalyzersRequest; import org.elasticsearch.client.indices.ReloadAnalyzersResponse; @@ -89,10 +88,10 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; @@ -2859,87 +2858,6 @@ public void onFailure(Exception e) { } - public void testFreezeIndex() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::freeze-index-request - FreezeIndexRequest request = new FreezeIndexRequest("index"); // <1> - // end::freeze-index-request - - // tag::freeze-index-request-timeout - request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> - // end::freeze-index-request-timeout - // tag::freeze-index-request-masterTimeout - request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1> - // end::freeze-index-request-masterTimeout - // tag::freeze-index-request-waitForActiveShards - request.setWaitForActiveShards(ActiveShardCount.DEFAULT); // <1> - // end::freeze-index-request-waitForActiveShards - - // tag::freeze-index-request-indicesOptions - request.setIndicesOptions(IndicesOptions.strictExpandOpen()); // <1> - // end::freeze-index-request-indicesOptions - - final RequestOptions freezeIndexOptions = RequestOptions.DEFAULT.toBuilder() - .setWarningsHandler(warnings -> List.of(FROZEN_INDICES_DEPRECATION_WARNING).equals(warnings) == false).build(); - - // tag::freeze-index-execute - ShardsAcknowledgedResponse openIndexResponse = client.indices().freeze(request, freezeIndexOptions); - // end::freeze-index-execute - - // tag::freeze-index-response - boolean acknowledged = openIndexResponse.isAcknowledged(); // <1> - boolean shardsAcked = openIndexResponse.isShardsAcknowledged(); // <2> - // end::freeze-index-response - assertTrue(acknowledged); - assertTrue(shardsAcked); - - // tag::freeze-index-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ShardsAcknowledgedResponse freezeIndexResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::freeze-index-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::freeze-index-execute-async - client.indices().freezeAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::freeze-index-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::freeze-index-notfound - try { - FreezeIndexRequest request = new FreezeIndexRequest("does_not_exist"); - client.indices().freeze(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.BAD_REQUEST) { - // <1> - } - } - // end::freeze-index-notfound - } - } - public void testUnfreezeIndex() throws Exception { RestHighLevelClient client = highLevelClient(); diff --git a/docs/java-rest/high-level/indices/freeze_index.asciidoc b/docs/java-rest/high-level/indices/freeze_index.asciidoc deleted file mode 100644 index c3773aee80c33..0000000000000 --- a/docs/java-rest/high-level/indices/freeze_index.asciidoc +++ /dev/null @@ -1,65 +0,0 @@ --- -:api: freeze-index -:request: FreezeIndexRequest -:response: FreezeIndexResponse --- - -[id="{upid}-{api}"] -=== Freeze Index API - -[id="{upid}-{api}-request"] -==== Freeze Index Request - -An +{request}+ requires an `index` argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] --------------------------------------------------- -<1> The index to freeze - -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-timeout] --------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index is frozen -as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-masterTimeout] --------------------------------------------------- -<1> Timeout to connect to the master node as a `TimeValue` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards] --------------------------------------------------- -<1> The number of active shard copies to wait for before the freeze index API -returns a response, as an `ActiveShardCount` - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and -how wildcard expressions are expanded - -include::../execution.asciidoc[] - -[id="{upid}-{api}-response"] -==== Freeze Index Response - -The returned +{response}+ allows to retrieve information about the -executed operation as follows: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] --------------------------------------------------- -<1> Indicates whether all of the nodes have acknowledged the request -<2> Indicates whether the requisite number of shard copies were started for -each shard in the index before timing out diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index e6432d0f272b4..414d7a43e5dc2 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -174,7 +174,6 @@ include::indices/validate_query.asciidoc[] include::indices/get_templates.asciidoc[] include::indices/templates_exist.asciidoc[] include::indices/get_index.asciidoc[] -include::indices/freeze_index.asciidoc[] include::indices/unfreeze_index.asciidoc[] include::indices/delete_template.asciidoc[] include::indices/reload_analyzers.asciidoc[] diff --git a/docs/java-rest/redirects.asciidoc b/docs/java-rest/redirects.asciidoc index a077102b405d4..37f331a87bcef 100644 --- a/docs/java-rest/redirects.asciidoc +++ b/docs/java-rest/redirects.asciidoc @@ -47,3 +47,11 @@ See <>. === Stop {transform} API See <>. + +[role="exclude",id="java-rest-high-freeze-index"] +=== Freeze index API + +The freeze index API was removed in 8.0. Frozen indices are no longer useful due +to +https://www.elastic.co/blog/significantly-decrease-your-elasticsearch-heap-memory-usage[recent +improvements in heap memory usage]. diff --git a/docs/reference/data-streams/data-streams.asciidoc b/docs/reference/data-streams/data-streams.asciidoc index 4e124e9b8055a..25e084e6e7c42 100644 --- a/docs/reference/data-streams/data-streams.asciidoc +++ b/docs/reference/data-streams/data-streams.asciidoc @@ -67,7 +67,6 @@ such as: * <> * <> -* <> * <> * <> diff --git a/docs/reference/ilm/actions/ilm-freeze.asciidoc b/docs/reference/ilm/actions/ilm-freeze.asciidoc deleted file mode 100644 index db413545c0910..0000000000000 --- a/docs/reference/ilm/actions/ilm-freeze.asciidoc +++ /dev/null @@ -1,34 +0,0 @@ -[role="xpack"] -[[ilm-freeze]] -=== Freeze - -Phases allowed: cold. - -<> an index. - -deprecated[7.x,"The ILM Freeze action was deprecated in 7.x and will be treated as a no-op in 8.0+."] - -[[ilm-freeze-options]] -==== Options - -None. - -[[ilm-freeze-ex]] -==== Example - -[source,console] --------------------------------------------------- -PUT _ilm/policy/my_policy -{ - "policy": { - "phases": { - "cold": { - "actions": { - "freeze" : { } - } - } - } - } -} --------------------------------------------------- - diff --git a/docs/reference/ilm/actions/ilm-searchable-snapshot.asciidoc b/docs/reference/ilm/actions/ilm-searchable-snapshot.asciidoc index 7e08947e7f624..fb756da1ecaa1 100644 --- a/docs/reference/ilm/actions/ilm-searchable-snapshot.asciidoc +++ b/docs/reference/ilm/actions/ilm-searchable-snapshot.asciidoc @@ -18,8 +18,7 @@ index>> to the frozen tier. In other phases, the action mounts a <> to the corresponding data tier. IMPORTANT: If the `searchable_snapshot` action is used in the hot phase the -subsequent phases cannot include the `shrink`, `forcemerge`, or `freeze` -actions. +subsequent phases cannot include the `shrink` or `forcemerge` actions. [NOTE] This action cannot be performed on a data stream's write index. Attempts to do diff --git a/docs/reference/ilm/ilm-actions.asciidoc b/docs/reference/ilm/ilm-actions.asciidoc index 4b3e456d00230..cbe6923e3cd0d 100644 --- a/docs/reference/ilm/ilm-actions.asciidoc +++ b/docs/reference/ilm/ilm-actions.asciidoc @@ -14,9 +14,6 @@ Permanently remove the index. Reduce the number of index segments and purge deleted documents. Makes the index read-only. -<>:: -Freeze the index to minimize its memory footprint. - <>:: Move the index shards to the <> that corresponds to the current {ilm-init} phase. @@ -49,7 +46,6 @@ Ensure that a snapshot exists before deleting the index. include::actions/ilm-allocate.asciidoc[] include::actions/ilm-delete.asciidoc[] include::actions/ilm-forcemerge.asciidoc[] -include::actions/ilm-freeze.asciidoc[] include::actions/ilm-migrate.asciidoc[] include::actions/ilm-readonly.asciidoc[] include::actions/ilm-rollover.asciidoc[] diff --git a/docs/reference/ilm/ilm-index-lifecycle.asciidoc b/docs/reference/ilm/ilm-index-lifecycle.asciidoc index a6f5fd755bf54..9f5e871cb2ad4 100644 --- a/docs/reference/ilm/ilm-index-lifecycle.asciidoc +++ b/docs/reference/ilm/ilm-index-lifecycle.asciidoc @@ -106,7 +106,6 @@ actions in the order listed. - <> - <> - <> - - <> * Frozen - <> * Delete diff --git a/docs/reference/ilm/ilm-overview.asciidoc b/docs/reference/ilm/ilm-overview.asciidoc index bc00a43bcabff..fa65d91d6e7f7 100644 --- a/docs/reference/ilm/ilm-overview.asciidoc +++ b/docs/reference/ilm/ilm-overview.asciidoc @@ -7,8 +7,8 @@ Overview ++++ -You can create and apply {ilm-cap} ({ilm-init}) policies to automatically manage your indices -according to your performance, resiliency, and retention requirements. +You can create and apply {ilm-cap} ({ilm-init}) policies to automatically manage your indices +according to your performance, resiliency, and retention requirements. Index lifecycle policies can trigger actions such as: @@ -17,7 +17,6 @@ size, number of docs, or age. * **Shrink**: Reduces the number of primary shards in an index. * **Force merge**: Triggers a <> to reduce the number of segments in an index's shards. -* **Freeze**: <> an index and makes it read-only. * **Delete**: Permanently remove an index, including all of its data and metadata. @@ -48,9 +47,9 @@ hardware. [IMPORTANT] =========================== -To use {ilm-init}, all nodes in a cluster must run the same version. -Although it might be possible to create and apply policies in a mixed-version cluster, +To use {ilm-init}, all nodes in a cluster must run the same version. +Although it might be possible to create and apply policies in a mixed-version cluster, there is no guarantee they will work as intended. Attempting to use a policy that contains actions that aren't -supported on all nodes in a cluster will cause errors. +supported on all nodes in a cluster will cause errors. =========================== diff --git a/docs/reference/indices.asciidoc b/docs/reference/indices.asciidoc index 650a6239cdbab..335757c8a1813 100644 --- a/docs/reference/indices.asciidoc +++ b/docs/reference/indices.asciidoc @@ -18,7 +18,6 @@ index settings, aliases, mappings, and index templates. * <> * <> * <> -* <> * <> * <> @@ -53,9 +52,9 @@ index settings, aliases, mappings, and index templates. === Index templates: Index templates automatically apply settings, mappings, and aliases to new indices. -They are most often used to configure rolling indices for time series data to -ensure that each new index has the same configuration as the previous one. -The index template associated with a data stream configures its backing indices. +They are most often used to configure rolling indices for time series data to +ensure that each new index has the same configuration as the previous one. +The index template associated with a data stream configures its backing indices. For more information, see <>. * <> @@ -113,7 +112,6 @@ include::indices/indices-exists.asciidoc[] include::indices/field-usage-stats.asciidoc[] include::indices/flush.asciidoc[] include::indices/forcemerge.asciidoc[] -include::indices/apis/freeze.asciidoc[] include::indices/get-alias.asciidoc[] include::indices/get-component-template.asciidoc[] include::indices/get-field-mapping.asciidoc[] diff --git a/docs/reference/indices/apis/freeze.asciidoc b/docs/reference/indices/apis/freeze.asciidoc deleted file mode 100644 index 2a18939fbf1bd..0000000000000 --- a/docs/reference/indices/apis/freeze.asciidoc +++ /dev/null @@ -1,62 +0,0 @@ -[role="xpack"] -[testenv="basic"] -[[freeze-index-api]] -=== Freeze index API -++++ -Freeze index -++++ - -// tag::freeze-api-dep[] -deprecated::[7.14, Frozen indices are no longer useful due to https://www.elastic.co/blog/significantly-decrease-your-elasticsearch-heap-memory-usage[recent improvements in heap memory usage].] -// end::freeze-api-dep[] - -Freezes an index. - -[[freeze-index-api-request]] -==== {api-request-title} - -`POST //_freeze` - -[[freeze-index-api-prereqs]] -==== {api-prereq-title} - -* If the {es} {security-features} are enabled, you must have the `manage` -<> for the target index or index alias. - -[[freeze-index-api-desc]] -==== {api-description-title} - -A frozen index has almost no overhead on the cluster (except for maintaining its -metadata in memory) and is read-only. Read-only indices are blocked for write -operations, such as <> or <>. See <>. - -The current write index on a data stream cannot be frozen. In order to freeze -the current write index, the data stream must first be -<> so that a new write index is created -and then the previous write index can be frozen. - -IMPORTANT: Freezing an index will close the index and reopen it within the same -API call. This causes primaries to not be allocated for a short amount of time -and causes the cluster to go red until the primaries are allocated again. This -limitation might be removed in the future. - -[[freeze-index-api-path-parms]] -==== {api-path-parms-title} - -``:: - (Required, string) Identifier for the index. - -[[freeze-index-api-examples]] -==== {api-examples-title} - -The following example freezes and unfreezes an index: - -[source,console] --------------------------------------------------- -POST /my-index-000001/_freeze -POST /my-index-000001/_unfreeze --------------------------------------------------- -// TEST[skip:unable to ignore deprecation warning] -// TEST[s/^/PUT my-index-000001\n/] - diff --git a/docs/reference/indices/apis/unfreeze.asciidoc b/docs/reference/indices/apis/unfreeze.asciidoc index 5176faf8bce97..96f56df47b9d6 100644 --- a/docs/reference/indices/apis/unfreeze.asciidoc +++ b/docs/reference/indices/apis/unfreeze.asciidoc @@ -6,7 +6,18 @@ Unfreeze index ++++ -deprecated::[7.14, Frozen indices are no longer useful due to https://www.elastic.co/blog/significantly-decrease-your-elasticsearch-heap-memory-usage[recent improvements in heap memory usage].] +[WARNING] +.Deprecated in 7.14 +==== +In 8.0, we removed the ability to freeze an index. In previous versions, +freezing an index reduced its memory overhead. However, frozen indices are no +longer useful due to +https://www.elastic.co/blog/significantly-decrease-your-elasticsearch-heap-memory-usage[recent +improvements in heap memory usage]. + +You can use this API to unfreeze indices that were frozen in 7.x. Frozen indices +are not related to the frozen data tier. +==== Unfreezes an index. @@ -25,12 +36,7 @@ Unfreezes an index. ==== {api-description-title} When a frozen index is unfrozen, the index goes through the normal recovery -process and becomes writeable again. See <>. - -IMPORTANT: Freezing an index will close the index and reopen it within the same -API call. This causes primaries to not be allocated for a short amount of time -and causes the cluster to go red until the primaries are allocated again. This -limitation might be removed in the future. +process and becomes writeable again. [[unfreeze-index-api-path-parms]] ==== {api-path-parms-title} @@ -41,11 +47,10 @@ limitation might be removed in the future. [[unfreeze-index-api-examples]] ==== {api-examples-title} -The following example freezes and unfreezes an index: +The following example unfreezes an index: [source,console] -------------------------------------------------- -POST /my-index-000001/_freeze POST /my-index-000001/_unfreeze -------------------------------------------------- // TEST[s/^/PUT my-index-000001\n/] diff --git a/docs/reference/indices/index-mgmt.asciidoc b/docs/reference/indices/index-mgmt.asciidoc index 0543da9b2a562..5bbb2044ca082 100644 --- a/docs/reference/indices/index-mgmt.asciidoc +++ b/docs/reference/indices/index-mgmt.asciidoc @@ -15,7 +15,7 @@ You'll learn how to: * View and edit index settings. * View mappings and statistics for an index. -* Perform index-level operations, such as refreshes and freezes. +* Perform index-level operations, such as refreshes. * View and manage data streams. * Create index templates to automatically configure new data streams and indices. @@ -43,9 +43,8 @@ Open {kib}'s main menu and click *Stack Management > Index Management*. image::images/index-mgmt/management_index_labels.png[Index Management UI] The *Index Management* page contains an overview of your indices. -Badges indicate if an index is <>, a -<>, or a -<>. +Badges indicate if an index is a <>, a +<>, or <>. Clicking a badge narrows the list to only indices of that type. You can also filter indices using the search bar. @@ -68,7 +67,6 @@ indices on the overview page. The menu includes the following actions: * <> * <> * <> -* <> * <> * *Add* <> diff --git a/docs/reference/indices/resolve.asciidoc b/docs/reference/indices/resolve.asciidoc index 2a64bf9f36a81..78716dd730753 100644 --- a/docs/reference/indices/resolve.asciidoc +++ b/docs/reference/indices/resolve.asciidoc @@ -18,8 +18,6 @@ PUT /remotecluster-bar-01 PUT /freeze-index -POST /freeze-index/_freeze - PUT /my-index-000001 PUT /freeze-index/_alias/f-alias @@ -110,7 +108,6 @@ The API returns the following response: "f-alias" ], "attributes": [ - "frozen", "open" ] }, diff --git a/docs/reference/mapping/params/eager-global-ordinals.asciidoc b/docs/reference/mapping/params/eager-global-ordinals.asciidoc index 27c6f94183134..b09e3eae783c8 100644 --- a/docs/reference/mapping/params/eager-global-ordinals.asciidoc +++ b/docs/reference/mapping/params/eager-global-ordinals.asciidoc @@ -85,13 +85,6 @@ PUT my-index-000001/_mapping ------------ // TEST[continued] -IMPORTANT: On a <>, global ordinals are discarded -after each search and rebuilt again when they're requested. This means that -`eager_global_ordinals` should not be used on frozen indices: it would -cause global ordinals to be reloaded on every search. Instead, the index should -be force-merged to a single segment before being frozen. This avoids building -global ordinals altogether (more details can be found in the next section). - ==== Avoiding global ordinal loading Usually, global ordinals do not present a large overhead in terms of their diff --git a/docs/reference/redirects.asciidoc b/docs/reference/redirects.asciidoc index bc41893897b8e..530104277ff93 100644 --- a/docs/reference/redirects.asciidoc +++ b/docs/reference/redirects.asciidoc @@ -3,6 +3,28 @@ The following pages have moved or been deleted. +[role="exclude",id="freeze-index-api"] +=== Freeze index API + +The freeze index API was removed in 8.0. +// tag::frozen-removal-explanation[] +Frozen indices are no longer useful due to +https://www.elastic.co/blog/significantly-decrease-your-elasticsearch-heap-memory-usage[recent +improvements in heap memory usage]. +// end::frozen-removal-explanation[] + +[role="exclude",id="ilm-freeze"] +=== Freeze {ilm-init} action + +The freeze {ilm-init} action was removed in 8.0. +include::redirects.asciidoc[tag=frozen-removal-explanation] + +[role="exclude",id="ilm-freeze-action"] +=== Freeze {ilm-init} action + +The freeze {ilm-init} action was removed in 8.0. +include::redirects.asciidoc[tag=frozen-removal-explanation] + [role="exclude",id="alias"] === Aliases @@ -989,10 +1011,6 @@ See <>. See <>. -[role="exclude",id="ilm-freeze-action"] -==== Freeze action - -See <>. [role="exclude",id="ilm-migrate-action"] ==== Migrate action @@ -1586,9 +1604,8 @@ See <>. === Frozen indices // tag::frozen-index-redirect[] -include::{es-repo-dir}/indices/apis/freeze.asciidoc[tag=freeze-api-dep] -For API documentation, see <> and <>. +For API documentation, see <>. // end::frozen-index-redirect[] [role="exclude",id="best_practices"] @@ -1613,16 +1630,16 @@ See the {glossary}/terms.html[Elastic glossary]. [role="exclude",id="multi-index"] === Multi-target syntax -See <>. +See <>. [float] [[hidden]] ==== Hidden data streams and indices -See <>. +See <>. [role="exclude",id="date-math-index-names"] -=== Date math support in system and index alias names +=== Date math support in system and index alias names See <>. diff --git a/docs/reference/search/search-your-data/long-running-searches.asciidoc b/docs/reference/search/search-your-data/long-running-searches.asciidoc index 7a2af03895738..c874c8415552c 100644 --- a/docs/reference/search/search-your-data/long-running-searches.asciidoc +++ b/docs/reference/search/search-your-data/long-running-searches.asciidoc @@ -5,8 +5,7 @@ {es} generally allows you to quickly search across big amounts of data. There are situations where a search executes on many shards, possibly against -<> and spanning multiple -<>, for which +large data sets or multiple <>, for which results are not expected to be returned in milliseconds. When you need to execute long-running searches, synchronously waiting for its results to be returned is not ideal. Instead, Async search lets diff --git a/docs/reference/search/search-your-data/search-your-data.asciidoc b/docs/reference/search/search-your-data/search-your-data.asciidoc index 59952312e18e5..61e61fe661943 100644 --- a/docs/reference/search/search-your-data/search-your-data.asciidoc +++ b/docs/reference/search/search-your-data/search-your-data.asciidoc @@ -220,8 +220,7 @@ _synchronous_ by default. The search request waits for complete results before returning a response. However, complete results can take longer for searches across -<> or <>. +large data sets or <>. To avoid long waits, you can run an _asynchronous_, or _async_, search instead. An <> lets you retrieve partial diff --git a/docs/reference/sql/endpoints/jdbc.asciidoc b/docs/reference/sql/endpoints/jdbc.asciidoc index 7b0e74cd4951a..b7f84e7f29001 100644 --- a/docs/reference/sql/endpoints/jdbc.asciidoc +++ b/docs/reference/sql/endpoints/jdbc.asciidoc @@ -145,7 +145,7 @@ will be - typically the first in natural ascending order) for fields with multip [discrete] ==== Index -`index.include.frozen` (default `false`):: Whether to include <> in the query execution or not (default). +`index.include.frozen` (default `false`):: Whether to include frozen-indices in the query execution or not (default). [discrete] ==== Additional diff --git a/docs/reference/sql/language/indices.asciidoc b/docs/reference/sql/language/indices.asciidoc index 6180f5b1c07ca..8887733325a51 100644 --- a/docs/reference/sql/language/indices.asciidoc +++ b/docs/reference/sql/language/indices.asciidoc @@ -49,7 +49,7 @@ Using `SHOW TABLES` command again: include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesLikeWildcard] ---- -The pattern matches all tables that start with `emp`. +The pattern matches all tables that start with `emp`. This command supports _escaping_ as well, for example: @@ -88,7 +88,7 @@ requires the keyword `LIKE` for SQL `LIKE` pattern. [[sql-index-frozen]] === Frozen Indices -By default, {es-sql} doesn't search <>. To +By default, {es-sql} doesn't search <>. To search frozen indices, use one of the following features: dedicated configuration parameter:: @@ -108,4 +108,4 @@ include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesIncludeFrozen] include-tagged::{sql-specs}/docs/docs.csv-spec[fromTableIncludeFrozen] ---- -Unless enabled, frozen indices are completely ignored; it is as if they do not exist and as such, queries ran against them are likely to fail. \ No newline at end of file +Unless enabled, frozen indices are completely ignored; it is as if they do not exist and as such, queries ran against them are likely to fail. diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.freeze.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.freeze.json deleted file mode 100644 index f7ef92dfd4266..0000000000000 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.freeze.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "indices.freeze":{ - "documentation":{ - "url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/freeze-index-api.html", - "description":"Freezes an index. A frozen index has almost no overhead on the cluster (except for maintaining its metadata in memory) and is read-only." - }, - "stability":"stable", - "visibility":"public", - "headers":{ - "accept": [ "application/json"] - }, - "url":{ - "paths":[ - { - "path":"/{index}/_freeze", - "methods":[ - "POST" - ], - "parts":{ - "index":{ - "type":"string", - "description":"The name of the index to freeze" - } - }, - "deprecated":{ - "version":"7.14.0", - "description":"Frozen indices are deprecated because they provide no benefit given improvements in heap memory utilization. They will be removed in a future release." - } - } - ] - }, - "params":{ - "timeout":{ - "type":"time", - "description":"Explicit operation timeout" - }, - "master_timeout":{ - "type":"time", - "description":"Specify timeout for connection to master" - }, - "ignore_unavailable":{ - "type":"boolean", - "description":"Whether specified concrete indices should be ignored when unavailable (missing or closed)" - }, - "allow_no_indices":{ - "type":"boolean", - "description":"Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)" - }, - "expand_wildcards":{ - "type":"enum", - "options":[ - "open", - "closed", - "hidden", - "none", - "all" - ], - "default":"closed", - "description":"Whether to expand wildcard expression to concrete indices that are open, closed or both." - }, - "wait_for_active_shards":{ - "type":"string", - "description":"Sets the number of active shards to wait for before the operation returns." - } - } - } -} diff --git a/x-pack/plugin/build.gradle b/x-pack/plugin/build.gradle index 9e7dbe30f7c2e..15d7056b12bd4 100644 --- a/x-pack/plugin/build.gradle +++ b/x-pack/plugin/build.gradle @@ -156,6 +156,11 @@ tasks.named("yamlRestTestV7CompatTest").configure { // a type field was added to cat.ml_trained_models #73660, this is a backwards compatible change. // still this is a cat api, and we don't support them with rest api compatibility. (the test would be very hard to transform too) 'ml/trained_model_cat_apis/Test cat trained models', + 'service_accounts/10_basic/Test get service accounts', //#76449, will remove upon backport + 'indices.freeze/30_usage/Usage stats on frozen indices', // #70192 -- the freeze index API is removed from 8.0 + 'indices.freeze/20_stats/Translog stats on frozen indices', + 'indices.freeze/10_basic/Basic', + 'indices.freeze/10_basic/Test index options', ].join(',') dependsOn "copyExtraResources" } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/frozen/FreezeRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/frozen/FreezeRequest.java index 78cab77c10c3d..be50b0129f9c1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/frozen/FreezeRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/frozen/FreezeRequest.java @@ -6,6 +6,7 @@ */ package org.elasticsearch.protocol.xpack.frozen; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; @@ -20,10 +21,12 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; +/** + * Despite its name, this class handles only _unfreeze_ requests. + */ public class FreezeRequest extends AcknowledgedRequest implements IndicesRequest.Replaceable { private String[] indices; - private boolean freeze = true; private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT; @@ -35,7 +38,12 @@ public FreezeRequest(StreamInput in) throws IOException { super(in); indicesOptions = IndicesOptions.readIndicesOptions(in); indices = in.readStringArray(); - freeze = in.readBoolean(); + if (in.getVersion().before(Version.V_8_0_0)) { + if (in.readBoolean()) { + // reject freeze requests in mixed clusters + throw new IllegalArgumentException("freeze requests are not supported in clusters with 8.x nodes"); + } + } waitForActiveShards = ActiveShardCount.readFrom(in); } @@ -48,21 +56,15 @@ public ActionRequestValidationException validate() { return validationException; } - public FreezeRequest setFreeze(boolean freeze) { - this.freeze = freeze; - return this; - } - - public boolean freeze() { - return freeze; - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); indicesOptions.writeIndicesOptions(out); out.writeStringArray(indices); - out.writeBoolean(freeze); + if (out.getVersion().before(Version.V_8_0_0)) { + // supports only unfreeze requests + out.writeBoolean(false); + } waitForActiveShards.writeTo(out); } diff --git a/x-pack/plugin/frozen-indices/build.gradle b/x-pack/plugin/frozen-indices/build.gradle index 169b02584f5fe..10d10a5b01680 100644 --- a/x-pack/plugin/frozen-indices/build.gradle +++ b/x-pack/plugin/frozen-indices/build.gradle @@ -12,3 +12,7 @@ dependencies { compileOnly project(path: xpackModule('core')) testImplementation(testArtifact(project(xpackModule('core')))) } + +// Because only unfreezing indices is supported, the tests for freezing indices have been removed +tasks.named("testingConventions").configure { enabled = false } + diff --git a/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexIT.java b/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexIT.java deleted file mode 100644 index 0832830ff01c6..0000000000000 --- a/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexIT.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.index.engine.frozen; - -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.search.ClosePointInTimeAction; -import org.elasticsearch.action.search.ClosePointInTimeRequest; -import org.elasticsearch.action.search.OpenPointInTimeAction; -import org.elasticsearch.action.search.OpenPointInTimeRequest; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.action.support.ActiveShardCount; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.cluster.metadata.DataStream; -import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand; -import org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.mapper.DateFieldMapper; -import org.elasticsearch.index.query.RangeQueryBuilder; -import org.elasticsearch.index.shard.IndexLongFieldRange; -import org.elasticsearch.indices.IndicesService; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.search.builder.PointInTimeBuilder; -import org.elasticsearch.test.ESIntegTestCase; -import org.elasticsearch.test.InternalTestCluster; -import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; -import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction; -import org.elasticsearch.xpack.frozen.FrozenIndices; -import org.joda.time.Instant; - -import java.io.IOException; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_SETTING; -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.sameInstance; - -@ESIntegTestCase.ClusterScope(numDataNodes = 0) -public class FrozenIndexIT extends ESIntegTestCase { - - @Override - protected Collection> nodePlugins() { - return List.of(FrozenIndices.class, LocalStateCompositeXPackPlugin.class); - } - - @Override - protected boolean addMockInternalEngine() { - return false; - } - - public void testTimestampRangeRecalculatedOnStalePrimaryAllocation() throws IOException { - final List nodeNames = internalCluster().startNodes(2); - - createIndex( - "index", - Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).build() - ); - - final IndexResponse indexResponse = client().prepareIndex("index") - .setSource(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD, "2010-01-06T02:03:04.567Z") - .get(); - - ensureGreen("index"); - - assertThat(client().admin().indices().prepareFlush("index").get().getSuccessfulShards(), equalTo(2)); - assertThat(client().admin().indices().prepareRefresh("index").get().getSuccessfulShards(), equalTo(2)); - - final String excludeSetting = INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getConcreteSettingForNamespace("_name").getKey(); - assertAcked( - client().admin().indices().prepareUpdateSettings("index").setSettings(Settings.builder().put(excludeSetting, nodeNames.get(0))) - ); - assertAcked(client().admin().cluster().prepareReroute().add(new CancelAllocationCommand("index", 0, nodeNames.get(0), true))); - assertThat(client().admin().cluster().prepareHealth("index").get().getUnassignedShards(), equalTo(1)); - - assertThat(client().prepareDelete("index", indexResponse.getId()).get().status(), equalTo(RestStatus.OK)); - - assertAcked( - client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index").waitForActiveShards(ActiveShardCount.ONE)).actionGet() - ); - - assertThat( - client().admin().cluster().prepareState().get().getState().metadata().index("index").getTimestampRange(), - sameInstance(IndexLongFieldRange.EMPTY) - ); - - internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeNames.get(1))); - assertThat(client().admin().cluster().prepareHealth("index").get().getUnassignedShards(), equalTo(2)); - assertAcked(client().admin().indices().prepareUpdateSettings("index").setSettings(Settings.builder().putNull(excludeSetting))); - assertThat(client().admin().cluster().prepareHealth("index").get().getUnassignedShards(), equalTo(2)); - - assertAcked( - client().admin().cluster().prepareReroute().add(new AllocateStalePrimaryAllocationCommand("index", 0, nodeNames.get(0), true)) - ); - - ensureYellowAndNoInitializingShards("index"); - - final IndexLongFieldRange timestampFieldRange = client().admin() - .cluster() - .prepareState() - .get() - .getState() - .metadata() - .index("index") - .getTimestampRange(); - assertThat(timestampFieldRange, not(sameInstance(IndexLongFieldRange.UNKNOWN))); - assertThat(timestampFieldRange, not(sameInstance(IndexLongFieldRange.EMPTY))); - assertTrue(timestampFieldRange.isComplete()); - assertThat(timestampFieldRange.getMin(), equalTo(Instant.parse("2010-01-06T02:03:04.567Z").getMillis())); - assertThat(timestampFieldRange.getMax(), equalTo(Instant.parse("2010-01-06T02:03:04.567Z").getMillis())); - } - - public void testTimestampFieldTypeExposedByAllIndicesServices() throws Exception { - internalCluster().startNodes(between(2, 4)); - - final String locale; - final String date; - - switch (between(1, 3)) { - case 1: - locale = ""; - date = "04 Feb 2020 12:01:23Z"; - break; - case 2: - locale = "en_GB"; - date = "04 Feb 2020 12:01:23Z"; - break; - case 3: - locale = "fr_FR"; - date = "04 févr. 2020 12:01:23Z"; - break; - default: - throw new AssertionError("impossible"); - } - - assertAcked( - prepareCreate("index").setSettings( - Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - ) - .setMapping( - jsonBuilder().startObject() - .startObject("_doc") - .startObject("properties") - .startObject(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD) - .field("type", "date") - .field("format", "dd LLL yyyy HH:mm:ssX") - .field("locale", locale) - .endObject() - .endObject() - .endObject() - .endObject() - ) - ); - - final Index index = client().admin() - .cluster() - .prepareState() - .clear() - .setIndices("index") - .setMetadata(true) - .get() - .getState() - .metadata() - .index("index") - .getIndex(); - - ensureGreen("index"); - if (randomBoolean()) { - client().prepareIndex("index").setSource(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD, date).get(); - } - - for (final IndicesService indicesService : internalCluster().getInstances(IndicesService.class)) { - assertNull(indicesService.getTimestampFieldType(index)); - } - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index")).actionGet()); - ensureGreen("index"); - for (final IndicesService indicesService : internalCluster().getInstances(IndicesService.class)) { - final PlainActionFuture timestampFieldTypeFuture = new PlainActionFuture<>(); - assertBusy(() -> { - final DateFieldMapper.DateFieldType timestampFieldType = indicesService.getTimestampFieldType(index); - assertNotNull(timestampFieldType); - timestampFieldTypeFuture.onResponse(timestampFieldType); - }); - assertTrue(timestampFieldTypeFuture.isDone()); - assertThat(timestampFieldTypeFuture.get().dateTimeFormatter().locale().toString(), equalTo(locale)); - assertThat(timestampFieldTypeFuture.get().dateTimeFormatter().parseMillis(date), equalTo(1580817683000L)); - } - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index").setFreeze(false)).actionGet()); - ensureGreen("index"); - for (final IndicesService indicesService : internalCluster().getInstances(IndicesService.class)) { - assertNull(indicesService.getTimestampFieldType(index)); - } - } - - public void testRetryPointInTime() throws Exception { - internalCluster().ensureAtLeastNumDataNodes(1); - final List dataNodes = internalCluster().clusterService() - .state() - .nodes() - .getDataNodes() - .stream() - .map(e -> e.getValue().getName()) - .collect(Collectors.toList()); - final String assignedNode = randomFrom(dataNodes); - final String indexName = "test"; - assertAcked( - client().admin() - .indices() - .prepareCreate(indexName) - .setSettings( - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, between(1, 5)) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put("index.routing.allocation.require._name", assignedNode) - .build() - ) - .setMapping("{\"properties\":{\"created_date\":{\"type\": \"date\", \"format\": \"yyyy-MM-dd\"}}}") - ); - int numDocs = randomIntBetween(1, 100); - for (int i = 0; i < numDocs; i++) { - client().prepareIndex(indexName).setSource("created_date", "2011-02-02").get(); - } - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest(indexName)).actionGet()); - final OpenPointInTimeRequest openPointInTimeRequest = new OpenPointInTimeRequest(indexName).indicesOptions( - IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED - ).keepAlive(TimeValue.timeValueMinutes(2)); - final String pitId = client().execute(OpenPointInTimeAction.INSTANCE, openPointInTimeRequest).actionGet().getPointInTimeId(); - try { - SearchResponse resp = client().prepareSearch() - .setIndices(indexName) - .setPreference(null) - .setPointInTime(new PointInTimeBuilder(pitId)) - .get(); - assertNoFailures(resp); - assertThat(resp.pointInTimeId(), equalTo(pitId)); - assertHitCount(resp, numDocs); - internalCluster().restartNode(assignedNode); - ensureGreen(indexName); - resp = client().prepareSearch() - .setIndices(indexName) - .setQuery(new RangeQueryBuilder("created_date").gte("2011-01-01").lte("2011-12-12")) - .setSearchType(SearchType.QUERY_THEN_FETCH) - .setPreference(null) - .setPreFilterShardSize(between(1, 10)) - .setAllowPartialSearchResults(true) - .setPointInTime(new PointInTimeBuilder(pitId)) - .get(); - assertNoFailures(resp); - assertThat(resp.pointInTimeId(), equalTo(pitId)); - assertHitCount(resp, numDocs); - } finally { - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest(indexName).setFreeze(false)).actionGet()); - client().execute(ClosePointInTimeAction.INSTANCE, new ClosePointInTimeRequest(pitId)).actionGet(); - } - } -} diff --git a/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexRecoveryTests.java b/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexRecoveryTests.java deleted file mode 100644 index 02520be6c691c..0000000000000 --- a/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexRecoveryTests.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.index.engine.frozen; - -import org.elasticsearch.client.Client; -import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.CollectionUtils; -import org.elasticsearch.common.util.set.Sets; -import org.elasticsearch.indices.recovery.RecoveryState; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; -import org.elasticsearch.test.ESIntegTestCase; -import org.elasticsearch.test.InternalTestCluster; -import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction; -import org.elasticsearch.xpack.frozen.FrozenIndices; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static java.util.stream.Collectors.toList; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.not; - -public class FrozenIndexRecoveryTests extends ESIntegTestCase { - - @Override - protected boolean addMockInternalEngine() { - return false; - } - - @Override - protected Collection> nodePlugins() { - return CollectionUtils.appendToCopy(super.nodePlugins(), FrozenIndices.class); - } - - public void testRecoverExistingReplica() throws Exception { - final String indexName = "test-recover-existing-replica"; - internalCluster().ensureAtLeastNumDataNodes(2); - List dataNodes = randomSubsetOf( - 2, - Sets.newHashSet(clusterService().state().nodes().getDataNodes().valuesIt()) - .stream() - .map(DiscoveryNode::getName) - .collect(Collectors.toSet()) - ); - createIndex( - indexName, - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - .put("index.routing.allocation.include._name", String.join(",", dataNodes)) - .build() - ); - indexRandom( - randomBoolean(), - randomBoolean(), - randomBoolean(), - IntStream.range(0, randomIntBetween(0, 50)) - .mapToObj(n -> client().prepareIndex(indexName).setSource("num", n)) - .collect(toList()) - ); - ensureGreen(indexName); - client().admin().indices().prepareFlush(indexName).get(); - // index more documents while one shard copy is offline - internalCluster().restartNode(dataNodes.get(1), new InternalTestCluster.RestartCallback() { - @Override - public Settings onNodeStopped(String nodeName) throws Exception { - Client client = client(dataNodes.get(0)); - int moreDocs = randomIntBetween(1, 50); - for (int i = 0; i < moreDocs; i++) { - client.prepareIndex(indexName).setSource("num", i).get(); - } - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest(indexName)).actionGet()); - return super.onNodeStopped(nodeName); - } - }); - ensureGreen(indexName); - internalCluster().assertSameDocIdsOnShards(); - for (RecoveryState recovery : client().admin().indices().prepareRecoveries(indexName).get().shardRecoveryStates().get(indexName)) { - if (recovery.getPrimary() == false) { - assertThat(recovery.getIndex().fileDetails(), not(empty())); - } - } - internalCluster().fullRestart(); - ensureGreen(indexName); - internalCluster().assertSameDocIdsOnShards(); - for (RecoveryState recovery : client().admin().indices().prepareRecoveries(indexName).get().shardRecoveryStates().get(indexName)) { - if (recovery.getPrimary() == false) { - assertThat(recovery.getIndex().fileDetails(), empty()); - } - } - } -} diff --git a/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexTests.java b/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexTests.java deleted file mode 100644 index 85f1cb26056f3..0000000000000 --- a/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexTests.java +++ /dev/null @@ -1,754 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -package org.elasticsearch.index.engine.frozen; - -import org.elasticsearch.ResourceNotFoundException; -import org.elasticsearch.action.OriginalIndices; -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; -import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.search.ClosePointInTimeAction; -import org.elasticsearch.action.search.ClosePointInTimeRequest; -import org.elasticsearch.action.search.OpenPointInTimeAction; -import org.elasticsearch.action.search.OpenPointInTimeRequest; -import org.elasticsearch.action.search.OpenPointInTimeResponse; -import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.cluster.block.ClusterBlockException; -import org.elasticsearch.cluster.metadata.DataStream; -import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.routing.RecoverySource; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.engine.Engine; -import org.elasticsearch.index.engine.InternalEngine; -import org.elasticsearch.index.mapper.DateFieldMapper; -import org.elasticsearch.index.query.MatchAllQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.shard.IndexLongFieldRange; -import org.elasticsearch.index.shard.IndexShard; -import org.elasticsearch.index.shard.IndexShardTestCase; -import org.elasticsearch.indices.IndicesService; -import org.elasticsearch.indices.recovery.RecoveryState; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.search.SearchContextMissingException; -import org.elasticsearch.search.SearchService; -import org.elasticsearch.search.builder.PointInTimeBuilder; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.internal.AliasFilter; -import org.elasticsearch.search.internal.ShardSearchContextId; -import org.elasticsearch.search.internal.ShardSearchRequest; -import org.elasticsearch.test.ESSingleNodeTestCase; -import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; -import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction; -import org.elasticsearch.xpack.frozen.FrozenIndices; -import org.hamcrest.Matchers; - -import java.io.IOException; -import java.time.Instant; -import java.util.Arrays; -import java.util.Collection; -import java.util.EnumSet; - -import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.sameInstance; - -public class FrozenIndexTests extends ESSingleNodeTestCase { - - @Override - protected Collection> getPlugins() { - return pluginList(FrozenIndices.class, LocalStateCompositeXPackPlugin.class); - } - - String openReaders(TimeValue keepAlive, String... indices) { - OpenPointInTimeRequest request = new OpenPointInTimeRequest(indices).indicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED) - .keepAlive(keepAlive); - final OpenPointInTimeResponse response = client().execute(OpenPointInTimeAction.INSTANCE, request).actionGet(); - return response.getPointInTimeId(); - } - - public void testCloseFreezeAndOpen() throws Exception { - createIndex("index", Settings.builder().put("index.number_of_shards", 2).build()); - client().prepareIndex("index").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - client().prepareIndex("index").setId("2").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - client().prepareIndex("index").setId("3").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index")).actionGet()); - expectThrows( - ClusterBlockException.class, - () -> client().prepareIndex("index").setId("4").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get() - ); - IndicesService indexServices = getInstanceFromNode(IndicesService.class); - Index index = resolveIndex("index"); - IndexService indexService = indexServices.indexServiceSafe(index); - IndexShard shard = indexService.getShard(0); - Engine engine = IndexShardTestCase.getEngine(shard); - assertEquals(0, shard.refreshStats().getTotal()); - boolean useDFS = randomBoolean(); - assertHitCount( - client().prepareSearch() - .setIndicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED) - .setSearchType(useDFS ? SearchType.DFS_QUERY_THEN_FETCH : SearchType.QUERY_THEN_FETCH) - .get(), - 3 - ); - assertThat(engine, Matchers.instanceOf(FrozenEngine.class)); - assertEquals(useDFS ? 3 : 2, shard.refreshStats().getTotal()); - assertFalse(((FrozenEngine) engine).isReaderOpen()); - assertTrue(indexService.getIndexSettings().isSearchThrottled()); - - // now scroll - SearchResponse searchResponse = client().prepareSearch() - .setIndicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED) - .setScroll(TimeValue.timeValueMinutes(1)) - .setSize(1) - .get(); - do { - assertHitCount(searchResponse, 3); - assertEquals(1, searchResponse.getHits().getHits().length); - SearchService searchService = getInstanceFromNode(SearchService.class); - assertThat(searchService.getActiveContexts(), Matchers.greaterThanOrEqualTo(1)); - for (int i = 0; i < 2; i++) { - shard = indexService.getShard(i); - engine = IndexShardTestCase.getEngine(shard); - // scrolls keep the reader open - assertTrue(((FrozenEngine) engine).isReaderOpen()); - } - searchResponse = client().prepareSearchScroll(searchResponse.getScrollId()).setScroll(TimeValue.timeValueMinutes(1)).get(); - } while (searchResponse.getHits().getHits().length > 0); - client().prepareClearScroll().addScrollId(searchResponse.getScrollId()).get(); - - String pitId = openReaders(TimeValue.timeValueMinutes(1), "index"); - try { - for (int from = 0; from < 3; from++) { - searchResponse = client().prepareSearch() - .setIndicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED) - .setPointInTime(new PointInTimeBuilder(pitId)) - .setSize(1) - .setFrom(from) - .get(); - assertHitCount(searchResponse, 3); - assertEquals(1, searchResponse.getHits().getHits().length); - SearchService searchService = getInstanceFromNode(SearchService.class); - assertThat(searchService.getActiveContexts(), Matchers.greaterThanOrEqualTo(1)); - for (int i = 0; i < 2; i++) { - shard = indexService.getShard(i); - engine = IndexShardTestCase.getEngine(shard); - assertFalse(((FrozenEngine) engine).isReaderOpen()); - } - } - } finally { - client().execute(ClosePointInTimeAction.INSTANCE, new ClosePointInTimeRequest(pitId)).get(); - } - } - - public void testSearchAndGetAPIsAreThrottled() throws IOException { - XContentBuilder mapping = XContentFactory.jsonBuilder() - .startObject() - .startObject("_doc") - .startObject("properties") - .startObject("field") - .field("type", "text") - .field("term_vector", "with_positions_offsets_payloads") - .endObject() - .endObject() - .endObject() - .endObject(); - createIndex("index", Settings.builder().put("index.number_of_shards", 2).build(), mapping); - for (int i = 0; i < 10; i++) { - client().prepareIndex("index").setId("" + i).setSource("field", "foo bar baz").get(); - } - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index")).actionGet()); - int numRequests = randomIntBetween(20, 50); - int numRefreshes = 0; - for (int i = 0; i < numRequests; i++) { - numRefreshes++; - // make sure that we don't share the frozen reader in concurrent requests since we acquire the - // searcher and rewrite the request outside of the search-throttle thread pool - switch (randomFrom(Arrays.asList(0, 1, 2))) { - case 0: - client().prepareGet("index", "" + randomIntBetween(0, 9)).get(); - break; - case 1: - client().prepareSearch("index") - .setIndicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED) - .setSearchType(SearchType.QUERY_THEN_FETCH) - .get(); - // in total 4 refreshes 1x query & 1x fetch per shard (we have 2) - numRefreshes += 3; - break; - case 2: - client().prepareTermVectors("index", "" + randomIntBetween(0, 9)).get(); - break; - case 3: - client().prepareExplain("index", "" + randomIntBetween(0, 9)).setQuery(new MatchAllQueryBuilder()).get(); - break; - - default: - assert false; - } - } - IndicesStatsResponse index = client().admin().indices().prepareStats("index").clear().setRefresh(true).get(); - assertEquals(numRefreshes, index.getTotal().refresh.getTotal()); - } - - public void testFreezeAndUnfreeze() { - final IndexService originalIndexService = createIndex("index", Settings.builder().put("index.number_of_shards", 2).build()); - assertThat(originalIndexService.getMetadata().getTimestampRange(), sameInstance(IndexLongFieldRange.UNKNOWN)); - - client().prepareIndex("index").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - client().prepareIndex("index").setId("2").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - client().prepareIndex("index").setId("3").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - - if (randomBoolean()) { - // sometimes close it - assertAcked(client().admin().indices().prepareClose("index").get()); - } - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index")).actionGet()); - { - IndicesService indexServices = getInstanceFromNode(IndicesService.class); - Index index = resolveIndex("index"); - IndexService indexService = indexServices.indexServiceSafe(index); - assertTrue(indexService.getIndexSettings().isSearchThrottled()); - assertTrue(FrozenEngine.INDEX_FROZEN.get(indexService.getIndexSettings().getSettings())); - assertTrue(FrozenEngine.INDEX_FROZEN.exists(indexService.getIndexSettings().getSettings())); - IndexShard shard = indexService.getShard(0); - assertEquals(0, shard.refreshStats().getTotal()); - assertThat(indexService.getMetadata().getTimestampRange(), sameInstance(IndexLongFieldRange.UNKNOWN)); - } - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index").setFreeze(false)).actionGet()); - { - IndicesService indexServices = getInstanceFromNode(IndicesService.class); - Index index = resolveIndex("index"); - IndexService indexService = indexServices.indexServiceSafe(index); - assertFalse(indexService.getIndexSettings().isSearchThrottled()); - assertFalse(FrozenEngine.INDEX_FROZEN.get(indexService.getIndexSettings().getSettings())); - assertFalse(FrozenEngine.INDEX_FROZEN.exists(indexService.getIndexSettings().getSettings())); - IndexShard shard = indexService.getShard(0); - Engine engine = IndexShardTestCase.getEngine(shard); - assertThat(engine, Matchers.instanceOf(InternalEngine.class)); - assertThat(indexService.getMetadata().getTimestampRange(), sameInstance(IndexLongFieldRange.UNKNOWN)); - } - client().prepareIndex("index").setId("4").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - } - - private void assertIndexFrozen(String idx) { - IndicesService indexServices = getInstanceFromNode(IndicesService.class); - Index index = resolveIndex(idx); - IndexService indexService = indexServices.indexServiceSafe(index); - assertTrue(indexService.getIndexSettings().isSearchThrottled()); - assertTrue(FrozenEngine.INDEX_FROZEN.get(indexService.getIndexSettings().getSettings())); - } - - public void testDoubleFreeze() { - createIndex("test-idx", Settings.builder().put("index.number_of_shards", 2).build()); - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("test-idx")).actionGet()); - ResourceNotFoundException exception = expectThrows( - ResourceNotFoundException.class, - () -> client().execute( - FreezeIndexAction.INSTANCE, - new FreezeRequest("test-idx").indicesOptions( - new IndicesOptions(EnumSet.noneOf(IndicesOptions.Option.class), EnumSet.of(IndicesOptions.WildcardStates.OPEN)) - ) - ).actionGet() - ); - assertEquals("no index found to freeze", exception.getMessage()); - } - - public void testUnfreezeClosedIndices() { - createIndex("idx", Settings.builder().put("index.number_of_shards", 1).build()); - client().prepareIndex("idx").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - createIndex("idx-closed", Settings.builder().put("index.number_of_shards", 1).build()); - client().prepareIndex("idx-closed").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("idx")).actionGet()); - assertAcked(client().admin().indices().prepareClose("idx-closed").get()); - assertAcked( - client().execute( - FreezeIndexAction.INSTANCE, - new FreezeRequest("idx*").setFreeze(false).indicesOptions(IndicesOptions.strictExpand()) - ).actionGet() - ); - ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get(); - assertEquals(IndexMetadata.State.CLOSE, stateResponse.getState().getMetadata().index("idx-closed").getState()); - assertEquals(IndexMetadata.State.OPEN, stateResponse.getState().getMetadata().index("idx").getState()); - assertHitCount(client().prepareSearch().get(), 1L); - } - - public void testFreezePattern() { - createIndex("test-idx", Settings.builder().put("index.number_of_shards", 1).build()); - client().prepareIndex("test-idx").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - createIndex("test-idx-1", Settings.builder().put("index.number_of_shards", 1).build()); - client().prepareIndex("test-idx-1").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("test-idx")).actionGet()); - assertIndexFrozen("test-idx"); - - IndicesStatsResponse index = client().admin().indices().prepareStats("test-idx").clear().setRefresh(true).get(); - assertEquals(0, index.getTotal().refresh.getTotal()); - assertHitCount(client().prepareSearch("test-idx").setIndicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED).get(), 1); - index = client().admin().indices().prepareStats("test-idx").clear().setRefresh(true).get(); - assertEquals(1, index.getTotal().refresh.getTotal()); - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("test*")).actionGet()); - assertIndexFrozen("test-idx"); - assertIndexFrozen("test-idx-1"); - index = client().admin().indices().prepareStats("test-idx").clear().setRefresh(true).get(); - assertEquals(1, index.getTotal().refresh.getTotal()); - index = client().admin().indices().prepareStats("test-idx-1").clear().setRefresh(true).get(); - assertEquals(0, index.getTotal().refresh.getTotal()); - } - - public void testCanMatch() throws IOException { - createIndex("index"); - client().prepareIndex("index").setId("1").setSource("field", "2010-01-05T02:00").setRefreshPolicy(IMMEDIATE).execute().actionGet(); - client().prepareIndex("index").setId("2").setSource("field", "2010-01-06T02:00").setRefreshPolicy(IMMEDIATE).execute().actionGet(); - { - IndicesService indexServices = getInstanceFromNode(IndicesService.class); - Index index = resolveIndex("index"); - IndexService indexService = indexServices.indexServiceSafe(index); - IndexShard shard = indexService.getShard(0); - assertFalse(indexService.getIndexSettings().isSearchThrottled()); - SearchService searchService = getInstanceFromNode(SearchService.class); - SearchRequest searchRequest = new SearchRequest().allowPartialSearchResults(true); - assertTrue( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null - ) - ).canMatch() - ); - - SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); - searchRequest.source(sourceBuilder); - sourceBuilder.query(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d/d")); - assertTrue( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null - ) - ).canMatch() - ); - - sourceBuilder.query(QueryBuilders.rangeQuery("field").gt("2010-01-06T02:00").lt("2010-01-07T02:00")); - assertFalse( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null - ) - ).canMatch() - ); - } - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index")).actionGet()); - { - - IndicesService indexServices = getInstanceFromNode(IndicesService.class); - Index index = resolveIndex("index"); - IndexService indexService = indexServices.indexServiceSafe(index); - IndexShard shard = indexService.getShard(0); - assertTrue(indexService.getIndexSettings().isSearchThrottled()); - SearchService searchService = getInstanceFromNode(SearchService.class); - SearchRequest searchRequest = new SearchRequest().allowPartialSearchResults(true); - assertTrue( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null - ) - ).canMatch() - ); - - SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); - sourceBuilder.query(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d/d")); - searchRequest.source(sourceBuilder); - assertTrue( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null - ) - ).canMatch() - ); - - sourceBuilder.query(QueryBuilders.rangeQuery("field").gt("2010-01-06T02:00").lt("2010-01-07T02:00")); - assertFalse( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null - ) - ).canMatch() - ); - - IndicesStatsResponse response = client().admin().indices().prepareStats("index").clear().setRefresh(true).get(); - assertEquals(0, response.getTotal().refresh.getTotal()); - - // Retry with point in time - PlainActionFuture openContextFuture = new PlainActionFuture<>(); - searchService.openReaderContext(shard.shardId(), TimeValue.timeValueSeconds(60), openContextFuture); - final ShardSearchContextId contextId = openContextFuture.actionGet(TimeValue.timeValueSeconds(60)); - assertNotNull(contextId.getSearcherId()); - sourceBuilder.query(QueryBuilders.rangeQuery("field").gt("2010-01-06T02:00").lt("2010-01-07T02:00")); - assertFalse( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null, - contextId, - null - ) - ).canMatch() - ); - - assertTrue(searchService.freeReaderContext(contextId)); - sourceBuilder.query(QueryBuilders.rangeQuery("field").gt("2010-01-06T02:00").lt("2010-01-07T02:00")); - assertFalse( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null, - contextId, - null - ) - ).canMatch() - ); - - expectThrows(SearchContextMissingException.class, () -> { - ShardSearchContextId withoutCommitId = new ShardSearchContextId(contextId.getSessionId(), contextId.getId(), null); - sourceBuilder.query(QueryBuilders.rangeQuery("field").gt("2010-01-06T02:00").lt("2010-01-07T02:00")); - assertFalse( - searchService.canMatch( - new ShardSearchRequest( - OriginalIndices.NONE, - searchRequest, - shard.shardId(), - 0, - 1, - new AliasFilter(null, Strings.EMPTY_ARRAY), - 1f, - -1, - null, - withoutCommitId, - null - ) - ).canMatch() - ); - }); - } - } - - public void testWriteToFrozenIndex() { - createIndex("idx", Settings.builder().put("index.number_of_shards", 1).build()); - client().prepareIndex("idx").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get(); - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("idx")).actionGet()); - assertIndexFrozen("idx"); - expectThrows( - ClusterBlockException.class, - () -> client().prepareIndex("idx").setId("2").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get() - ); - } - - public void testIgnoreUnavailable() { - createIndex("idx", Settings.builder().put("index.number_of_shards", 1).build()); - createIndex("idx-close", Settings.builder().put("index.number_of_shards", 1).build()); - assertAcked(client().admin().indices().prepareClose("idx-close")); - assertAcked( - client().execute( - FreezeIndexAction.INSTANCE, - new FreezeRequest("idx*", "not_available").indicesOptions( - IndicesOptions.fromParameters(null, "true", null, null, IndicesOptions.strictExpandOpen()) - ) - ).actionGet() - ); - assertIndexFrozen("idx"); - assertEquals( - IndexMetadata.State.CLOSE, - client().admin().cluster().prepareState().get().getState().metadata().index("idx-close").getState() - ); - } - - public void testUnfreezeClosedIndex() { - createIndex("idx", Settings.builder().put("index.number_of_shards", 1).build()); - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("idx")).actionGet()); - assertAcked(client().admin().indices().prepareClose("idx")); - assertEquals( - IndexMetadata.State.CLOSE, - client().admin().cluster().prepareState().get().getState().metadata().index("idx").getState() - ); - expectThrows( - IndexNotFoundException.class, - () -> client().execute( - FreezeIndexAction.INSTANCE, - new FreezeRequest("id*").setFreeze(false) - .indicesOptions( - new IndicesOptions(EnumSet.noneOf(IndicesOptions.Option.class), EnumSet.of(IndicesOptions.WildcardStates.OPEN)) - ) - ).actionGet() - ); - // we don't resolve to closed indices - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("idx").setFreeze(false)).actionGet()); - assertEquals( - IndexMetadata.State.OPEN, - client().admin().cluster().prepareState().get().getState().metadata().index("idx").getState() - ); - } - - public void testFreezeIndexIncreasesIndexSettingsVersion() { - final String index = "test"; - createIndex(index, Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).build()); - client().prepareIndex(index).setSource("field", "value").execute().actionGet(); - - final long settingsVersion = client().admin() - .cluster() - .prepareState() - .get() - .getState() - .metadata() - .index(index) - .getSettingsVersion(); - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest(index)).actionGet()); - assertIndexFrozen(index); - assertThat( - client().admin().cluster().prepareState().get().getState().metadata().index(index).getSettingsVersion(), - greaterThan(settingsVersion) - ); - } - - public void testFreezeEmptyIndexWithTranslogOps() throws Exception { - final String indexName = "empty"; - createIndex( - indexName, - Settings.builder() - .put("index.number_of_shards", 1) - .put("index.number_of_replicas", 0) - .put("index.refresh_interval", TimeValue.MINUS_ONE) - .build() - ); - - final long nbNoOps = randomIntBetween(1, 10); - for (long i = 0; i < nbNoOps; i++) { - final DeleteResponse deleteResponse = client().prepareDelete(indexName, Long.toString(i)).get(); - assertThat(deleteResponse.status(), is(RestStatus.NOT_FOUND)); - } - - final IndicesService indicesService = getInstanceFromNode(IndicesService.class); - assertBusy(() -> { - final Index index = client().admin().cluster().prepareState().get().getState().metadata().index(indexName).getIndex(); - final IndexService indexService = indicesService.indexService(index); - assertThat(indexService.hasShard(0), is(true)); - assertThat(indexService.getShard(0).getLastKnownGlobalCheckpoint(), greaterThanOrEqualTo(nbNoOps - 1L)); - }); - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest(indexName)).actionGet()); - assertIndexFrozen(indexName); - } - - public void testRecoveryState() { - final String indexName = "index_recovery_state"; - createIndex(indexName, Settings.builder().put("index.number_of_replicas", 0).build()); - - final long nbDocs = randomIntBetween(0, 50); - for (long i = 0; i < nbDocs; i++) { - final IndexResponse indexResponse = client().prepareIndex(indexName).setId(Long.toString(i)).setSource("field", i).get(); - assertThat(indexResponse.status(), is(RestStatus.CREATED)); - } - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest(indexName)).actionGet()); - assertIndexFrozen(indexName); - - final IndexMetadata indexMetadata = client().admin().cluster().prepareState().get().getState().metadata().index(indexName); - final IndexService indexService = getInstanceFromNode(IndicesService.class).indexService(indexMetadata.getIndex()); - for (int i = 0; i < indexMetadata.getNumberOfShards(); i++) { - final IndexShard indexShard = indexService.getShardOrNull(i); - assertThat("Shard [" + i + "] is missing for index " + indexMetadata.getIndex(), indexShard, notNullValue()); - final RecoveryState recoveryState = indexShard.recoveryState(); - assertThat(recoveryState.getRecoverySource(), is(RecoverySource.ExistingStoreRecoverySource.INSTANCE)); - assertThat(recoveryState.getStage(), is(RecoveryState.Stage.DONE)); - assertThat(recoveryState.getTargetNode(), notNullValue()); - assertThat(recoveryState.getIndex().totalFileCount(), greaterThan(0)); - assertThat(recoveryState.getIndex().reusedFileCount(), greaterThan(0)); - assertThat(recoveryState.getTranslog().recoveredOperations(), equalTo(0)); - assertThat(recoveryState.getTranslog().totalOperations(), equalTo(0)); - assertThat(recoveryState.getTranslog().recoveredPercent(), equalTo(100.0f)); - } - } - - public void testTranslogStats() { - final String indexName = "test"; - IndexService indexService = createIndex(indexName, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build()); - - final int nbDocs = randomIntBetween(0, 50); - int uncommittedOps = 0; - for (long i = 0; i < nbDocs; i++) { - final IndexResponse indexResponse = client().prepareIndex(indexName).setId(Long.toString(i)).setSource("field", i).get(); - assertThat(indexResponse.status(), is(RestStatus.CREATED)); - if (rarely()) { - client().admin().indices().prepareFlush(indexName).get(); - uncommittedOps = 0; - } else { - uncommittedOps += 1; - } - } - - IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().setTranslog(true).get(); - assertThat(stats.getIndex(indexName), notNullValue()); - assertThat( - stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), - equalTo(indexService.getIndexSettings().isSoftDeleteEnabled() ? uncommittedOps : nbDocs) - ); - assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().getUncommittedOperations(), equalTo(uncommittedOps)); - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest(indexName)).actionGet()); - assertIndexFrozen(indexName); - - IndicesOptions indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN; - stats = client().admin().indices().prepareStats(indexName).setIndicesOptions(indicesOptions).clear().setTranslog(true).get(); - assertThat(stats.getIndex(indexName), notNullValue()); - assertThat( - stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), - equalTo(indexService.getIndexSettings().isSoftDeleteEnabled() ? 0 : nbDocs) - ); - assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().getUncommittedOperations(), equalTo(0)); - } - - public void testComputesTimestampRangeFromMilliseconds() { - final int shardCount = between(1, 3); - createIndex("index", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, shardCount).build()); - client().prepareIndex("index").setSource(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD, "2010-01-05T01:02:03.456Z").get(); - client().prepareIndex("index").setSource(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD, "2010-01-06T02:03:04.567Z").get(); - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index")).actionGet()); - - final IndexLongFieldRange timestampFieldRange = client().admin() - .cluster() - .prepareState() - .get() - .getState() - .metadata() - .index("index") - .getTimestampRange(); - assertThat(timestampFieldRange, not(sameInstance(IndexLongFieldRange.UNKNOWN))); - assertThat(timestampFieldRange, not(sameInstance(IndexLongFieldRange.EMPTY))); - assertTrue(timestampFieldRange.isComplete()); - assertThat(timestampFieldRange.getMin(), equalTo(Instant.parse("2010-01-05T01:02:03.456Z").toEpochMilli())); - assertThat(timestampFieldRange.getMax(), equalTo(Instant.parse("2010-01-06T02:03:04.567Z").toEpochMilli())); - } - - public void testComputesTimestampRangeFromNanoseconds() throws IOException { - - final XContentBuilder mapping = XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD) - .field("type", "date_nanos") - .field("format", "strict_date_optional_time_nanos") - .endObject() - .endObject() - .endObject(); - - final int shardCount = between(1, 3); - createIndex("index", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, shardCount).build(), mapping); - client().prepareIndex("index").setSource(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD, "2010-01-05T01:02:03.456789012Z").get(); - client().prepareIndex("index").setSource(DataStream.TimestampField.FIXED_TIMESTAMP_FIELD, "2010-01-06T02:03:04.567890123Z").get(); - - assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index")).actionGet()); - - final IndexLongFieldRange timestampFieldRange = client().admin() - .cluster() - .prepareState() - .get() - .getState() - .metadata() - .index("index") - .getTimestampRange(); - assertThat(timestampFieldRange, not(sameInstance(IndexLongFieldRange.UNKNOWN))); - assertThat(timestampFieldRange, not(sameInstance(IndexLongFieldRange.EMPTY))); - assertTrue(timestampFieldRange.isComplete()); - final DateFieldMapper.Resolution resolution = DateFieldMapper.Resolution.NANOSECONDS; - assertThat(timestampFieldRange.getMin(), equalTo(resolution.convert(Instant.parse("2010-01-05T01:02:03.456789012Z")))); - assertThat(timestampFieldRange.getMax(), equalTo(resolution.convert(Instant.parse("2010-01-06T02:03:04.567890123Z")))); - } - -} diff --git a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java index 6e834ddb75288..177670bcd328b 100644 --- a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java +++ b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java @@ -15,21 +15,18 @@ import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; import org.elasticsearch.action.admin.indices.open.OpenIndexClusterStateUpdateRequest; import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.action.support.DestructiveOperations; import org.elasticsearch.action.support.master.TransportMasterNodeAction; import org.elasticsearch.cluster.AckedClusterStateUpdateTask; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.block.ClusterBlocks; -import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.metadata.MetadataIndexStateService; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; @@ -45,13 +42,11 @@ import java.util.ArrayList; import java.util.List; -import java.util.SortedMap; public final class TransportFreezeIndexAction extends TransportMasterNodeAction { private static final Logger logger = LogManager.getLogger(TransportFreezeIndexAction.class); - private final DestructiveOperations destructiveOperations; private final MetadataIndexStateService indexStateService; @Inject @@ -61,8 +56,7 @@ public TransportFreezeIndexAction( ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, - IndexNameExpressionResolver indexNameExpressionResolver, - DestructiveOperations destructiveOperations + IndexNameExpressionResolver indexNameExpressionResolver ) { super( FreezeIndexAction.NAME, @@ -75,13 +69,11 @@ public TransportFreezeIndexAction( FreezeResponse::new, ThreadPool.Names.SAME ); - this.destructiveOperations = destructiveOperations; this.indexStateService = indexStateService; } @Override protected void doExecute(Task task, FreezeRequest request, ActionListener listener) { - destructiveOperations.failDestructive(request.indices()); super.doExecute(task, request, listener); } @@ -90,16 +82,14 @@ private Index[] resolveIndices(FreezeRequest request, ClusterState state) { for (Index index : indexNameExpressionResolver.concreteIndices(state, request)) { IndexMetadata metadata = state.metadata().index(index); Settings settings = metadata.getSettings(); - // only unfreeze if we are frozen and only freeze if we are not frozen already. - // this prevents all indices that are already frozen that match a pattern to - // go through the cycles again. - if ((request.freeze() && FrozenEngine.INDEX_FROZEN.get(settings) == false) - || (request.freeze() == false && FrozenEngine.INDEX_FROZEN.get(settings))) { + // only unfreeze if we are frozen so that all indices that are already unfrozen that match a pattern + // do not go through the cycles again + if (FrozenEngine.INDEX_FROZEN.get(settings)) { indices.add(index); } } if (indices.isEmpty() && request.indicesOptions().allowNoIndices() == false) { - throw new ResourceNotFoundException("no index found to " + (request.freeze() ? "freeze" : "unfreeze")); + throw new ResourceNotFoundException("no index found to unfreeze"); } return indices.toArray(Index.EMPTY_ARRAY); } @@ -161,24 +151,6 @@ private void toggleFrozenSettings( })) { @Override public ClusterState execute(ClusterState currentState) { - List writeIndices = new ArrayList<>(); - SortedMap lookup = currentState.metadata().getIndicesLookup(); - for (Index index : concreteIndices) { - IndexAbstraction ia = lookup.get(index.getName()); - if (ia != null - && ia.getParentDataStream() != null - && ia.getParentDataStream().getWriteIndex().getIndex().equals(index)) { - writeIndices.add(index.getName()); - } - } - if (writeIndices.size() > 0) { - throw new IllegalArgumentException( - "cannot freeze the following data stream write indices [" - + Strings.collectionToCommaDelimitedString(writeIndices) - + "]" - ); - } - final Metadata.Builder builder = Metadata.builder(currentState.metadata()); ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()); for (Index index : concreteIndices) { @@ -187,18 +159,11 @@ public ClusterState execute(ClusterState currentState) { throw new IllegalStateException("index [" + index.getName() + "] is not closed"); } final Settings.Builder settingsBuilder = Settings.builder().put(indexMetadata.getSettings()); - if (request.freeze()) { - settingsBuilder.put(FrozenEngine.INDEX_FROZEN.getKey(), true); - settingsBuilder.put(IndexSettings.INDEX_SEARCH_THROTTLED.getKey(), true); - settingsBuilder.put("index.blocks.write", true); - blocks.addIndexBlock(index.getName(), IndexMetadata.INDEX_WRITE_BLOCK); - } else { - settingsBuilder.remove(FrozenEngine.INDEX_FROZEN.getKey()); - settingsBuilder.remove(IndexSettings.INDEX_SEARCH_THROTTLED.getKey()); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings()) == false) { - settingsBuilder.remove("index.blocks.write"); - blocks.removeIndexBlock(index.getName(), IndexMetadata.INDEX_WRITE_BLOCK); - } + settingsBuilder.remove(FrozenEngine.INDEX_FROZEN.getKey()); + settingsBuilder.remove(IndexSettings.INDEX_SEARCH_THROTTLED.getKey()); + if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings()) == false) { + settingsBuilder.remove("index.blocks.write"); + blocks.removeIndexBlock(index.getName(), IndexMetadata.INDEX_WRITE_BLOCK); } builder.put( IndexMetadata.builder(indexMetadata) diff --git a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java index acc98a5d26ebe..c11aac3e0ea66 100644 --- a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java +++ b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java @@ -29,25 +29,21 @@ public final class RestFreezeIndexAction extends BaseRestHandler { @Override public List routes() { - return List.of( - Route.builder(POST, "/{index}/_freeze").deprecated(DEPRECATION_WARNING, DEPRECATION_VERSION).build(), - Route.builder(POST, "/{index}/_unfreeze").deprecated(DEPRECATION_WARNING, DEPRECATION_VERSION).build() - ); + return List.of(Route.builder(POST, "/{index}/_unfreeze").deprecated(DEPRECATION_WARNING, DEPRECATION_VERSION).build()); } @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { - boolean freeze = request.path().endsWith("/_freeze"); - FreezeRequest freezeRequest = new FreezeRequest(Strings.splitStringByCommaToArray(request.param("index"))); - freezeRequest.timeout(request.paramAsTime("timeout", freezeRequest.timeout())); - freezeRequest.masterNodeTimeout(request.paramAsTime("master_timeout", freezeRequest.masterNodeTimeout())); - freezeRequest.indicesOptions(IndicesOptions.fromRequest(request, freezeRequest.indicesOptions())); + // Supports only _unfreeze_ requests + FreezeRequest unfreezeRequest = new FreezeRequest(Strings.splitStringByCommaToArray(request.param("index"))); + unfreezeRequest.timeout(request.paramAsTime("timeout", unfreezeRequest.timeout())); + unfreezeRequest.masterNodeTimeout(request.paramAsTime("master_timeout", unfreezeRequest.masterNodeTimeout())); + unfreezeRequest.indicesOptions(IndicesOptions.fromRequest(request, unfreezeRequest.indicesOptions())); String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { - freezeRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards)); + unfreezeRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards)); } - freezeRequest.setFreeze(freeze); - return channel -> client.execute(FreezeIndexAction.INSTANCE, freezeRequest, new RestToXContentListener<>(channel)); + return channel -> client.execute(FreezeIndexAction.INSTANCE, unfreezeRequest, new RestToXContentListener<>(channel)); } @Override diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java index 8f0d0aeb767b2..9c4d90379556c 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java @@ -41,7 +41,6 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; public abstract class AbstractSearchableSnapshotsRestTestCase extends ESRestTestCase { @@ -176,30 +175,6 @@ 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); - final Map frozenIndexSettings = indexSettings(restoredIndexName); - assertThat(Boolean.valueOf(extractValue(frozenIndexSettings, "index.frozen")), equalTo(true)); - assertThat(Boolean.valueOf(extractValue(frozenIndexSettings, "index.search.throttled")), equalTo(true)); - 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); - final Map unfrozenIndexSettings = indexSettings(restoredIndexName); - assertThat(extractValue(unfrozenIndexSettings, "index.frozen"), nullValue()); - assertThat(extractValue(unfrozenIndexSettings, "index.search.throttled"), nullValue()); - assertThat(Boolean.valueOf(extractValue(frozenIndexSettings, "index.blocks.write")), equalTo(true)); - }); - } - public void testSourceOnlyRepository() throws Exception { runSearchableSnapshotsTest((indexName, numDocs) -> { for (int i = 0; i < 10; i++) { diff --git a/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java b/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java index 209fe2c9a9205..5f96584059012 100644 --- a/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java +++ b/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java @@ -65,6 +65,7 @@ public class JdbcConfiguration extends ConnectionConfiguration { static final String FIELD_MULTI_VALUE_LENIENCY = "field.multi.value.leniency"; static final String FIELD_MULTI_VALUE_LENIENCY_DEFAULT = "true"; + // TODO: remove this setting in 9.0 when frozen indices are removed static final String INDEX_INCLUDE_FROZEN = "index.include.frozen"; static final String INDEX_INCLUDE_FROZEN_DEFAULT = "false"; diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/10_basic.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/10_basic.yml deleted file mode 100644 index e7e123abd8770..0000000000000 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/10_basic.yml +++ /dev/null @@ -1,178 +0,0 @@ ---- -"Basic": -- skip: - features: [ "warnings" ] - -- do: - index: - index: test - id: "1" - body: { "foo": "Hello: 1" } -- do: - index: - index: test - id: "2" - 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 - -- do: - search: - rest_total_hits_as_int: true - index: test - ignore_throttled: false - body: - query: - match: - foo: hello - -- match: {hits.total: 2} - -# 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 - -- do: - search: - rest_total_hits_as_int: true - index: _all - body: - query: - match: - foo: hello - -- match: {hits.total: 2} - -- do: - index: - index: test-01 - id: "1" - body: { "foo": "Hello: 01" } - - -- 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* - -- do: - search: - rest_total_hits_as_int: true - index: _all - ignore_throttled: false - body: - query: - match: - foo: hello - -- match: {hits.total: 3} - -- do: - search: - rest_total_hits_as_int: true - index: _all - body: - query: - match: - foo: hello - -- match: {hits.total: 0} - ---- -"Test index options": - -- skip: - features: ["allowed_warnings", "warnings"] - -- do: - index: - index: test - id: "1" - body: { "foo": "Hello: 1" } - -- do: - index: - index: test-close - id: "1" - body: { "foo": "Hello: 1" } - -- do: - indices.close: - index: test-close - allowed_warnings: - - "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 - -- do: - search: - rest_total_hits_as_int: true - index: _all - body: - query: - match: - foo: hello - -- match: {hits.total: 0} - -- do: - search: - rest_total_hits_as_int: true - index: _all - ignore_throttled: false - body: - query: - match: - foo: hello - -- match: {hits.total: 1} - ---- -"Cannot freeze write index for data stream": - - skip: - version: " - 7.9.99" - reason: "enable in 7.9+ when backported" - features: allowed_warnings - - - do: - allowed_warnings: - - "index template [my-template1] has index patterns [simple-data-stream1] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template1] will take precedence during new index creation" - indices.put_index_template: - name: my-template1 - body: - index_patterns: [simple-data-stream1] - template: - mappings: - properties: - '@timestamp': - type: date - data_stream: {} - - - do: - indices.create_data_stream: - name: simple-data-stream1 - - is_true: acknowledged - - - do: - catch: bad_request - indices.freeze: - index: ".ds-simple-data-stream1-*000001" - - - do: - indices.delete_data_stream: - name: simple-data-stream1 - - is_true: acknowledged - diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/20_stats.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/20_stats.yml deleted file mode 100644 index 0ce2b8c22fd61..0000000000000 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/20_stats.yml +++ /dev/null @@ -1,67 +0,0 @@ ---- -setup: - - do: - indices.create: - index: test - - do: - cluster.health: - wait_for_no_initializing_shards: true - ---- -"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" - - - do: - index: - index: test - id: 1 - body: { "foo": "bar" } - - - do: - index: - index: test - id: 2 - body: { "foo": "bar" } - - - do: - index: - index: test - id: 3 - body: { "foo": "bar" } - - - do: - indices.stats: - metric: [ translog ] - - match: { indices.test.primaries.translog.operations: 3 } - - match: { indices.test.primaries.translog.uncommitted_operations: 3 } - - # 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 - - - do: - indices.stats: - metric: [ translog ] - - match: { indices.test.primaries.translog.operations: 0 } - - match: { indices.test.primaries.translog.uncommitted_operations: 0 } - - # 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 - - - do: - indices.stats: - metric: [ translog ] - - match: { indices.test.primaries.translog.operations: 0 } - - match: { indices.test.primaries.translog.uncommitted_operations: 0 } diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/30_usage.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/30_usage.yml deleted file mode 100644 index f874cda55ac95..0000000000000 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/indices.freeze/30_usage.yml +++ /dev/null @@ -1,65 +0,0 @@ ---- -setup: - - do: - indices.create: - index: test - - do: - cluster.health: - wait_for_no_initializing_shards: true - ---- -"Usage stats on frozen indices": - - skip: - features: [ "warnings" ] - version: " - 7.3.99" - reason: "frozen indices have usage stats starting in version 7.4" - - - do: - index: - index: test - id: 1 - body: { "foo": "bar" } - - - do: - index: - index: test - id: 2 - body: { "foo": "bar" } - - - do: - index: - index: test - id: 3 - body: { "foo": "bar" } - - - do: {xpack.usage: {}} - - match: { frozen_indices.available: true } - - match: { frozen_indices.enabled: true } - - match: { frozen_indices.indices_count: 0 } - - # 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 - - - - do: {xpack.usage: {}} - - match: { frozen_indices.available: true } - - match: { frozen_indices.enabled: true } - - match: { frozen_indices.indices_count: 1 } - - # 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 - - - do: {xpack.usage: {}} - - match: { frozen_indices.available: true } - - match: { frozen_indices.enabled: true } - - match: { frozen_indices.indices_count: 0 } diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java index 47975872ffe10..87b5862463088 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.index.IndexSettings; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.test.StreamsUtils; @@ -703,57 +702,6 @@ private void waitForRollUpJob(final String rollupJob, final Matcher expectedS return null; } - public void testFrozenIndexAfterRestarted() throws Exception { - final String index = "test_frozen_index"; - if (isRunningAgainstOldCluster()) { - Settings.Builder settings = Settings.builder(); - if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) { - settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); - } - String mappings = randomBoolean() ? "\"_source\": { \"enabled\": false}" : null; - createIndex(index, settings.build(), mappings); - ensureGreen(index); - int numDocs = randomIntBetween(10, 500); - for (int i = 0; i < numDocs; i++) { - int id = randomIntBetween(0, 100); - final Request indexRequest = new Request("POST", "/" + index + "/" + "_doc/" + id); - indexRequest.setJsonEntity(Strings.toString(JsonXContent.contentBuilder().startObject().field("f", "v").endObject())); - assertOK(client().performRequest(indexRequest)); - if (rarely()) { - flush(index, randomBoolean()); - } - } - } else { - ensureGreen(index); - final int totalHits = (int) XContentMapValues.extractValue("hits.total.value", - entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search")))); - 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)); - 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); - } - } - @SuppressWarnings("unchecked") public void testDataStreams() throws Exception { assumeTrue("no data streams in versions before " + Version.V_7_9_0, getOldClusterVersion().onOrAfter(Version.V_7_9_0));