99
1010import org .apache .http .entity .ContentType ;
1111import org .apache .http .entity .StringEntity ;
12+ import org .elasticsearch .action .admin .indices .rollover .RolloverConditions ;
1213import org .elasticsearch .client .Request ;
1314import org .elasticsearch .client .Response ;
1415import org .elasticsearch .client .ResponseException ;
@@ -295,7 +296,10 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws
295296 TimeValue .ZERO ,
296297 Map .of (
297298 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 ()),
299303 SearchableSnapshotAction .NAME ,
300304 new SearchableSnapshotAction (snapshotRepo )
301305 )
@@ -319,8 +323,11 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws
319323
320324 // rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
321325 indexDocument (client (), dataStream , true );
326+ rolloverMaxOneDocCondition (client (), dataStream );
327+ List <String > backingIndices = getDataStreamBackingIndexNames (dataStream );
328+ assertThat (backingIndices .size (), equalTo (2 ));
322329
323- String backingIndexName = getDataStreamBackingIndexNames ( dataStream ) .getFirst ();
330+ String backingIndexName = backingIndices .getFirst ();
324331 String restoredIndexName = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + backingIndexName ;
325332 awaitIndexExists (restoredIndexName );
326333 TimeSeriesRestDriver .awaitStepKey (client (), restoredIndexName , "hot" , null , PhaseCompleteStep .NAME );
@@ -357,7 +364,10 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
357364 TimeValue .ZERO ,
358365 Map .of (
359366 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 ()),
361371 SearchableSnapshotAction .NAME ,
362372 new SearchableSnapshotAction (snapshotRepo )
363373 )
@@ -383,8 +393,11 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
383393 // rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
384394 // indexing only one document as we want only one rollover to be triggered
385395 indexDocument (client (), dataStream , true );
396+ rolloverMaxOneDocCondition (client (), dataStream );
397+ List <String > backingIndices = getDataStreamBackingIndexNames (dataStream );
398+ assertThat (backingIndices .size (), equalTo (2 ));
386399
387- String backingIndexName = getDataStreamBackingIndexNames ( dataStream ) .getFirst ();
400+ String backingIndexName = backingIndices .getFirst ();
388401 String searchableSnapMountedIndexName = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + backingIndexName ;
389402 awaitIndexExists (searchableSnapMountedIndexName );
390403 TimeSeriesRestDriver .awaitStepKey (client (), searchableSnapMountedIndexName , "hot" , null , PhaseCompleteStep .NAME );
@@ -453,15 +466,24 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
453466 public void testIdenticalSearchableSnapshotActionIsNoop () throws Exception {
454467 String index = "myindex-" + randomAlphaOfLength (4 ).toLowerCase (Locale .ROOT ) + "-000001" ;
455468 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 ()));
459469 createPolicy (
460470 client (),
461471 policy ,
462472 null ,
463473 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+ ),
465487 new Phase (
466488 "cold" ,
467489 TimeValue .ZERO ,
@@ -472,16 +494,13 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
472494
473495 createIndex (
474496 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 (),
476498 null ,
477499 "\" alias\" : {\" is_write_index\" : true}"
478500 );
479501 ensureGreen (index );
480502 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" );
485504
486505 final String searchableSnapMountedIndexName = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + index ;
487506
@@ -772,7 +791,10 @@ public void testSearchableSnapshotsInHotPhasePinnedToHotNodes() throws Exception
772791 TimeValue .ZERO ,
773792 Map .of (
774793 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 ()),
776798 SearchableSnapshotAction .NAME ,
777799 new SearchableSnapshotAction (snapshotRepo , randomBoolean ())
778800 )
@@ -804,6 +826,7 @@ public void testSearchableSnapshotsInHotPhasePinnedToHotNodes() throws Exception
804826
805827 // rollover the data stream so searchable_snapshot can complete
806828 indexDocument (client (), dataStream , true );
829+ rolloverMaxOneDocCondition (client (), dataStream );
807830
808831 final String restoredIndex = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + firstGenIndex ;
809832 logger .info ("--> waiting for [{}] to exist..." , restoredIndex );
0 commit comments