From 911d46370e5ad8c1f83f8c47ac2484422be2d8e4 Mon Sep 17 00:00:00 2001 From: Dan Hermann Date: Tue, 16 Jun 2020 10:53:20 -0500 Subject: [PATCH] Prohibit clone, shrink, and split on a data stream's write index --- .../test/indices.clone/10_basic.yml | 44 +++++++++++++++++++ .../test/indices.shrink/10_basic.yml | 43 ++++++++++++++++++ .../test/indices.split/10_basic.yml | 44 +++++++++++++++++++ .../metadata/MetadataCreateIndexService.java | 9 ++++ 4 files changed, 140 insertions(+) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.clone/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.clone/10_basic.yml index 412d29905ff..5424b0c55e1 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.clone/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.clone/10_basic.yml @@ -109,3 +109,47 @@ setup: settings: index.number_of_replicas: 0 index.number_of_shards: 6 + +--- +"Prohibit clone on data stream's write index": + - skip: + version: " - 7.99.99" + reason: needs 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 + + - do: + catch: bad_request + indices.clone: + index: ".ds-simple-data-stream1-000001" + target: "target" + wait_for_active_shards: 1 + master_timeout: 10s + body: + settings: + index.number_of_replicas: 0 + index.number_of_shards: 2 + + - do: + indices.delete_data_stream: + name: simple-data-stream1 + - is_true: acknowledged diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.shrink/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.shrink/10_basic.yml index 41c851b71cc..47cb2a079c0 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.shrink/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.shrink/10_basic.yml @@ -81,3 +81,46 @@ - match: { _type: _doc } - match: { _id: "1" } - match: { _source: { foo: "hello world" } } + +--- +"Prohibit shrink on data stream's write index": + - skip: + version: " - 7.99.99" + reason: needs 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 + + - do: + catch: bad_request + indices.shrink: + index: ".ds-simple-data-stream1-000001" + target: "target" + wait_for_active_shards: 1 + master_timeout: 10s + body: + settings: + index.number_of_replicas: 0 + + - do: + indices.delete_data_stream: + name: simple-data-stream1 + - is_true: acknowledged diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.split/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.split/10_basic.yml index 2baa82ea788..21f4a9b6e14 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.split/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.split/10_basic.yml @@ -221,3 +221,47 @@ setup: settings: index.number_of_replicas: 0 index.number_of_shards: 6 + +--- +"Prohibit split on data stream's write index": + - skip: + version: " - 7.99.99" + reason: needs 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 + + - do: + catch: bad_request + indices.split: + index: ".ds-simple-data-stream1-000001" + target: "target" + wait_for_active_shards: 1 + master_timeout: 10s + body: + settings: + index.number_of_replicas: 0 + index.number_of_shards: 4 + + - do: + indices.delete_data_stream: + name: simple-data-stream1 + - is_true: acknowledged diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java index f1585ef59bf..e362403ca2a 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java @@ -1131,6 +1131,15 @@ public class MetadataCreateIndexService { if (sourceMetadata == null) { throw new IndexNotFoundException(sourceIndex); } + + IndexAbstraction source = state.metadata().getIndicesLookup().get(sourceIndex); + assert source != null; + if (source.getParentDataStream() != null && + source.getParentDataStream().getWriteIndex().getIndex().equals(sourceMetadata.getIndex())) { + throw new IllegalArgumentException(String.format(Locale.ROOT, "cannot resize the write index [%s] for data stream [%s]", + sourceIndex, source.getParentDataStream().getName())); + } + // ensure index is read-only if (state.blocks().indexBlocked(ClusterBlockLevel.WRITE, sourceIndex) == false) { throw new IllegalStateException("index " + sourceIndex + " must be read-only to resize index. use \"index.blocks.write=true\"");