9
9
10
10
import org .apache .http .entity .ContentType ;
11
11
import org .apache .http .entity .StringEntity ;
12
+ import org .elasticsearch .action .admin .indices .rollover .RolloverConditions ;
12
13
import org .elasticsearch .client .Request ;
13
14
import org .elasticsearch .client .Response ;
14
15
import org .elasticsearch .client .ResponseException ;
@@ -295,7 +296,10 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws
295
296
TimeValue .ZERO ,
296
297
Map .of (
297
298
RolloverAction .NAME ,
298
- new RolloverAction (null , null , null , 1L , null , null , null , null , null , null ),
299
+ // We create the policy with maxDocs 2 since we're required to have a rollover action if we're creating a searchable
300
+ // snapshot in the hot phase. But we will only index one document and trigger the rollover manually,
301
+ // to improve reliability and speed of the test.
302
+ new RolloverAction (RolloverConditions .newBuilder ().addMaxIndexDocsCondition (2L ).build ()),
299
303
SearchableSnapshotAction .NAME ,
300
304
new SearchableSnapshotAction (snapshotRepo )
301
305
)
@@ -319,8 +323,11 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws
319
323
320
324
// rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
321
325
indexDocument (client (), dataStream , true );
326
+ rolloverMaxOneDocCondition (client (), dataStream );
327
+ List <String > backingIndices = getDataStreamBackingIndexNames (dataStream );
328
+ assertThat (backingIndices .size (), equalTo (2 ));
322
329
323
- String backingIndexName = getDataStreamBackingIndexNames ( dataStream ) .getFirst ();
330
+ String backingIndexName = backingIndices .getFirst ();
324
331
String restoredIndexName = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + backingIndexName ;
325
332
awaitIndexExists (restoredIndexName );
326
333
TimeSeriesRestDriver .awaitStepKey (client (), restoredIndexName , "hot" , null , PhaseCompleteStep .NAME );
@@ -357,7 +364,10 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
357
364
TimeValue .ZERO ,
358
365
Map .of (
359
366
RolloverAction .NAME ,
360
- new RolloverAction (null , null , null , 1L , null , null , null , null , null , null ),
367
+ // We create the policy with maxDocs 2 since we're required to have a rollover action if we're creating a searchable
368
+ // snapshot in the hot phase. But we will only index one document and trigger the rollover manually,
369
+ // to improve reliability and speed of the test.
370
+ new RolloverAction (RolloverConditions .newBuilder ().addMaxIndexDocsCondition (2L ).build ()),
361
371
SearchableSnapshotAction .NAME ,
362
372
new SearchableSnapshotAction (snapshotRepo )
363
373
)
@@ -383,8 +393,11 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
383
393
// rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
384
394
// indexing only one document as we want only one rollover to be triggered
385
395
indexDocument (client (), dataStream , true );
396
+ rolloverMaxOneDocCondition (client (), dataStream );
397
+ List <String > backingIndices = getDataStreamBackingIndexNames (dataStream );
398
+ assertThat (backingIndices .size (), equalTo (2 ));
386
399
387
- String backingIndexName = getDataStreamBackingIndexNames ( dataStream ) .getFirst ();
400
+ String backingIndexName = backingIndices .getFirst ();
388
401
String searchableSnapMountedIndexName = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + backingIndexName ;
389
402
awaitIndexExists (searchableSnapMountedIndexName );
390
403
TimeSeriesRestDriver .awaitStepKey (client (), searchableSnapMountedIndexName , "hot" , null , PhaseCompleteStep .NAME );
@@ -453,15 +466,24 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
453
466
public void testIdenticalSearchableSnapshotActionIsNoop () throws Exception {
454
467
String index = "myindex-" + randomAlphaOfLength (4 ).toLowerCase (Locale .ROOT ) + "-000001" ;
455
468
createSnapshotRepo (client (), snapshotRepo , randomBoolean ());
456
- Map <String , LifecycleAction > hotActions = new HashMap <>();
457
- hotActions .put (RolloverAction .NAME , new RolloverAction (null , null , null , 1L , null , null , null , null , null , null ));
458
- hotActions .put (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (snapshotRepo , randomBoolean ()));
459
469
createPolicy (
460
470
client (),
461
471
policy ,
462
472
null ,
463
473
null ,
464
- new Phase ("hot" , TimeValue .ZERO , hotActions ),
474
+ new Phase (
475
+ "hot" ,
476
+ TimeValue .ZERO ,
477
+ Map .of (
478
+ RolloverAction .NAME ,
479
+ // We create the policy with maxDocs 2 since we're required to have a rollover action if we're creating a searchable
480
+ // snapshot in the hot phase. But we will only index one document and trigger the rollover manually,
481
+ // to improve reliability and speed of the test.
482
+ new RolloverAction (RolloverConditions .newBuilder ().addMaxIndexDocsCondition (2L ).build ()),
483
+ SearchableSnapshotAction .NAME ,
484
+ new SearchableSnapshotAction (snapshotRepo , randomBoolean ())
485
+ )
486
+ ),
465
487
new Phase (
466
488
"cold" ,
467
489
TimeValue .ZERO ,
@@ -472,16 +494,13 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
472
494
473
495
createIndex (
474
496
index ,
475
- Settings .builder ().put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , "alias" ).build (),
497
+ Settings .builder ().put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , "alias" ).put ( LifecycleSettings . LIFECYCLE_NAME , policy ). build (),
476
498
null ,
477
499
"\" alias\" : {\" is_write_index\" : true}"
478
500
);
479
501
ensureGreen (index );
480
502
indexDocument (client (), index , true );
481
-
482
- // enable ILM after we indexed a document as otherwise ILM might sometimes run so fast the indexDocument call will fail with
483
- // `index_not_found_exception`
484
- updateIndexSettings (index , Settings .builder ().put (LifecycleSettings .LIFECYCLE_NAME , policy ));
503
+ rolloverMaxOneDocCondition (client (), "alias" );
485
504
486
505
final String searchableSnapMountedIndexName = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + index ;
487
506
@@ -772,7 +791,10 @@ public void testSearchableSnapshotsInHotPhasePinnedToHotNodes() throws Exception
772
791
TimeValue .ZERO ,
773
792
Map .of (
774
793
RolloverAction .NAME ,
775
- new RolloverAction (null , null , null , 1L , null , null , null , null , null , null ),
794
+ // We create the policy with maxDocs 2 since we're required to have a rollover action if we're creating a searchable
795
+ // snapshot in the hot phase. But we will only index one document and trigger the rollover manually,
796
+ // to improve reliability and speed of the test.
797
+ new RolloverAction (RolloverConditions .newBuilder ().addMaxIndexDocsCondition (2L ).build ()),
776
798
SearchableSnapshotAction .NAME ,
777
799
new SearchableSnapshotAction (snapshotRepo , randomBoolean ())
778
800
)
@@ -804,6 +826,7 @@ public void testSearchableSnapshotsInHotPhasePinnedToHotNodes() throws Exception
804
826
805
827
// rollover the data stream so searchable_snapshot can complete
806
828
indexDocument (client (), dataStream , true );
829
+ rolloverMaxOneDocCondition (client (), dataStream );
807
830
808
831
final String restoredIndex = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + firstGenIndex ;
809
832
logger .info ("--> waiting for [{}] to exist..." , restoredIndex );
0 commit comments