From cae49b0fd76474d5575d38ccef18a0a2fe2dd918 Mon Sep 17 00:00:00 2001 From: Dan Hermann Date: Tue, 30 Jun 2020 14:30:32 -0500 Subject: [PATCH] [7.x] Add data stream support to open index API (#58767) --- .../test/indices.open/10_basic.yml | 69 +++++++++++++++++++ .../elasticsearch/indices/DataStreamIT.java | 2 + .../open/TransportOpenIndexAction.java | 4 +- 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml index 33e01c9c258..b775db042bf 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml @@ -155,3 +155,72 @@ indices.delete_data_stream: name: simple-data-stream1 - is_true: acknowledged + +--- +"Open write index for data stream opens all backing indices": + - skip: + version: " - 7.99.99" + reason: "change to - 7.8.99 after backport" + 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: + timestamp_field: '@timestamp' + + - do: + indices.create_data_stream: + name: simple-data-stream1 + - is_true: acknowledged + + # rollover data stream twice to create new backing indices + - do: + indices.rollover: + alias: "simple-data-stream1" + + - match: { old_index: .ds-simple-data-stream1-000001 } + - match: { new_index: .ds-simple-data-stream1-000002 } + - match: { rolled_over: true } + - match: { dry_run: false } + + - do: + indices.rollover: + alias: "simple-data-stream1" + + - match: { old_index: .ds-simple-data-stream1-000002 } + - match: { new_index: .ds-simple-data-stream1-000003 } + - match: { rolled_over: true } + - match: { dry_run: false } + + - do: + indices.close: + index: ".ds-simple-data-stream1-000001,.ds-simple-data-stream1-000002" + - is_true: acknowledged + + - do: + indices.open: + index: simple-data-stream1 + - is_true: acknowledged + + # all closed backing indices should be re-opened and returned + - do: + indices.get: + index: ".ds-simple-data-stream1-*" + + - is_true: \.ds-simple-data-stream1-000001.settings + - is_true: \.ds-simple-data-stream1-000002.settings + + - do: + indices.delete_data_stream: + name: simple-data-stream1 + - is_true: acknowledged diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/DataStreamIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/DataStreamIT.java index 41043ed1c4f..5fd0f54b3ad 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/DataStreamIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/DataStreamIT.java @@ -392,6 +392,7 @@ public class DataStreamIT extends ESIntegTestCase { verifyResolvability(dataStreamName, client().admin().cluster().prepareState().setIndices(dataStreamName), false); verifyResolvability(dataStreamName, client().prepareFieldCaps(dataStreamName).setFields("*"), false); verifyResolvability(dataStreamName, client().admin().indices().prepareGetIndex().addIndices(dataStreamName), false); + verifyResolvability(dataStreamName, client().admin().indices().prepareOpen(dataStreamName), false); request = new CreateDataStreamAction.Request("logs-barbaz"); client().admin().indices().createDataStream(request).actionGet(); @@ -421,6 +422,7 @@ public class DataStreamIT extends ESIntegTestCase { verifyResolvability(wildcardExpression, client().admin().cluster().prepareState().setIndices(wildcardExpression), false); verifyResolvability(wildcardExpression, client().prepareFieldCaps(wildcardExpression).setFields("*"), false); verifyResolvability(wildcardExpression, client().admin().indices().prepareGetIndex().addIndices(wildcardExpression), false); + verifyResolvability(wildcardExpression, client().admin().indices().prepareOpen(wildcardExpression), false); } public void testCannotDeleteComposableTemplateUsedByDataStream() throws Exception { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java index c30a56c7fe8..1778ecf7190 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java @@ -83,13 +83,13 @@ public class TransportOpenIndexAction extends TransportMasterNodeAction listener) { - final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request, true); if (concreteIndices == null || concreteIndices.length == 0) { listener.onResponse(new OpenIndexResponse(true, true)); return;