Prohibit clone, shrink, and split on a data stream's write index

This commit is contained in:
Dan Hermann 2020-06-16 10:53:20 -05:00 committed by GitHub
parent 03ce0f8a4d
commit 911d46370e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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\"");