Skip to content

Commit 911d463

Browse files
authored
Prohibit clone, shrink, and split on a data stream's write index
1 parent 03ce0f8 commit 911d463

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

rest-api-spec/src/main/resources/rest-api-spec/test/indices.clone/10_basic.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,47 @@ setup:
109109
settings:
110110
index.number_of_replicas: 0
111111
index.number_of_shards: 6
112+
113+
---
114+
"Prohibit clone on data stream's write index":
115+
- skip:
116+
version: " - 7.99.99"
117+
reason: needs backport
118+
features: allowed_warnings
119+
120+
- do:
121+
allowed_warnings:
122+
- "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"
123+
indices.put_index_template:
124+
name: my-template1
125+
body:
126+
index_patterns: [simple-data-stream1]
127+
template:
128+
mappings:
129+
properties:
130+
'@timestamp':
131+
type: date
132+
data_stream:
133+
timestamp_field: '@timestamp'
134+
135+
- do:
136+
indices.create_data_stream:
137+
name: simple-data-stream1
138+
- is_true: acknowledged
139+
140+
- do:
141+
catch: bad_request
142+
indices.clone:
143+
index: ".ds-simple-data-stream1-000001"
144+
target: "target"
145+
wait_for_active_shards: 1
146+
master_timeout: 10s
147+
body:
148+
settings:
149+
index.number_of_replicas: 0
150+
index.number_of_shards: 2
151+
152+
- do:
153+
indices.delete_data_stream:
154+
name: simple-data-stream1
155+
- is_true: acknowledged

rest-api-spec/src/main/resources/rest-api-spec/test/indices.shrink/10_basic.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,46 @@
8181
- match: { _type: _doc }
8282
- match: { _id: "1" }
8383
- match: { _source: { foo: "hello world" } }
84+
85+
---
86+
"Prohibit shrink on data stream's write index":
87+
- skip:
88+
version: " - 7.99.99"
89+
reason: needs backport
90+
features: allowed_warnings
91+
92+
- do:
93+
allowed_warnings:
94+
- "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"
95+
indices.put_index_template:
96+
name: my-template1
97+
body:
98+
index_patterns: [simple-data-stream1]
99+
template:
100+
mappings:
101+
properties:
102+
'@timestamp':
103+
type: date
104+
data_stream:
105+
timestamp_field: '@timestamp'
106+
107+
- do:
108+
indices.create_data_stream:
109+
name: simple-data-stream1
110+
- is_true: acknowledged
111+
112+
- do:
113+
catch: bad_request
114+
indices.shrink:
115+
index: ".ds-simple-data-stream1-000001"
116+
target: "target"
117+
wait_for_active_shards: 1
118+
master_timeout: 10s
119+
body:
120+
settings:
121+
index.number_of_replicas: 0
122+
123+
- do:
124+
indices.delete_data_stream:
125+
name: simple-data-stream1
126+
- is_true: acknowledged

rest-api-spec/src/main/resources/rest-api-spec/test/indices.split/10_basic.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,47 @@ setup:
221221
settings:
222222
index.number_of_replicas: 0
223223
index.number_of_shards: 6
224+
225+
---
226+
"Prohibit split on data stream's write index":
227+
- skip:
228+
version: " - 7.99.99"
229+
reason: needs backport
230+
features: allowed_warnings
231+
232+
- do:
233+
allowed_warnings:
234+
- "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"
235+
indices.put_index_template:
236+
name: my-template1
237+
body:
238+
index_patterns: [simple-data-stream1]
239+
template:
240+
mappings:
241+
properties:
242+
'@timestamp':
243+
type: date
244+
data_stream:
245+
timestamp_field: '@timestamp'
246+
247+
- do:
248+
indices.create_data_stream:
249+
name: simple-data-stream1
250+
- is_true: acknowledged
251+
252+
- do:
253+
catch: bad_request
254+
indices.split:
255+
index: ".ds-simple-data-stream1-000001"
256+
target: "target"
257+
wait_for_active_shards: 1
258+
master_timeout: 10s
259+
body:
260+
settings:
261+
index.number_of_replicas: 0
262+
index.number_of_shards: 4
263+
264+
- do:
265+
indices.delete_data_stream:
266+
name: simple-data-stream1
267+
- is_true: acknowledged

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,15 @@ static IndexMetadata validateResize(ClusterState state, String sourceIndex,
11311131
if (sourceMetadata == null) {
11321132
throw new IndexNotFoundException(sourceIndex);
11331133
}
1134+
1135+
IndexAbstraction source = state.metadata().getIndicesLookup().get(sourceIndex);
1136+
assert source != null;
1137+
if (source.getParentDataStream() != null &&
1138+
source.getParentDataStream().getWriteIndex().getIndex().equals(sourceMetadata.getIndex())) {
1139+
throw new IllegalArgumentException(String.format(Locale.ROOT, "cannot resize the write index [%s] for data stream [%s]",
1140+
sourceIndex, source.getParentDataStream().getName()));
1141+
}
1142+
11341143
// ensure index is read-only
11351144
if (state.blocks().indexBlocked(ClusterBlockLevel.WRITE, sourceIndex) == false) {
11361145
throw new IllegalStateException("index " + sourceIndex + " must be read-only to resize index. use \"index.blocks.write=true\"");

0 commit comments

Comments
 (0)