Skip to content

Commit 9329cb2

Browse files
committed
Add skip setting to shrink action
1 parent 19bc926 commit 9329cb2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
import org.elasticsearch.cluster.ProjectState;
1414
import org.elasticsearch.cluster.metadata.IndexMetadata;
1515
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
16+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
17+
import org.elasticsearch.common.settings.Settings;
1618
import org.elasticsearch.core.Tuple;
1719
import org.elasticsearch.index.Index;
1820

1921
import java.util.Objects;
2022
import java.util.function.BiFunction;
2123

24+
import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
25+
2226
/**
2327
* Copies the execution state data from one index to another, typically after a
2428
* new index has been created. As part of the execution state copy it will set the target index
@@ -101,8 +105,20 @@ public ProjectState performAction(Index index, ProjectState projectState) {
101105
newLifecycleState.setAction(action);
102106
newLifecycleState.setStep(step);
103107

108+
// Build a new index metadata with the version incremented and the new lifecycle state.
109+
IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(targetIndexMetadata)
110+
.version(targetIndexMetadata.getVersion() + 1)
111+
.putCustom(ILM_CUSTOM_METADATA_KEY, newLifecycleState.build().asMap());
112+
113+
// Remove the skip setting if it's present.
114+
if (targetIndexMetadata.getSettings().hasValue(LifecycleSettings.LIFECYCLE_SKIP)) {
115+
final var newSettings = Settings.builder().put(targetIndexMetadata.getSettings());
116+
newSettings.remove(LifecycleSettings.LIFECYCLE_SKIP);
117+
indexMetadataBuilder.settingsVersion(targetIndexMetadata.getSettingsVersion() + 1).settings(newSettings);
118+
}
119+
104120
return projectState.updateProject(
105-
projectState.metadata().withLifecycleState(targetIndexMetadata.getIndex(), newLifecycleState.build())
121+
ProjectMetadata.builder(projectState.metadata()).put(indexMetadataBuilder.build(), false).build()
106122
);
107123
}
108124

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void performAction(
8383
// need to remove the single shard, allocation so replicas can be allocated
8484
builder.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, indexMetadata.getNumberOfReplicas())
8585
.put(LifecycleSettings.LIFECYCLE_NAME, policyName)
86+
.put(LifecycleSettings.LIFECYCLE_SKIP, true)
8687
.put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", (String) null);
8788
if (numberOfShards != null) {
8889
builder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards);

0 commit comments

Comments
 (0)