20
20
import org .elasticsearch .common .Nullable ;
21
21
import org .elasticsearch .common .Strings ;
22
22
import org .elasticsearch .common .settings .Settings ;
23
- import org .elasticsearch .common .unit .ByteSizeValue ;
24
23
import org .elasticsearch .common .unit .TimeValue ;
25
24
import org .elasticsearch .common .xcontent .XContentBuilder ;
26
25
import org .elasticsearch .common .xcontent .XContentHelper ;
71
70
import static org .elasticsearch .xpack .TimeSeriesRestDriver .getStepKeyForIndex ;
72
71
import static org .elasticsearch .xpack .TimeSeriesRestDriver .index ;
73
72
import static org .elasticsearch .xpack .TimeSeriesRestDriver .indexDocument ;
74
- import static org .elasticsearch .xpack .TimeSeriesRestDriver .rolloverMaxOneDocCondition ;
75
73
import static org .elasticsearch .xpack .TimeSeriesRestDriver .updatePolicy ;
76
74
import static org .hamcrest .Matchers .containsString ;
77
75
import static org .hamcrest .Matchers .equalTo ;
@@ -165,93 +163,6 @@ public void testRetryFreezeDeleteAction() throws Exception {
165
163
assertBusy (() -> assertThat (getOnlyIndexSettings (client (), index ).get ("index.frozen" ), equalTo ("true" )));
166
164
}
167
165
168
- public void testRolloverAction () throws Exception {
169
- String originalIndex = index + "-000001" ;
170
- String secondIndex = index + "-000002" ;
171
- createIndexWithSettings (client (), originalIndex , alias , Settings .builder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
172
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
173
- .put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ));
174
-
175
- // create policy
176
- createNewSingletonPolicy (client (), policy , "hot" , new RolloverAction (null , null , null , 1L ));
177
- // update policy on index
178
- updatePolicy (client (), originalIndex , policy );
179
- // index document {"foo": "bar"} to trigger rollover
180
- index (client (), originalIndex , "_id" , "foo" , "bar" );
181
-
182
- assertBusy (() -> {
183
- assertThat (getStepKeyForIndex (client (), originalIndex ), equalTo (PhaseCompleteStep .finalStep ("hot" ).getKey ()));
184
- assertTrue (indexExists (secondIndex ));
185
- assertTrue (indexExists (originalIndex ));
186
- assertEquals ("true" , getOnlyIndexSettings (client (), originalIndex ).get (LifecycleSettings .LIFECYCLE_INDEXING_COMPLETE ));
187
- }, 30 , TimeUnit .SECONDS );
188
- }
189
-
190
- public void testRolloverActionWithIndexingComplete () throws Exception {
191
- String originalIndex = index + "-000001" ;
192
- String secondIndex = index + "-000002" ;
193
- createIndexWithSettings (client (), originalIndex , alias , Settings .builder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
194
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
195
- .put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ));
196
-
197
- Request updateSettingsRequest = new Request ("PUT" , "/" + originalIndex + "/_settings" );
198
- updateSettingsRequest .setJsonEntity ("{\n " +
199
- " \" settings\" : {\n " +
200
- " \" " + LifecycleSettings .LIFECYCLE_INDEXING_COMPLETE + "\" : true\n " +
201
- " }\n " +
202
- "}" );
203
- client ().performRequest (updateSettingsRequest );
204
- Request updateAliasRequest = new Request ("POST" , "/_aliases" );
205
- updateAliasRequest .setJsonEntity ("{\n " +
206
- " \" actions\" : [\n " +
207
- " {\n " +
208
- " \" add\" : {\n " +
209
- " \" index\" : \" " + originalIndex + "\" ,\n " +
210
- " \" alias\" : \" " + alias + "\" ,\n " +
211
- " \" is_write_index\" : false\n " +
212
- " }\n " +
213
- " }\n " +
214
- " ]\n " +
215
- "}" );
216
- client ().performRequest (updateAliasRequest );
217
-
218
- // create policy
219
- createNewSingletonPolicy (client (), policy , "hot" , new RolloverAction (null , null , null , 1L ));
220
- // update policy on index
221
- updatePolicy (client (), originalIndex , policy );
222
- // index document {"foo": "bar"} to trigger rollover
223
- index (client (), originalIndex , "_id" , "foo" , "bar" );
224
-
225
- assertBusy (() -> {
226
- assertThat (getStepKeyForIndex (client (), originalIndex ), equalTo (PhaseCompleteStep .finalStep ("hot" ).getKey ()));
227
- assertTrue (indexExists (originalIndex ));
228
- assertFalse (indexExists (secondIndex )); // careful, *assertFalse* not *assertTrue*
229
- assertEquals ("true" , getOnlyIndexSettings (client (), originalIndex ).get (LifecycleSettings .LIFECYCLE_INDEXING_COMPLETE ));
230
- }, 30 , TimeUnit .SECONDS );
231
- }
232
-
233
- public void testRolloverActionWithMaxPrimaryShardSize () throws Exception {
234
- String originalIndex = index + "-000001" ;
235
- String secondIndex = index + "-000002" ;
236
- createIndexWithSettings (client (), originalIndex , alias , Settings .builder ()
237
- .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 3 )
238
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
239
- .put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ));
240
-
241
- index (client (), originalIndex , "_id" , "foo" , "bar" );
242
-
243
- // create policy
244
- createNewSingletonPolicy (client (), policy , "hot" , new RolloverAction (null , ByteSizeValue .ofBytes (1 ), null , null ));
245
- // update policy on index
246
- updatePolicy (client (), originalIndex , policy );
247
-
248
- assertBusy (() -> {
249
- assertThat (getStepKeyForIndex (client (), originalIndex ), equalTo (PhaseCompleteStep .finalStep ("hot" ).getKey ()));
250
- assertTrue (indexExists (secondIndex ));
251
- assertTrue (indexExists (originalIndex ));
252
- assertEquals ("true" , getOnlyIndexSettings (client (), originalIndex ).get (LifecycleSettings .LIFECYCLE_INDEXING_COMPLETE ));
253
- }, 30 , TimeUnit .SECONDS );
254
- }
255
166
256
167
@ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/69340" )
257
168
public void testAllocateOnlyAllocation () throws Exception {
@@ -262,9 +173,7 @@ public void testAllocateOnlyAllocation() throws Exception {
262
173
String endPhase = randomFrom ("warm" , "cold" );
263
174
createNewSingletonPolicy (client (), policy , endPhase , allocateAction );
264
175
updatePolicy (client (), index , policy );
265
- assertBusy (() -> {
266
- assertThat (getStepKeyForIndex (client (), index ), equalTo (PhaseCompleteStep .finalStep (endPhase ).getKey ()));
267
- });
176
+ assertBusy (() -> assertThat (getStepKeyForIndex (client (), index ), equalTo (PhaseCompleteStep .finalStep (endPhase ).getKey ())));
268
177
ensureGreen (index );
269
178
}
270
179
@@ -701,228 +610,8 @@ public void testCanStopILMWithPolicyUsingNonexistentPolicy() throws Exception {
701
610
});
702
611
703
612
// Re-start ILM so that subsequent tests don't fail
704
- Request startILMReqest = new Request ("POST" , "_ilm/start" );
705
- assertOK (client ().performRequest (startILMReqest ));
706
- }
707
-
708
- public void testILMRolloverRetriesOnReadOnlyBlock () throws Exception {
709
- String firstIndex = index + "-000001" ;
710
-
711
- createNewSingletonPolicy (client (), policy , "hot" , new RolloverAction (null , null , TimeValue .timeValueSeconds (1 ), null ));
712
-
713
- // create the index as readonly and associate the ILM policy to it
714
- createIndexWithSettings (
715
- client (),
716
- firstIndex ,
717
- alias ,
718
- Settings .builder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
719
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
720
- .put (LifecycleSettings .LIFECYCLE_NAME , policy )
721
- .put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias )
722
- .put ("index.blocks.read_only" , true ),
723
- true
724
- );
725
-
726
- // wait for ILM to start retrying the step
727
- assertBusy (() -> assertThat ((Integer ) explainIndex (client (), firstIndex ).get (FAILED_STEP_RETRY_COUNT_FIELD ),
728
- greaterThanOrEqualTo (1 )));
729
-
730
- // remove the read only block
731
- Request allowWritesOnIndexSettingUpdate = new Request ("PUT" , firstIndex + "/_settings" );
732
- allowWritesOnIndexSettingUpdate .setJsonEntity ("{" +
733
- " \" index\" : {\n " +
734
- " \" blocks.read_only\" : \" false\" \n " +
735
- " }\n " +
736
- "}" );
737
- client ().performRequest (allowWritesOnIndexSettingUpdate );
738
-
739
- // index is not readonly so the ILM should complete successfully
740
- assertBusy (() -> assertThat (getStepKeyForIndex (client (), firstIndex ), equalTo (PhaseCompleteStep .finalStep ("hot" ).getKey ())));
741
- }
742
-
743
- public void testILMRolloverOnManuallyRolledIndex () throws Exception {
744
- String originalIndex = index + "-000001" ;
745
- String secondIndex = index + "-000002" ;
746
- String thirdIndex = index + "-000003" ;
747
-
748
- // Set up a policy with rollover
749
- createNewSingletonPolicy (client (), policy , "hot" , new RolloverAction (null , null , null , 2L ));
750
- Request createIndexTemplate = new Request ("PUT" , "_template/rolling_indexes" );
751
- createIndexTemplate .setJsonEntity ("{" +
752
- "\" index_patterns\" : [\" " + index + "-*\" ], \n " +
753
- " \" settings\" : {\n " +
754
- " \" number_of_shards\" : 1,\n " +
755
- " \" number_of_replicas\" : 0,\n " +
756
- " \" index.lifecycle.name\" : \" " + policy + "\" , \n " +
757
- " \" index.lifecycle.rollover_alias\" : \" " + alias + "\" \n " +
758
- " }\n " +
759
- "}" );
760
- client ().performRequest (createIndexTemplate );
761
-
762
- createIndexWithSettings (
763
- client (),
764
- originalIndex ,
765
- alias ,
766
- Settings .builder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
767
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 ),
768
- true
769
- );
770
-
771
- // Index a document
772
- index (client (), originalIndex , "1" , "foo" , "bar" );
773
- Request refreshOriginalIndex = new Request ("POST" , "/" + originalIndex + "/_refresh" );
774
- client ().performRequest (refreshOriginalIndex );
775
-
776
- // Manual rollover
777
- rolloverMaxOneDocCondition (client (), alias );
778
- assertBusy (() -> assertTrue (indexExists (secondIndex )));
779
-
780
- // Index another document into the original index so the ILM rollover policy condition is met
781
- index (client (), originalIndex , "2" , "foo" , "bar" );
782
- client ().performRequest (refreshOriginalIndex );
783
-
784
- // Wait for the rollover policy to execute
785
- assertBusy (() -> assertThat (getStepKeyForIndex (client (), originalIndex ), equalTo (PhaseCompleteStep .finalStep ("hot" ).getKey ())));
786
-
787
- // ILM should manage the second index after attempting (and skipping) rolling the original index
788
- assertBusy (() -> assertTrue ((boolean ) explainIndex (client (), secondIndex ).getOrDefault ("managed" , true )));
789
-
790
- // index some documents to trigger an ILM rollover
791
- index (client (), alias , "1" , "foo" , "bar" );
792
- index (client (), alias , "2" , "foo" , "bar" );
793
- index (client (), alias , "3" , "foo" , "bar" );
794
- Request refreshSecondIndex = new Request ("POST" , "/" + secondIndex + "/_refresh" );
795
- client ().performRequest (refreshSecondIndex ).getStatusLine ();
796
-
797
- // ILM should rollover the second index even though it skipped the first one
798
- assertBusy (() -> assertThat (getStepKeyForIndex (client (), secondIndex ), equalTo (PhaseCompleteStep .finalStep ("hot" ).getKey ())));
799
- assertBusy (() -> assertTrue (indexExists (thirdIndex )));
800
- }
801
-
802
- public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted () throws Exception {
803
- String index = this .index + "-000001" ;
804
- String rolledIndex = this .index + "-000002" ;
805
-
806
- createNewSingletonPolicy (client (), policy , "hot" , new RolloverAction (null , null , TimeValue .timeValueSeconds (1 ), null ));
807
-
808
- // create the rolled index so the rollover of the first index fails
809
- createIndexWithSettings (
810
- client (),
811
- rolledIndex ,
812
- alias ,
813
- Settings .builder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
814
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
815
- .put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ),
816
- false
817
- );
818
-
819
- createIndexWithSettings (
820
- client (),
821
- index ,
822
- alias ,
823
- Settings .builder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
824
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
825
- .put (LifecycleSettings .LIFECYCLE_NAME , policy )
826
- .put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ),
827
- true
828
- );
829
-
830
- assertBusy (() -> assertThat ((Integer ) explainIndex (client (), index ).get (FAILED_STEP_RETRY_COUNT_FIELD ), greaterThanOrEqualTo (1 )),
831
- 30 ,
832
- TimeUnit .SECONDS );
833
-
834
- Request moveToStepRequest = new Request ("POST" , "_ilm/move/" + index );
835
- moveToStepRequest .setJsonEntity ("{\n " +
836
- " \" current_step\" : {\n " +
837
- " \" phase\" : \" hot\" ,\n " +
838
- " \" action\" : \" rollover\" ,\n " +
839
- " \" name\" : \" check-rollover-ready\" \n " +
840
- " },\n " +
841
- " \" next_step\" : {\n " +
842
- " \" phase\" : \" hot\" ,\n " +
843
- " \" action\" : \" rollover\" ,\n " +
844
- " \" name\" : \" attempt-rollover\" \n " +
845
- " }\n " +
846
- "}" );
847
-
848
- // Using {@link #waitUntil} here as ILM moves back and forth between the {@link WaitForRolloverReadyStep} step and
849
- // {@link org.elasticsearch.xpack.core.ilm.ErrorStep} in order to retry the failing step. As {@link #assertBusy}
850
- // increases the wait time between calls exponentially, we might miss the window where the policy is on
851
- // {@link WaitForRolloverReadyStep} and the move to `attempt-rollover` request will not be successful.
852
- assertTrue (waitUntil (() -> {
853
- try {
854
- return client ().performRequest (moveToStepRequest ).getStatusLine ().getStatusCode () == 200 ;
855
- } catch (IOException e ) {
856
- return false ;
857
- }
858
- }, 30 , TimeUnit .SECONDS ));
859
-
860
- // Similar to above, using {@link #waitUntil} as we want to make sure the `attempt-rollover` step started failing and is being
861
- // retried (which means ILM moves back and forth between the `attempt-rollover` step and the `error` step)
862
- assertTrue ("ILM did not start retrying the attempt-rollover step" , waitUntil (() -> {
863
- try {
864
- Map <String , Object > explainIndexResponse = explainIndex (client (), index );
865
- String failedStep = (String ) explainIndexResponse .get ("failed_step" );
866
- Integer retryCount = (Integer ) explainIndexResponse .get (FAILED_STEP_RETRY_COUNT_FIELD );
867
- return failedStep != null && failedStep .equals ("attempt-rollover" ) && retryCount != null && retryCount >= 1 ;
868
- } catch (IOException e ) {
869
- return false ;
870
- }
871
- }, 30 , TimeUnit .SECONDS ));
872
-
873
- deleteIndex (rolledIndex );
874
-
875
- // the rollover step should eventually succeed
876
- assertBusy (() -> assertThat (indexExists (rolledIndex ), is (true )));
877
- assertBusy (() -> assertThat (getStepKeyForIndex (client (), index ), equalTo (PhaseCompleteStep .finalStep ("hot" ).getKey ())));
878
- }
879
-
880
- public void testUpdateRolloverLifecycleDateStepRetriesWhenRolloverInfoIsMissing () throws Exception {
881
- String index = this .index + "-000001" ;
882
-
883
- createNewSingletonPolicy (client (), policy , "hot" , new RolloverAction (null , null , null , 1L ));
884
-
885
- createIndexWithSettings (
886
- client (),
887
- index ,
888
- alias ,
889
- Settings .builder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
890
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
891
- .put (LifecycleSettings .LIFECYCLE_NAME , policy )
892
- .put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ),
893
- true
894
- );
895
-
896
- assertBusy (() -> assertThat (getStepKeyForIndex (client (), index ).getName (), is (WaitForRolloverReadyStep .NAME )));
897
-
898
- // moving ILM to the "update-rollover-lifecycle-date" without having gone through the actual rollover step
899
- // the "update-rollover-lifecycle-date" step will fail as the index has no rollover information
900
- Request moveToStepRequest = new Request ("POST" , "_ilm/move/" + index );
901
- moveToStepRequest .setJsonEntity ("{\n " +
902
- " \" current_step\" : {\n " +
903
- " \" phase\" : \" hot\" ,\n " +
904
- " \" action\" : \" rollover\" ,\n " +
905
- " \" name\" : \" check-rollover-ready\" \n " +
906
- " },\n " +
907
- " \" next_step\" : {\n " +
908
- " \" phase\" : \" hot\" ,\n " +
909
- " \" action\" : \" rollover\" ,\n " +
910
- " \" name\" : \" update-rollover-lifecycle-date\" \n " +
911
- " }\n " +
912
- "}" );
913
- client ().performRequest (moveToStepRequest );
914
-
915
- assertBusy (() -> assertThat ((Integer ) explainIndex (client (), index ).get (FAILED_STEP_RETRY_COUNT_FIELD ), greaterThanOrEqualTo (1 )),
916
- 30 , TimeUnit .SECONDS );
917
-
918
- index (client (), index , "1" , "foo" , "bar" );
919
- Request refreshIndex = new Request ("POST" , "/" + index + "/_refresh" );
920
- client ().performRequest (refreshIndex );
921
-
922
- // manual rollover the index so the "update-rollover-lifecycle-date" ILM step can continue and finish successfully as the index
923
- // will have rollover information now
924
- rolloverMaxOneDocCondition (client (), alias );
925
- assertBusy (() -> assertThat (getStepKeyForIndex (client (), index ), equalTo (PhaseCompleteStep .finalStep ("hot" ).getKey ())));
613
+ Request startILMRequest = new Request ("POST" , "_ilm/start" );
614
+ assertOK (client ().performRequest (startILMRequest ));
926
615
}
927
616
928
617
public void testWaitForActiveShardsStep () throws Exception {
0 commit comments