@@ -769,20 +769,6 @@ public void testRemoveAndReaddPolicy() throws Exception {
769
769
client ().performRequest (addPolicyRequest );
770
770
assertBusy (() -> assertTrue ((boolean ) explainIndex (originalIndex ).getOrDefault ("managed" , false )));
771
771
772
- // Wait for rollover to error
773
- assertBusy (() -> assertThat (getStepKeyForIndex (originalIndex ), equalTo (new StepKey ("hot" , RolloverAction .NAME , ErrorStep .NAME ))));
774
-
775
- // Set indexing complete
776
- Request setIndexingCompleteRequest = new Request ("PUT" , "/" + originalIndex + "/_settings" );
777
- setIndexingCompleteRequest .setJsonEntity ("{\n " +
778
- " \" index.lifecycle.indexing_complete\" : true\n " +
779
- "}" );
780
- client ().performRequest (setIndexingCompleteRequest );
781
-
782
- // Retry policy
783
- Request retryRequest = new Request ("POST" , "/" + originalIndex + "/_ilm/retry" );
784
- client ().performRequest (retryRequest );
785
-
786
772
// Wait for everything to be copacetic
787
773
assertBusy (() -> assertThat (getStepKeyForIndex (originalIndex ), equalTo (TerminalPolicyStep .KEY )));
788
774
}
@@ -884,6 +870,79 @@ public void testExplainFilters() throws Exception {
884
870
});
885
871
}
886
872
873
+ public void testILMRolloverOnManuallyRolledIndex () throws Exception {
874
+ String originalIndex = index + "-000001" ;
875
+ String secondIndex = index + "-000002" ;
876
+ String thirdIndex = index + "-000003" ;
877
+
878
+ // Configure ILM to run every second
879
+ Request updateLifecylePollSetting = new Request ("PUT" , "_cluster/settings" );
880
+ updateLifecylePollSetting .setJsonEntity ("{" +
881
+ " \" transient\" : {\n " +
882
+ "\" indices.lifecycle.poll_interval\" : \" 1s\" \n " +
883
+ " }\n " +
884
+ "}" );
885
+ client ().performRequest (updateLifecylePollSetting );
886
+
887
+ // Set up a policy with rollover
888
+ createNewSingletonPolicy ("hot" , new RolloverAction (null , null , 2L ));
889
+ Request createIndexTemplate = new Request ("PUT" , "_template/rolling_indexes" );
890
+ createIndexTemplate .setJsonEntity ("{" +
891
+ "\" index_patterns\" : [\" " + index + "-*\" ], \n " +
892
+ " \" settings\" : {\n " +
893
+ " \" number_of_shards\" : 1,\n " +
894
+ " \" number_of_replicas\" : 0,\n " +
895
+ " \" index.lifecycle.name\" : \" " + policy + "\" , \n " +
896
+ " \" index.lifecycle.rollover_alias\" : \" alias\" \n " +
897
+ " }\n " +
898
+ "}" );
899
+ client ().performRequest (createIndexTemplate );
900
+
901
+ createIndexWithSettings (
902
+ originalIndex ,
903
+ Settings .builder ().put (IndexMetaData .SETTING_NUMBER_OF_SHARDS , 1 )
904
+ .put (IndexMetaData .SETTING_NUMBER_OF_REPLICAS , 0 ),
905
+ true
906
+ );
907
+
908
+ // Index a document
909
+ index (client (), originalIndex , "1" , "foo" , "bar" );
910
+ Request refreshOriginalIndex = new Request ("POST" , "/" + originalIndex + "/_refresh" );
911
+ client ().performRequest (refreshOriginalIndex );
912
+
913
+ // Manual rollover
914
+ Request rolloverRequest = new Request ("POST" , "/alias/_rollover" );
915
+ rolloverRequest .setJsonEntity ("{\n " +
916
+ " \" conditions\" : {\n " +
917
+ " \" max_docs\" : \" 1\" \n " +
918
+ " }\n " +
919
+ "}"
920
+ );
921
+ client ().performRequest (rolloverRequest );
922
+ assertBusy (() -> assertTrue (indexExists (secondIndex )));
923
+
924
+ // Index another document into the original index so the ILM rollover policy condition is met
925
+ index (client (), originalIndex , "2" , "foo" , "bar" );
926
+ client ().performRequest (refreshOriginalIndex );
927
+
928
+ // Wait for the rollover policy to execute
929
+ assertBusy (() -> assertThat (getStepKeyForIndex (originalIndex ), equalTo (TerminalPolicyStep .KEY )));
930
+
931
+ // ILM should manage the second index after attempting (and skipping) rolling the original index
932
+ assertBusy (() -> assertTrue ((boolean ) explainIndex (secondIndex ).getOrDefault ("managed" , true )));
933
+
934
+ // index some documents to trigger an ILM rollover
935
+ index (client (), "alias" , "1" , "foo" , "bar" );
936
+ index (client (), "alias" , "2" , "foo" , "bar" );
937
+ index (client (), "alias" , "3" , "foo" , "bar" );
938
+ Request refreshSecondIndex = new Request ("POST" , "/" + secondIndex + "/_refresh" );
939
+ client ().performRequest (refreshSecondIndex ).getStatusLine ();
940
+
941
+ // ILM should rollover the second index even though it skipped the first one
942
+ assertBusy (() -> assertThat (getStepKeyForIndex (secondIndex ), equalTo (TerminalPolicyStep .KEY )));
943
+ assertBusy (() -> assertTrue (indexExists (thirdIndex )));
944
+ }
945
+
887
946
private void createFullPolicy (TimeValue hotTime ) throws IOException {
888
947
Map <String , LifecycleAction > hotActions = new HashMap <>();
889
948
hotActions .put (SetPriorityAction .NAME , new SetPriorityAction (100 ));
0 commit comments