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