conditionally update CS only if StepInfo changes (#33004)
If we are waiting on a condition to be met, and the reason it is not completed is unchanged, we find ourselves updating cluster state over and over again and kicking of the ILM listeners to re-check. This is overkill and can generate way too many cluster state updates
This commit is contained in:
parent
6780ab9d5c
commit
96869b253c
|
@ -278,11 +278,28 @@ public class IndexLifecycleRunner {
|
|||
return newClusterStateBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally updates cluster state with new step info. The new cluster state is only
|
||||
* built if the step info has changed, otherwise the same old <code>clusterState</code> is
|
||||
* returned
|
||||
*
|
||||
* @param index the index to modify
|
||||
* @param clusterState the cluster state to modify
|
||||
* @param stepInfo the new step info to update
|
||||
* @return Updated cluster state with <code>stepInfo</code> if changed, otherwise the same cluster state
|
||||
* if no changes to step info exist
|
||||
* @throws IOException if parsing step info fails
|
||||
*/
|
||||
static ClusterState addStepInfoToClusterState(Index index, ClusterState clusterState, ToXContentObject stepInfo) throws IOException {
|
||||
IndexMetaData idxMeta = clusterState.getMetaData().index(index);
|
||||
XContentBuilder infoXContentBuilder = JsonXContent.contentBuilder();
|
||||
final String stepInfoString;
|
||||
try (XContentBuilder infoXContentBuilder = JsonXContent.contentBuilder()) {
|
||||
stepInfo.toXContent(infoXContentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
String stepInfoString = BytesReference.bytes(infoXContentBuilder).utf8ToString();
|
||||
stepInfoString = BytesReference.bytes(infoXContentBuilder).utf8ToString();
|
||||
}
|
||||
if (stepInfoString.equals(LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(idxMeta.getSettings()))) {
|
||||
return clusterState;
|
||||
}
|
||||
Settings.Builder indexSettings = Settings.builder().put(idxMeta.getSettings())
|
||||
.put(LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.getKey(), stepInfoString);
|
||||
ClusterState.Builder newClusterStateBuilder = newClusterStateWithIndexSettings(index, clusterState, indexSettings);
|
||||
|
|
|
@ -820,6 +820,8 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
Index index = clusterState.metaData().index(indexName).getIndex();
|
||||
ClusterState newClusterState = IndexLifecycleRunner.addStepInfoToClusterState(index, clusterState, stepInfo);
|
||||
assertClusterStateStepInfo(clusterState, index, currentStep, newClusterState, stepInfo);
|
||||
ClusterState runAgainClusterState = IndexLifecycleRunner.addStepInfoToClusterState(index, newClusterState, stepInfo);
|
||||
assertSame(newClusterState, runAgainClusterState);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Reference in New Issue