Skip to content

Commit 0659dda

Browse files
authored
Reduce the number of times that LifecycleExecutionState is parsed when 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
1 parent 4176187 commit 0659dda

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class IndexLifecycleRunner {
6262
*/
6363
static Step getCurrentStep(PolicyStepsRegistry stepRegistry, String policy, IndexMetadata indexMetadata) {
6464
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
65+
return getCurrentStep(stepRegistry, policy, indexMetadata, lifecycleState);
66+
}
67+
68+
static Step getCurrentStep(PolicyStepsRegistry stepRegistry,
69+
String policy,
70+
IndexMetadata indexMetadata,
71+
LifecycleExecutionState lifecycleState) {
6572
StepKey currentStepKey = LifecycleExecutionState.getCurrentStepKey(lifecycleState);
6673
logger.trace("[{}] retrieved current step key: {}", indexMetadata.getIndex().getName(), currentStepKey);
6774
if (currentStepKey == null) {
@@ -126,7 +133,7 @@ void runPeriodicStep(String policy, Metadata metadata, IndexMetadata indexMetada
126133
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
127134
final Step currentStep;
128135
try {
129-
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata);
136+
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata, lifecycleState);
130137
} catch (Exception e) {
131138
markPolicyRetrievalError(policy, indexMetadata.getIndex(), lifecycleState, e);
132139
return;
@@ -261,7 +268,7 @@ void maybeRunAsyncAction(ClusterState currentState, IndexMetadata indexMetadata,
261268
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
262269
final Step currentStep;
263270
try {
264-
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata);
271+
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata, lifecycleState);
265272
} catch (Exception e) {
266273
markPolicyRetrievalError(policy, indexMetadata.getIndex(), lifecycleState, e);
267274
return;
@@ -322,7 +329,7 @@ void runPolicyAfterStateChange(String policy, IndexMetadata indexMetadata) {
322329
LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata);
323330
final Step currentStep;
324331
try {
325-
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata);
332+
currentStep = getCurrentStep(stepRegistry, policy, indexMetadata, lifecycleState);
326333
} catch (Exception e) {
327334
markPolicyRetrievalError(policy, indexMetadata.getIndex(), lifecycleState, e);
328335
return;

0 commit comments

Comments
 (0)