Skip to content

Commit 32c8490

Browse files
committed
PR feedback
1 parent 44f2bbb commit 32c8490

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929
* Resizes an index with the specified settings, using the name that was generated in a previous {@link GenerateUniqueIndexNameStep} step.
3030
*/
3131
public class ResizeIndexStep extends AsyncActionStep {
32+
33+
public static final String SHRINK = "shrink";
34+
public static final String CLONE = "clone";
3235
private static final Logger logger = LogManager.getLogger(ResizeIndexStep.class);
3336

3437
private final ResizeType resizeType;
3538
private final BiFunction<String, LifecycleExecutionState, String> targetIndexNameSupplier;
39+
/** A supplier that takes the index metadata of the <i>original</i> index and returns settings for the target index . */
3640
private final Function<IndexMetadata, Settings> targetIndexSettingsSupplier;
3741
@Nullable
3842
private final ByteSizeValue maxPrimaryShardSize;
@@ -51,6 +55,7 @@ public ResizeIndexStep(
5155
this.targetIndexNameSupplier = targetIndexNameSupplier;
5256
this.targetIndexSettingsSupplier = targetIndexSettingsSupplier;
5357
this.maxPrimaryShardSize = maxPrimaryShardSize;
58+
assert resizeType == ResizeType.SHRINK || maxPrimaryShardSize == null : "maxPrimaryShardSize can only be set for shrink operations";
5459
}
5560

5661
@Override
@@ -94,9 +99,13 @@ public void performAction(
9499
TimeValue.MAX_VALUE
95100
);
96101
resizeRequest.setResizeType(resizeType);
97-
resizeRequest.setMaxPrimaryShardSize(maxPrimaryShardSize);
98102
resizeRequest.getTargetIndexRequest().settings(relevantTargetSettings);
103+
if (resizeType == ResizeType.SHRINK) {
104+
resizeRequest.setMaxPrimaryShardSize(maxPrimaryShardSize);
105+
}
99106

107+
// This request does not wait for (successful) completion of the resize operation - it fires-and-forgets.
108+
// It's up to a subsequent step to check for the existence of the target index and wait for it to be green.
100109
getClient(currentState.projectId()).admin()
101110
.indices()
102111
.resizeIndex(resizeRequest, listener.delegateFailureAndWrap((l, response) -> l.onResponse(null)));

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public class ShrinkAction implements LifecycleAction {
4848
public static final ParseField ALLOW_WRITE_AFTER_SHRINK = new ParseField("allow_write_after_shrink");
4949
public static final String CONDITIONAL_SKIP_SHRINK_STEP = BranchingStep.NAME + "-check-prerequisites";
5050
public static final String CLEANUP_SHRINK_INDEX_STEP = "cleanup-shrink-index";
51-
public static final String SHRINK_STEP = "shrink";
5251
public static final String CONDITIONAL_DATASTREAM_CHECK_KEY = BranchingStep.NAME + "-on-datastream-check";
5352

5453
private static final ConstructingObjectParser<ShrinkAction, Void> PARSER = new ConstructingObjectParser<>(
@@ -175,7 +174,7 @@ public List<Step> toSteps(Client client, String phase, Step.StepKey nextStepKey)
175174
StepKey generateShrinkIndexNameKey = new StepKey(phase, NAME, GenerateUniqueIndexNameStep.NAME);
176175
StepKey setSingleNodeKey = new StepKey(phase, NAME, SetSingleNodeAllocateStep.NAME);
177176
StepKey allocationRoutedKey = new StepKey(phase, NAME, CheckShrinkReadyStep.NAME);
178-
StepKey shrinkKey = new StepKey(phase, NAME, SHRINK_STEP);
177+
StepKey shrinkKey = new StepKey(phase, NAME, ResizeIndexStep.SHRINK);
179178
StepKey enoughShardsKey = new StepKey(phase, NAME, ShrunkShardsAllocatedStep.NAME);
180179
StepKey copyMetadataKey = new StepKey(phase, NAME, CopyExecutionStateStep.NAME);
181180
StepKey dataStreamCheckBranchingKey = new StepKey(phase, NAME, CONDITIONAL_DATASTREAM_CHECK_KEY);

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ResizeIndexStepTests.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public ResizeIndexStep createRandomInstance() {
3939
ResizeType resizeType = randomFrom(ResizeType.values());
4040
Settings.Builder settings = Settings.builder();
4141
ByteSizeValue maxPrimaryShardSize = null;
42-
if (randomBoolean()) {
42+
// Only shrink supports max_primary_shard_size, so if we pick shrink we sometimes set it, otherwise we always
43+
// set number_of_shards.
44+
if (resizeType != ResizeType.SHRINK || randomBoolean()) {
4345
settings.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 20));
4446
} else {
4547
maxPrimaryShardSize = ByteSizeValue.ofBytes(between(1, 100));
@@ -65,7 +67,14 @@ public ResizeIndexStep mutateInstance(ResizeIndexStep instance) {
6567
switch (between(0, 2)) {
6668
case 0 -> key = new StepKey(key.phase(), key.action(), key.name() + randomAlphaOfLength(5));
6769
case 1 -> nextKey = new StepKey(nextKey.phase(), nextKey.action(), nextKey.name() + randomAlphaOfLength(5));
68-
case 2 -> resizeType = randomValueOtherThan(resizeType, () -> randomFrom(ResizeType.values()));
70+
case 2 -> {
71+
if (resizeType != ResizeType.SHRINK || randomBoolean()) {
72+
resizeType = randomValueOtherThan(resizeType, () -> randomFrom(ResizeType.values()));
73+
maxPrimaryShardSize = null;
74+
} else {
75+
maxPrimaryShardSize = randomValueOtherThan(maxPrimaryShardSize, () -> ByteSizeValue.ofBytes(between(1, 100)));
76+
}
77+
}
6978
default -> throw new AssertionError("Illegal randomisation branch");
7079
}
7180

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public void testToSteps() {
290290
StepKey generateShrinkIndexNameKey = new StepKey(phase, ShrinkAction.NAME, GenerateUniqueIndexNameStep.NAME);
291291
StepKey setSingleNodeKey = new StepKey(phase, ShrinkAction.NAME, SetSingleNodeAllocateStep.NAME);
292292
StepKey allocationRoutedKey = new StepKey(phase, ShrinkAction.NAME, CheckShrinkReadyStep.NAME);
293-
StepKey shrinkKey = new StepKey(phase, ShrinkAction.NAME, ShrinkAction.SHRINK_STEP);
293+
StepKey shrinkKey = new StepKey(phase, ShrinkAction.NAME, ResizeIndexStep.SHRINK);
294294
StepKey enoughShardsKey = new StepKey(phase, ShrinkAction.NAME, ShrunkShardsAllocatedStep.NAME);
295295
StepKey copyMetadataKey = new StepKey(phase, ShrinkAction.NAME, CopyExecutionStateStep.NAME);
296296
StepKey dataStreamCheckBranchingKey = new StepKey(phase, ShrinkAction.NAME, ShrinkAction.CONDITIONAL_DATASTREAM_CHECK_KEY);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
4949
import org.elasticsearch.xpack.core.ilm.OperationMode;
5050
import org.elasticsearch.xpack.core.ilm.OperationModeUpdateTask;
51+
import org.elasticsearch.xpack.core.ilm.ResizeIndexStep;
5152
import org.elasticsearch.xpack.core.ilm.SetSingleNodeAllocateStep;
5253
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
5354
import org.elasticsearch.xpack.core.ilm.ShrunkShardsAllocatedStep;
@@ -83,7 +84,7 @@ public class IndexLifecycleService
8384
IndexEventListener,
8485
ShutdownAwarePlugin {
8586
private static final Logger logger = LogManager.getLogger(IndexLifecycleService.class);
86-
private static final Set<String> IGNORE_STEPS_MAINTENANCE_REQUESTED = Set.of(ShrinkAction.SHRINK_STEP, DownsampleStep.NAME);
87+
private static final Set<String> IGNORE_STEPS_MAINTENANCE_REQUESTED = Set.of(ResizeIndexStep.SHRINK, DownsampleStep.NAME);
8788
private volatile boolean isMaster = false;
8889
private volatile TimeValue pollInterval;
8990

@@ -617,7 +618,7 @@ static boolean hasIndicesInDangerousStepForNodeShutdown(ClusterState state, Stri
617618
String step = indexToMetadata.getValue().getLifecycleExecutionState().step();
618619
return SetSingleNodeAllocateStep.NAME.equals(step)
619620
|| CheckShrinkReadyStep.NAME.equals(step)
620-
|| ShrinkAction.SHRINK_STEP.equals(step)
621+
|| ResizeIndexStep.SHRINK.equals(step)
621622
|| ShrunkShardsAllocatedStep.NAME.equals(step);
622623
})
623624
// Only look at indices where the node picked for the shrink is the node marked as shutting down

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.elasticsearch.xpack.core.ilm.OperationMode;
5151
import org.elasticsearch.xpack.core.ilm.OperationModeUpdateTask;
5252
import org.elasticsearch.xpack.core.ilm.Phase;
53+
import org.elasticsearch.xpack.core.ilm.ResizeIndexStep;
5354
import org.elasticsearch.xpack.core.ilm.SetSingleNodeAllocateStep;
5455
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
5556
import org.elasticsearch.xpack.core.ilm.ShrunkShardsAllocatedStep;
@@ -183,7 +184,7 @@ public void testStoppedModeSkip() {
183184
}
184185

185186
public void testRequestedStopOnShrink() {
186-
Step.StepKey mockShrinkStep = new Step.StepKey(randomAlphaOfLength(4), ShrinkAction.NAME, ShrinkAction.SHRINK_STEP);
187+
Step.StepKey mockShrinkStep = new Step.StepKey(randomAlphaOfLength(4), ShrinkAction.NAME, ResizeIndexStep.SHRINK);
187188
String policyName = randomAlphaOfLengthBetween(1, 20);
188189
IndexLifecycleRunnerTests.MockClusterStateActionStep mockStep = new IndexLifecycleRunnerTests.MockClusterStateActionStep(
189190
mockShrinkStep,
@@ -231,7 +232,7 @@ public void testRequestedStopInShrinkActionButNotShrinkStep() {
231232
action.toSteps(mock(Client.class), "warm", randomStepKey())
232233
.stream()
233234
.map(sk -> sk.getKey().name())
234-
.filter(name -> name.equals(ShrinkAction.SHRINK_STEP) == false)
235+
.filter(name -> name.equals(ResizeIndexStep.SHRINK) == false)
235236
.forEach(this::verifyCanStopWithStep);
236237
}
237238

@@ -562,7 +563,7 @@ public void testHasIndicesInDangerousStepForNodeShutdown() {
562563
randomFrom(
563564
SetSingleNodeAllocateStep.NAME,
564565
CheckShrinkReadyStep.NAME,
565-
ShrinkAction.SHRINK_STEP,
566+
ResizeIndexStep.SHRINK,
566567
ShrunkShardsAllocatedStep.NAME
567568
)
568569
)

x-pack/plugin/shutdown/src/test/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusActionTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.elasticsearch.xpack.core.ilm.ErrorStep;
5555
import org.elasticsearch.xpack.core.ilm.LifecycleOperationMetadata;
5656
import org.elasticsearch.xpack.core.ilm.OperationMode;
57+
import org.elasticsearch.xpack.core.ilm.ResizeIndexStep;
5758
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
5859
import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType;
5960
import org.hamcrest.Matcher;
@@ -693,7 +694,7 @@ public void testExplainThrottled() {
693694
public void testIlmShrinkingIndexAvoidsStall() {
694695
LifecycleExecutionState executionState = LifecycleExecutionState.builder()
695696
.setAction(ShrinkAction.NAME)
696-
.setStep(ShrinkAction.SHRINK_STEP)
697+
.setStep(ResizeIndexStep.SHRINK)
697698
.setPhase(randomFrom("hot", "warm"))
698699
.build();
699700
checkStalledShardWithIlmState(executionState, OperationMode.RUNNING, SingleNodeShutdownMetadata.Status.IN_PROGRESS);
@@ -702,15 +703,15 @@ public void testIlmShrinkingIndexAvoidsStall() {
702703
public void testIlmShrinkingWithIlmStoppingIndexAvoidsStall() {
703704
LifecycleExecutionState executionState = LifecycleExecutionState.builder()
704705
.setAction(ShrinkAction.NAME)
705-
.setStep(ShrinkAction.SHRINK_STEP)
706+
.setStep(ResizeIndexStep.SHRINK)
706707
.build();
707708
checkStalledShardWithIlmState(executionState, OperationMode.STOPPING, SingleNodeShutdownMetadata.Status.IN_PROGRESS);
708709
}
709710

710711
public void testIlmShrinkingButIlmStoppedDoesNotAvoidStall() {
711712
LifecycleExecutionState executionState = LifecycleExecutionState.builder()
712713
.setAction(ShrinkAction.NAME)
713-
.setStep(ShrinkAction.SHRINK_STEP)
714+
.setStep(ResizeIndexStep.SHRINK)
714715
.build();
715716
checkStalledShardWithIlmState(executionState, OperationMode.STOPPED, SingleNodeShutdownMetadata.Status.STALLED);
716717
}

0 commit comments

Comments
 (0)