-
Notifications
You must be signed in to change notification settings - Fork 25.6k
stop throwing an IllegalStateException for unrecognized steps #32212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5e66362
3235a1f
5a96ade
f19ba97
24ee939
81bf84c
c82a463
c009641
460fb34
76f9245
4bb6910
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
|
|
||
| import org.apache.logging.log4j.Logger; | ||
| import org.elasticsearch.ElasticsearchException; | ||
| import org.elasticsearch.action.support.TransportAction; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
| import org.elasticsearch.cluster.metadata.MetaData; | ||
|
|
@@ -64,8 +65,11 @@ public void runPolicy(String policy, IndexMetaData indexMetaData, ClusterState c | |
| } | ||
| Step currentStep = getCurrentStep(stepRegistry, policy, indexSettings); | ||
| if (currentStep == null) { | ||
| throw new IllegalStateException( | ||
| "current step for index [" + indexMetaData.getIndex().getName() + "] with policy [" + policy + "] is not recognized"); | ||
| // This may happen in the case that there is invalid ilm-step index settings or the stepRegistry is out of | ||
| // sync with the current cluster state | ||
| logger.warn("current step [" + getCurrentStepKey(indexSettings) + "] for index [" + indexMetaData.getIndex().getName() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although I love that we want to provide the step info here, I have mixed feelings about the assertions that exist inside of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the assertions are fine because ILM is in full control of the phase, action and step settings (they are INTERNAL settings so can't be touched by a user and will soon be moved to a custom index metadata object further locking down access to them. Therefore, I don't think its necessary to check that if one is set all three are set in production code but its useful to have the check in testing to make sure we don't do something silly so assertions feel right to me. |
||
| + "] with policy [" + policy + "] is not recognized"); | ||
| return; | ||
| } | ||
| logger.debug("running policy with current-step[" + currentStep.getKey() + "]"); | ||
| if (currentStep instanceof TerminalPolicyStep) { | ||
|
|
@@ -164,6 +168,23 @@ static Step getCurrentStep(PolicyStepsRegistry stepRegistry, String policy, Sett | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * This method is intended for handling moving to different steps from {@link TransportAction} executions. | ||
| * For this reason, it is reasonable to throw {@link IllegalArgumentException} when state is not as expected. | ||
| * @param indexName | ||
| * The index whose step is to change | ||
| * @param currentState | ||
| * The current {@link ClusterState} | ||
| * @param currentStepKey | ||
| * The current {@link StepKey} found for the index in the current cluster state | ||
| * @param nextStepKey | ||
| * The next step to move the index into | ||
| * @param nowSupplier | ||
| * The current-time supplier for updating when steps changed | ||
| * @param stepRegistry | ||
| * The steps registry to check a step-key's existence in the index's current policy | ||
| * @return The updated cluster state where the index moved to <code>nextStepKey</code> | ||
| */ | ||
| static ClusterState moveClusterStateToStep(String indexName, ClusterState currentState, StepKey currentStepKey, | ||
| StepKey nextStepKey, LongSupplier nowSupplier, | ||
| PolicyStepsRegistry stepRegistry) { | ||
|
|
@@ -180,10 +201,9 @@ static ClusterState moveClusterStateToStep(String indexName, ClusterState curren | |
| throw new IllegalArgumentException("index [" + indexName + "] is not on current step [" + currentStepKey + "]"); | ||
| } | ||
|
|
||
| try { | ||
| stepRegistry.getStep(indexPolicySetting, nextStepKey); | ||
| } catch (IllegalStateException e) { | ||
| throw new IllegalArgumentException(e.getMessage()); | ||
| Step nextStep = stepRegistry.getStep(indexPolicySetting, nextStepKey); | ||
| if (nextStep == null) { | ||
| throw new IllegalArgumentException("step [" + nextStepKey + "] with policy [" + indexPolicySetting + "] does not exist"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain why this still needs to throw an exception rather than just returning an unmodified cluster state? Also I know we threw an IllegalArgumentException before but it feels wrong to me since the user won't have supplied anything invalid
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am cool with that. I still feel like IllegalArgumentException should be thrown to users of TransportMoveToStepAction. So I will push up a basic exception for that, and it will know that nothing "right" happened since the clusterStates will be the same instance |
||
| } | ||
|
|
||
| return IndexLifecycleRunner.moveClusterStateToNextStep(idxMeta.getIndex(), currentState, currentStepKey, nextStepKey, nowSupplier); | ||
|
|
@@ -358,7 +378,7 @@ private static boolean canSetPolicy(StepKey currentStepKey, LifecyclePolicy curr | |
| return true; | ||
| } | ||
| } | ||
|
|
||
| private static boolean isActionChanged(StepKey stepKey, LifecyclePolicy currentPolicy, LifecyclePolicy newPolicy) { | ||
| LifecycleAction currentAction = getActionFromPolicy(currentPolicy, stepKey.getPhase(), stepKey.getAction()); | ||
| LifecycleAction newAction = getActionFromPolicy(newPolicy, stepKey.getPhase(), stepKey.getAction()); | ||
|
|
@@ -385,7 +405,7 @@ private static LifecycleAction getActionFromPolicy(LifecyclePolicy policy, Strin | |
| * state where it is able to deal with the policy being updated to | ||
| * <code>newPolicy</code>. If any of these indexes is not in a state wheree | ||
| * it can deal with the update the method will return <code>false</code>. | ||
| * | ||
| * | ||
| * @param policyName | ||
| * the name of the policy being updated | ||
| * @param newPolicy | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked closer at this. I missed something here.
This method calls
PolicyStepsRegistry#getStep, which chooses to throw IllegalStateExceptions as well. Further investigation to see what the repercussions of changing that is necessary.and tests need to be added to walk these paths as well. Current tests do not catch this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, should https://github.com/talevy/elasticsearch/blob/80ab7739ca8877e2036edfac724f6014fefb7e52/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/PolicyStepsRegistry.java#L101-L114 continue to throw an IllegalStateException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we probably need to make
PolicyStepsRegistry.getStep()returnnullif the step is missing (in much the same way that a map returnsnullfor a missing key. Then we'll have to check fornull:IndexLifecycleRunner.runPolicy()and if itsnulllog a warning and returnIndexLifecycleRunner.moveClusterStateToStep()where I think we should do the same as aboveExecuteStepsUpdateTask.execute()where we should log the warning if itsnullbut return the cluster state up to changing the current step so we don't lose all the progress made on the previous cluster state stepswdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is what I was thinking as well. Just wanted to double check with you before I take that route