Skip to content

Commit

Permalink
Reduce the number of times that LifecycleExecutionState is parsed w…
Browse files Browse the repository at this point in the history
…hen running a policy. (#77863) (#77882)

Sometimes the parsing done by `getCurrentStep()` method is unnecessary, because the
method calling the `getCurrentStep()` method has already parsed a `LifecycleExecutionState`
instance and can just provide that.

Relates to #77466
  • Loading branch information
martijnvg authored Sep 16, 2021
1 parent 4176187 commit 0659dda
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class IndexLifecycleRunner {
*/
static Step getCurrentStep(PolicyStepsRegistry stepRegistry, String policy, IndexMetadata indexMetadata) {
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
return getCurrentStep(stepRegistry, policy, indexMetadata, lifecycleState);
}

static Step getCurrentStep(PolicyStepsRegistry stepRegistry,
String policy,
IndexMetadata indexMetadata,
LifecycleExecutionState lifecycleState) {
StepKey currentStepKey = LifecycleExecutionState.getCurrentStepKey(lifecycleState);
logger.trace("[{}] retrieved current step key: {}", indexMetadata.getIndex().getName(), currentStepKey);
if (currentStepKey == null) {
Expand Down Expand Up @@ -126,7 +133,7 @@ void runPeriodicStep(String policy, Metadata metadata, IndexMetadata indexMetada
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
final Step currentStep;
try {
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata);
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata, lifecycleState);
} catch (Exception e) {
markPolicyRetrievalError(policy, indexMetadata.getIndex(), lifecycleState, e);
return;
Expand Down Expand Up @@ -261,7 +268,7 @@ void maybeRunAsyncAction(ClusterState currentState, IndexMetadata indexMetadata,
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
final Step currentStep;
try {
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata);
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata, lifecycleState);
} catch (Exception e) {
markPolicyRetrievalError(policy, indexMetadata.getIndex(), lifecycleState, e);
return;
Expand Down Expand Up @@ -322,7 +329,7 @@ void runPolicyAfterStateChange(String policy, IndexMetadata indexMetadata) {
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
final Step currentStep;
try {
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata);
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata, lifecycleState);
} catch (Exception e) {
markPolicyRetrievalError(policy, indexMetadata.getIndex(), lifecycleState, e);
return;
Expand Down

0 comments on commit 0659dda

Please sign in to comment.