70
70
@ ESIntegTestCase .ClusterScope (transportClientRatio = 0 )
71
71
public class DataStreamsSnapshotsIT extends AbstractSnapshotIntegTestCase {
72
72
73
- private static final String DS_BACKING_INDEX_NAME = DataStream .getDefaultBackingIndexName ("ds" , 1 );
74
- private static final String DS2_BACKING_INDEX_NAME = DataStream .getDefaultBackingIndexName ("ds2" , 1 );
75
73
private static final Map <String , Integer > DOCUMENT_SOURCE = Collections .singletonMap ("@timestamp" , 123 );
76
74
public static final String REPO = "repo" ;
77
75
public static final String SNAPSHOT = "snap" ;
78
76
private Client client ;
79
77
78
+ private String dsBackingIndexName ;
79
+ private String ds2BackingIndexName ;
80
80
private String id ;
81
81
82
82
@ Override
@@ -100,6 +100,14 @@ public void setup() throws Exception {
100
100
response = client .execute (CreateDataStreamAction .INSTANCE , request ).get ();
101
101
assertTrue (response .isAcknowledged ());
102
102
103
+ // Resolve backing index names after data streams have been created:
104
+ // (these names have a date component, and running around midnight could lead to test failures otherwise)
105
+ GetDataStreamAction .Request getDataStreamRequest = new GetDataStreamAction .Request (new String [] { "*" });
106
+ GetDataStreamAction .Response getDataStreamResponse = client .execute (GetDataStreamAction .INSTANCE , getDataStreamRequest ).actionGet ();
107
+ dsBackingIndexName = getDataStreamResponse .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ();
108
+ // Will be used in some tests, to test renaming while restoring a snapshot:
109
+ ds2BackingIndexName = dsBackingIndexName .replace ("-ds-" , "-ds2-" );
110
+
103
111
IndexResponse indexResponse = client .prepareIndex ("ds" , "_doc" )
104
112
.setOpType (DocWriteRequest .OpType .CREATE )
105
113
.setSource (DOCUMENT_SOURCE )
@@ -134,7 +142,7 @@ public void testSnapshotAndRestore() throws Exception {
134
142
RestStatus status = createSnapshotResponse .getSnapshotInfo ().status ();
135
143
assertEquals (RestStatus .OK , status );
136
144
137
- assertEquals (Collections .singletonList (DS_BACKING_INDEX_NAME ), getSnapshot (REPO , SNAPSHOT ).indices ());
145
+ assertEquals (Collections .singletonList (dsBackingIndexName ), getSnapshot (REPO , SNAPSHOT ).indices ());
138
146
139
147
assertTrue (
140
148
client .execute (DeleteDataStreamAction .INSTANCE , new DeleteDataStreamAction .Request (new String [] { "ds" }))
@@ -151,7 +159,7 @@ public void testSnapshotAndRestore() throws Exception {
151
159
152
160
assertEquals (1 , restoreSnapshotResponse .getRestoreInfo ().successfulShards ());
153
161
154
- assertEquals (DOCUMENT_SOURCE , client .prepareGet (DS_BACKING_INDEX_NAME , "_doc" , id ).get ().getSourceAsMap ());
162
+ assertEquals (DOCUMENT_SOURCE , client .prepareGet (dsBackingIndexName , "_doc" , id ).get ().getSourceAsMap ());
155
163
SearchHit [] hits = client .prepareSearch ("ds" ).get ().getHits ().getHits ();
156
164
assertEquals (1 , hits .length );
157
165
assertEquals (DOCUMENT_SOURCE , hits [0 ].getSourceAsMap ());
@@ -162,7 +170,7 @@ public void testSnapshotAndRestore() throws Exception {
162
170
).get ();
163
171
assertEquals (1 , ds .getDataStreams ().size ());
164
172
assertEquals (1 , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().size ());
165
- assertEquals (DS_BACKING_INDEX_NAME , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ());
173
+ assertEquals (dsBackingIndexName , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ());
166
174
167
175
GetAliasesResponse getAliasesResponse = client .admin ().indices ().getAliases (new GetAliasesRequest ("my-alias" )).actionGet ();
168
176
assertThat (getAliasesResponse .getDataStreamAliases ().keySet (), containsInAnyOrder ("ds" , "other-ds" ));
@@ -184,7 +192,7 @@ public void testSnapshotAndRestoreAllDataStreamsInPlace() throws Exception {
184
192
RestStatus status = createSnapshotResponse .getSnapshotInfo ().status ();
185
193
assertEquals (RestStatus .OK , status );
186
194
187
- assertEquals (Collections .singletonList (DS_BACKING_INDEX_NAME ), getSnapshot (REPO , SNAPSHOT ).indices ());
195
+ assertEquals (Collections .singletonList (dsBackingIndexName ), getSnapshot (REPO , SNAPSHOT ).indices ());
188
196
189
197
// Close all indices:
190
198
CloseIndexRequest closeIndexRequest = new CloseIndexRequest ("*" );
@@ -199,7 +207,7 @@ public void testSnapshotAndRestoreAllDataStreamsInPlace() throws Exception {
199
207
.get ();
200
208
assertEquals (1 , restoreSnapshotResponse .getRestoreInfo ().successfulShards ());
201
209
202
- assertEquals (DOCUMENT_SOURCE , client .prepareGet (DS_BACKING_INDEX_NAME , "_doc" , id ).get ().getSourceAsMap ());
210
+ assertEquals (DOCUMENT_SOURCE , client .prepareGet (dsBackingIndexName , "_doc" , id ).get ().getSourceAsMap ());
203
211
SearchHit [] hits = client .prepareSearch ("ds" ).get ().getHits ().getHits ();
204
212
assertEquals (1 , hits .length );
205
213
assertEquals (DOCUMENT_SOURCE , hits [0 ].getSourceAsMap ());
@@ -211,7 +219,7 @@ public void testSnapshotAndRestoreAllDataStreamsInPlace() throws Exception {
211
219
contains (equalTo ("ds" ), equalTo ("other-ds" ))
212
220
);
213
221
java .util .List <Index > backingIndices = ds .getDataStreams ().get (0 ).getDataStream ().getIndices ();
214
- assertThat (backingIndices .stream ().map (Index ::getName ).collect (Collectors .toList ()), contains (DS_BACKING_INDEX_NAME ));
222
+ assertThat (backingIndices .stream ().map (Index ::getName ).collect (Collectors .toList ()), contains (dsBackingIndexName ));
215
223
backingIndices = ds .getDataStreams ().get (1 ).getDataStream ().getIndices ();
216
224
String expectedBackingIndexName = DataStream .getDefaultBackingIndexName ("other-ds" , 1 );
217
225
assertThat (backingIndices .stream ().map (Index ::getName ).collect (Collectors .toList ()), contains (expectedBackingIndexName ));
@@ -229,7 +237,7 @@ public void testSnapshotAndRestoreInPlace() throws Exception {
229
237
RestStatus status = createSnapshotResponse .getSnapshotInfo ().status ();
230
238
assertEquals (RestStatus .OK , status );
231
239
232
- assertEquals (Collections .singletonList (DS_BACKING_INDEX_NAME ), getSnapshot (REPO , SNAPSHOT ).indices ());
240
+ assertEquals (Collections .singletonList (dsBackingIndexName ), getSnapshot (REPO , SNAPSHOT ).indices ());
233
241
234
242
// A rollover after taking snapshot. The new backing index should be a standalone index after restoring
235
243
// and not part of the data stream:
@@ -251,7 +259,7 @@ public void testSnapshotAndRestoreInPlace() throws Exception {
251
259
.get ();
252
260
assertEquals (1 , restoreSnapshotResponse .getRestoreInfo ().successfulShards ());
253
261
254
- assertEquals (DOCUMENT_SOURCE , client .prepareGet (DS_BACKING_INDEX_NAME , "_doc" , id ).get ().getSourceAsMap ());
262
+ assertEquals (DOCUMENT_SOURCE , client .prepareGet (dsBackingIndexName , "_doc" , id ).get ().getSourceAsMap ());
255
263
SearchHit [] hits = client .prepareSearch ("ds" ).get ().getHits ().getHits ();
256
264
assertEquals (1 , hits .length );
257
265
assertEquals (DOCUMENT_SOURCE , hits [0 ].getSourceAsMap ());
@@ -264,7 +272,7 @@ public void testSnapshotAndRestoreInPlace() throws Exception {
264
272
);
265
273
java .util .List <Index > backingIndices = ds .getDataStreams ().get (0 ).getDataStream ().getIndices ();
266
274
assertThat (ds .getDataStreams ().get (0 ).getDataStream ().getIndices (), hasSize (1 ));
267
- assertThat (backingIndices .stream ().map (Index ::getName ).collect (Collectors .toList ()), contains (equalTo (DS_BACKING_INDEX_NAME )));
275
+ assertThat (backingIndices .stream ().map (Index ::getName ).collect (Collectors .toList ()), contains (equalTo (dsBackingIndexName )));
268
276
269
277
// The backing index created as part of rollover should still exist (but just not part of the data stream)
270
278
assertThat (indexExists (DataStream .getDefaultBackingIndexName ("ds" , 2 )), is (true ));
@@ -287,7 +295,7 @@ public void testSnapshotAndRestoreAll() throws Exception {
287
295
RestStatus status = createSnapshotResponse .getSnapshotInfo ().status ();
288
296
assertEquals (RestStatus .OK , status );
289
297
290
- assertEquals (Collections .singletonList (DS_BACKING_INDEX_NAME ), getSnapshot (REPO , SNAPSHOT ).indices ());
298
+ assertEquals (Collections .singletonList (dsBackingIndexName ), getSnapshot (REPO , SNAPSHOT ).indices ());
291
299
292
300
assertAcked (client .execute (DeleteDataStreamAction .INSTANCE , new DeleteDataStreamAction .Request (new String [] { "*" })).get ());
293
301
assertAcked (client .admin ().indices ().prepareDelete ("*" ).setIndicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN_CLOSED_HIDDEN ));
@@ -301,7 +309,7 @@ public void testSnapshotAndRestoreAll() throws Exception {
301
309
302
310
assertEquals (1 , restoreSnapshotResponse .getRestoreInfo ().successfulShards ());
303
311
304
- assertEquals (DOCUMENT_SOURCE , client .prepareGet (DS_BACKING_INDEX_NAME , "_doc" , id ).get ().getSourceAsMap ());
312
+ assertEquals (DOCUMENT_SOURCE , client .prepareGet (dsBackingIndexName , "_doc" , id ).get ().getSourceAsMap ());
305
313
SearchHit [] hits = client .prepareSearch ("ds" ).get ().getHits ().getHits ();
306
314
assertEquals (1 , hits .length );
307
315
assertEquals (DOCUMENT_SOURCE , hits [0 ].getSourceAsMap ());
@@ -312,7 +320,7 @@ public void testSnapshotAndRestoreAll() throws Exception {
312
320
).get ();
313
321
assertEquals (1 , ds .getDataStreams ().size ());
314
322
assertEquals (1 , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().size ());
315
- assertEquals (DS_BACKING_INDEX_NAME , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ());
323
+ assertEquals (dsBackingIndexName , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ());
316
324
317
325
GetAliasesResponse getAliasesResponse = client .admin ().indices ().getAliases (new GetAliasesRequest ("my-alias" )).actionGet ();
318
326
assertThat (getAliasesResponse .getDataStreamAliases ().keySet (), containsInAnyOrder ("ds" ));
@@ -353,9 +361,9 @@ public void testRename() throws Exception {
353
361
).get ();
354
362
assertEquals (1 , ds .getDataStreams ().size ());
355
363
assertEquals (1 , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().size ());
356
- assertEquals (DS2_BACKING_INDEX_NAME , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ());
364
+ assertEquals (ds2BackingIndexName , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ());
357
365
assertEquals (DOCUMENT_SOURCE , client .prepareSearch ("ds2" ).get ().getHits ().getHits ()[0 ].getSourceAsMap ());
358
- assertEquals (DOCUMENT_SOURCE , client .prepareGet (DS2_BACKING_INDEX_NAME , "_doc" , id ).get ().getSourceAsMap ());
366
+ assertEquals (DOCUMENT_SOURCE , client .prepareGet (ds2BackingIndexName , "_doc" , id ).get ().getSourceAsMap ());
359
367
360
368
GetAliasesResponse getAliasesResponse = client .admin ().indices ().getAliases (new GetAliasesRequest ("my-alias" )).actionGet ();
361
369
assertThat (getAliasesResponse .getDataStreamAliases ().keySet (), containsInAnyOrder ("ds" , "ds2" , "other-ds" ));
@@ -393,15 +401,15 @@ public void testBackingIndexIsNotRenamedWhenRestoringDataStream() {
393
401
.prepareRestoreSnapshot (REPO , SNAPSHOT )
394
402
.setWaitForCompletion (true )
395
403
.setIndices ("ds" )
396
- .setRenamePattern (DS_BACKING_INDEX_NAME )
404
+ .setRenamePattern (dsBackingIndexName )
397
405
.setRenameReplacement ("new_index_name" )
398
406
.get ();
399
407
400
408
assertThat (restoreSnapshotResponse .status (), is (RestStatus .OK ));
401
409
402
410
GetDataStreamAction .Request getDSRequest = new GetDataStreamAction .Request (new String [] { "ds" });
403
411
GetDataStreamAction .Response response = client .execute (GetDataStreamAction .INSTANCE , getDSRequest ).actionGet ();
404
- assertThat (response .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName (), is (DS_BACKING_INDEX_NAME ));
412
+ assertThat (response .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName (), is (dsBackingIndexName ));
405
413
}
406
414
407
415
public void testDataStreamAndBackingIndicesAreRenamedUsingRegex () {
@@ -444,7 +452,7 @@ public void testDataStreamAndBackingIndicesAreRenamedUsingRegex() {
444
452
// data stream "ds" should still exist in the system
445
453
GetDataStreamAction .Request getDSRequest = new GetDataStreamAction .Request (new String [] { "ds" });
446
454
response = client .execute (GetDataStreamAction .INSTANCE , getDSRequest ).actionGet ();
447
- assertThat (response .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName (), is (DS_BACKING_INDEX_NAME ));
455
+ assertThat (response .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName (), is (dsBackingIndexName ));
448
456
}
449
457
450
458
public void testWildcards () throws Exception {
@@ -476,7 +484,7 @@ public void testWildcards() throws Exception {
476
484
).get ();
477
485
assertEquals (1 , ds .getDataStreams ().size ());
478
486
assertEquals (1 , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().size ());
479
- assertEquals (DS2_BACKING_INDEX_NAME , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ());
487
+ assertEquals (ds2BackingIndexName , ds .getDataStreams ().get (0 ).getDataStream ().getIndices ().get (0 ).getName ());
480
488
assertThat (
481
489
"we renamed the restored data stream to one that doesn't match any existing composable template" ,
482
490
ds .getDataStreams ().get (0 ).getIndexTemplate (),
@@ -489,7 +497,7 @@ public void testDataStreamNotStoredWhenIndexRequested() {
489
497
.cluster ()
490
498
.prepareCreateSnapshot (REPO , "snap2" )
491
499
.setWaitForCompletion (true )
492
- .setIndices (DS_BACKING_INDEX_NAME )
500
+ .setIndices (dsBackingIndexName )
493
501
.setIncludeGlobalState (false )
494
502
.get ();
495
503
0 commit comments