@@ -271,11 +271,13 @@ static Step getCurrentStep(PolicyStepsRegistry stepRegistry, String policy, Inde
271
271
* @param nextStepKey The next step to move the index into
272
272
* @param nowSupplier The current-time supplier for updating when steps changed
273
273
* @param stepRegistry The steps registry to check a step-key's existence in the index's current policy
274
+ * @param forcePhaseDefinitionRefresh When true, step information will be recompiled from the latest version of the
275
+ * policy. Otherwise, existing phase definition is used.
274
276
* @return The updated cluster state where the index moved to <code>nextStepKey</code>
275
277
*/
276
278
static ClusterState moveClusterStateToStep (String indexName , ClusterState currentState , StepKey currentStepKey ,
277
279
StepKey nextStepKey , LongSupplier nowSupplier ,
278
- PolicyStepsRegistry stepRegistry ) {
280
+ PolicyStepsRegistry stepRegistry , boolean forcePhaseDefinitionRefresh ) {
279
281
IndexMetaData idxMeta = currentState .getMetaData ().index (indexName );
280
282
Settings indexSettings = idxMeta .getSettings ();
281
283
String indexPolicySetting = LifecycleSettings .LIFECYCLE_NAME_SETTING .get (indexSettings );
@@ -295,18 +297,19 @@ static ClusterState moveClusterStateToStep(String indexName, ClusterState curren
295
297
"] with policy [" + indexPolicySetting + "] does not exist" );
296
298
}
297
299
298
- return IndexLifecycleRunner .moveClusterStateToNextStep (idxMeta .getIndex (), currentState , currentStepKey , nextStepKey , nowSupplier );
300
+ return IndexLifecycleRunner .moveClusterStateToNextStep (idxMeta .getIndex (), currentState , currentStepKey ,
301
+ nextStepKey , nowSupplier , forcePhaseDefinitionRefresh );
299
302
}
300
303
301
304
static ClusterState moveClusterStateToNextStep (Index index , ClusterState clusterState , StepKey currentStep , StepKey nextStep ,
302
- LongSupplier nowSupplier ) {
305
+ LongSupplier nowSupplier , boolean forcePhaseDefinitionRefresh ) {
303
306
IndexMetaData idxMeta = clusterState .getMetaData ().index (index );
304
307
IndexLifecycleMetadata ilmMeta = clusterState .metaData ().custom (IndexLifecycleMetadata .TYPE );
305
308
LifecyclePolicyMetadata policyMetadata = ilmMeta .getPolicyMetadatas ()
306
309
.get (LifecycleSettings .LIFECYCLE_NAME_SETTING .get (idxMeta .getSettings ()));
307
310
LifecycleExecutionState lifecycleState = LifecycleExecutionState .fromIndexMetadata (idxMeta );
308
311
LifecycleExecutionState newLifecycleState = moveExecutionStateToNextStep (policyMetadata ,
309
- lifecycleState , currentStep , nextStep , nowSupplier );
312
+ lifecycleState , currentStep , nextStep , nowSupplier , forcePhaseDefinitionRefresh );
310
313
ClusterState .Builder newClusterStateBuilder = newClusterStateWithLifecycleState (index , clusterState , newLifecycleState );
311
314
312
315
return newClusterStateBuilder .build ();
@@ -324,7 +327,7 @@ static ClusterState moveClusterStateToErrorStep(Index index, ClusterState cluste
324
327
causeXContentBuilder .endObject ();
325
328
LifecycleExecutionState nextStepState = moveExecutionStateToNextStep (policyMetadata ,
326
329
LifecycleExecutionState .fromIndexMetadata (idxMeta ), currentStep , new StepKey (currentStep .getPhase (),
327
- currentStep .getAction (), ErrorStep .NAME ), nowSupplier );
330
+ currentStep .getAction (), ErrorStep .NAME ), nowSupplier , false );
328
331
LifecycleExecutionState .Builder failedState = LifecycleExecutionState .builder (nextStepState );
329
332
failedState .setFailedStep (currentStep .getName ());
330
333
failedState .setStepInfo (BytesReference .bytes (causeXContentBuilder ).utf8ToString ());
@@ -343,9 +346,9 @@ ClusterState moveClusterStateToFailedStep(ClusterState currentState, String[] in
343
346
StepKey currentStepKey = IndexLifecycleRunner .getCurrentStepKey (lifecycleState );
344
347
String failedStep = lifecycleState .getFailedStep ();
345
348
if (currentStepKey != null && ErrorStep .NAME .equals (currentStepKey .getName ())
346
- && Strings .isNullOrEmpty (failedStep ) == false ) {
349
+ && Strings .isNullOrEmpty (failedStep ) == false ) {
347
350
StepKey nextStepKey = new StepKey (currentStepKey .getPhase (), currentStepKey .getAction (), failedStep );
348
- newState = moveClusterStateToStep (index , currentState , currentStepKey , nextStepKey , nowSupplier , stepRegistry );
351
+ newState = moveClusterStateToStep (index , currentState , currentStepKey , nextStepKey , nowSupplier , stepRegistry , true );
349
352
} else {
350
353
throw new IllegalArgumentException ("cannot retry an action for an index ["
351
354
+ index + "] that has not encountered an error when running a Lifecycle Policy" );
@@ -357,7 +360,8 @@ ClusterState moveClusterStateToFailedStep(ClusterState currentState, String[] in
357
360
private static LifecycleExecutionState moveExecutionStateToNextStep (LifecyclePolicyMetadata policyMetadata ,
358
361
LifecycleExecutionState existingState ,
359
362
StepKey currentStep , StepKey nextStep ,
360
- LongSupplier nowSupplier ) {
363
+ LongSupplier nowSupplier ,
364
+ boolean forcePhaseDefinitionRefresh ) {
361
365
long nowAsMillis = nowSupplier .getAsLong ();
362
366
LifecycleExecutionState .Builder updatedState = LifecycleExecutionState .builder (existingState );
363
367
updatedState .setPhase (nextStep .getPhase ());
@@ -369,7 +373,7 @@ private static LifecycleExecutionState moveExecutionStateToNextStep(LifecyclePol
369
373
updatedState .setFailedStep (null );
370
374
updatedState .setStepInfo (null );
371
375
372
- if (currentStep .getPhase ().equals (nextStep .getPhase ()) == false ) {
376
+ if (currentStep .getPhase ().equals (nextStep .getPhase ()) == false || forcePhaseDefinitionRefresh ) {
373
377
final String newPhaseDefinition ;
374
378
final Phase nextPhase ;
375
379
if ("new" .equals (nextStep .getPhase ()) || TerminalPolicyStep .KEY .equals (nextStep )) {
0 commit comments