diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAction.java index 38493ae74ab..31d8519dd37 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAction.java @@ -79,7 +79,7 @@ public class ReplicasAction implements LifecycleAction { StepKey enoughKey = new StepKey(phase, NAME, ReplicasAllocatedStep.NAME); Settings replicaSettings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build(); return Arrays.asList(new UpdateSettingsStep(updateReplicasKey, enoughKey, client, replicaSettings), - new ReplicasAllocatedStep(enoughKey, nextStepKey, numberOfReplicas)); + new ReplicasAllocatedStep(enoughKey, nextStepKey)); } public int getNumberOfReplicas() { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStep.java index 1b23dae66c7..012a2c4515d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStep.java @@ -21,15 +21,9 @@ import java.util.Objects; public class ReplicasAllocatedStep extends ClusterStateWaitStep { public static final String NAME = "enough-shards-allocated"; - private int numberReplicas; - public ReplicasAllocatedStep(StepKey key, StepKey nextStepKey, int numberReplicas) { + public ReplicasAllocatedStep(StepKey key, StepKey nextStepKey) { super(key, nextStepKey); - this.numberReplicas = numberReplicas; - } - - int getNumberReplicas() { - return numberReplicas; } @Override @@ -41,73 +35,54 @@ public class ReplicasAllocatedStep extends ClusterStateWaitStep { } // We only want to make progress if the cluster state reflects the number of replicas change and all shards are active boolean allShardsActive = ActiveShardCount.ALL.enoughShardsActive(clusterState, index.getName()); - boolean isConditionMet = idxMeta.getNumberOfReplicas() == numberReplicas && allShardsActive; - if (isConditionMet) { + if (allShardsActive) { return new Result(true, null); } else { - return new Result(false, new Info(numberReplicas, idxMeta.getNumberOfReplicas(), allShardsActive)); + return new Result(false, new Info(idxMeta.getNumberOfReplicas(), allShardsActive)); } } - + @Override public int hashCode() { - return Objects.hash(super.hashCode(), numberReplicas); + return super.hashCode(); } - + @Override public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ReplicasAllocatedStep other = (ReplicasAllocatedStep) obj; - return super.equals(obj) && - Objects.equals(numberReplicas, other.numberReplicas); + return obj != null && getClass() == obj.getClass() && super.equals(obj); } - + public static final class Info implements ToXContentObject { - private final long expectedReplicas; private final long actualReplicas; private final boolean allShardsActive; private final String message; - static final ParseField EXPECTED_REPLICAS = new ParseField("expected_replicas"); static final ParseField ACTUAL_REPLICAS = new ParseField("actual_replicas"); static final ParseField ALL_SHARDS_ACTIVE = new ParseField("all_shards_active"); static final ParseField MESSAGE = new ParseField("message"); static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("replicas_allocated_step_info", - a -> new Info((long) a[0], (long) a[1], (boolean) a[2])); + a -> new Info((long) a[0], (boolean) a[1])); static { - PARSER.declareLong(ConstructingObjectParser.constructorArg(), EXPECTED_REPLICAS); PARSER.declareLong(ConstructingObjectParser.constructorArg(), ACTUAL_REPLICAS); PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), ALL_SHARDS_ACTIVE); PARSER.declareString((i, s) -> {}, MESSAGE); } - public Info(long expectedReplicas, long actualReplicas, boolean allShardsActive) { - this.expectedReplicas = expectedReplicas; + public Info(long actualReplicas, boolean allShardsActive) { this.actualReplicas = actualReplicas; this.allShardsActive = allShardsActive; - if (actualReplicas != expectedReplicas) { - message = "Waiting for " + IndexMetaData.SETTING_NUMBER_OF_REPLICAS + " to be updated to " + expectedReplicas; - } else if (allShardsActive == false) { + if (allShardsActive == false) { message = "Waiting for all shard copies to be active"; } else { message = ""; } } - public long getExpectedReplicas() { - return expectedReplicas; - } - public long getActualReplicas() { return actualReplicas; } - + public boolean allShardsActive() { return allShardsActive; } @@ -116,7 +91,6 @@ public class ReplicasAllocatedStep extends ClusterStateWaitStep { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(MESSAGE.getPreferredName(), message); - builder.field(EXPECTED_REPLICAS.getPreferredName(), expectedReplicas); builder.field(ACTUAL_REPLICAS.getPreferredName(), actualReplicas); builder.field(ALL_SHARDS_ACTIVE.getPreferredName(), allShardsActive); builder.endObject(); @@ -125,7 +99,7 @@ public class ReplicasAllocatedStep extends ClusterStateWaitStep { @Override public int hashCode() { - return Objects.hash(expectedReplicas, actualReplicas, allShardsActive); + return Objects.hash(actualReplicas, allShardsActive); } @Override @@ -137,8 +111,7 @@ public class ReplicasAllocatedStep extends ClusterStateWaitStep { return false; } Info other = (Info) obj; - return Objects.equals(expectedReplicas, other.expectedReplicas) && - Objects.equals(actualReplicas, other.actualReplicas) && + return Objects.equals(actualReplicas, other.actualReplicas) && Objects.equals(allShardsActive, other.allShardsActive); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkAction.java index b8c877a728a..33f89ea23c7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkAction.java @@ -86,8 +86,7 @@ public class ShrinkAction implements LifecycleAction { SetSingleNodeAllocateStep setSingleNodeStep = new SetSingleNodeAllocateStep(setSingleNodeKey, allocationRoutedKey, client); AllocationRoutedStep allocationStep = new AllocationRoutedStep(allocationRoutedKey, shrinkKey, false); ShrinkStep shrink = new ShrinkStep(shrinkKey, enoughShardsKey, client, numberOfShards, SHRUNKEN_INDEX_PREFIX); - ShrunkShardsAllocatedStep allocated = new ShrunkShardsAllocatedStep(enoughShardsKey, aliasKey, numberOfShards, - SHRUNKEN_INDEX_PREFIX); + ShrunkShardsAllocatedStep allocated = new ShrunkShardsAllocatedStep(enoughShardsKey, aliasKey, SHRUNKEN_INDEX_PREFIX); ShrinkSetAliasStep aliasSwapAndDelete = new ShrinkSetAliasStep(aliasKey, isShrunkIndexKey, client, SHRUNKEN_INDEX_PREFIX); ShrunkenIndexCheckStep waitOnShrinkTakeover = new ShrunkenIndexCheckStep(isShrunkIndexKey, nextStepKey, SHRUNKEN_INDEX_PREFIX); return Arrays.asList(setSingleNodeStep, allocationStep, shrink, allocated, aliasSwapAndDelete, waitOnShrinkTakeover); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStep.java index aeb07cfc7ce..b64ebf5e46b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStep.java @@ -19,19 +19,13 @@ import java.util.Objects; public class ShrunkShardsAllocatedStep extends ClusterStateWaitStep { public static final String NAME = "shrunk-shards-allocated"; - private final int numberOfShards; private String shrunkIndexPrefix; - public ShrunkShardsAllocatedStep(StepKey key, StepKey nextStepKey, int numberOfShards, String shrunkIndexPrefix) { + public ShrunkShardsAllocatedStep(StepKey key, StepKey nextStepKey, String shrunkIndexPrefix) { super(key, nextStepKey); - this.numberOfShards = numberOfShards; this.shrunkIndexPrefix = shrunkIndexPrefix; } - public int getNumberOfShards() { - return numberOfShards; - } - String getShrunkIndexPrefix() { return shrunkIndexPrefix; } @@ -42,23 +36,22 @@ public class ShrunkShardsAllocatedStep extends ClusterStateWaitStep { // active boolean indexExists = clusterState.metaData().index(shrunkIndexPrefix + index.getName()) != null; if (indexExists == false) { - return new Result(false, new Info(false, -1, -1, false)); + return new Result(false, new Info(false, -1, false)); } boolean allShardsActive = ActiveShardCount.ALL.enoughShardsActive(clusterState, shrunkIndexPrefix + index.getName()); int numShrunkIndexShards = clusterState.metaData().index(shrunkIndexPrefix + index.getName()).getNumberOfShards(); - boolean isConditionMet = numShrunkIndexShards == numberOfShards && allShardsActive; - if (isConditionMet) { + if (allShardsActive) { return new Result(true, null); } else { - return new Result(false, new Info(true, numberOfShards, numShrunkIndexShards, allShardsActive)); + return new Result(false, new Info(true, numShrunkIndexShards, allShardsActive)); } } - + @Override public int hashCode() { - return Objects.hash(super.hashCode(), numberOfShards, shrunkIndexPrefix); + return Objects.hash(super.hashCode(), shrunkIndexPrefix); } - + @Override public boolean equals(Object obj) { if (obj == null) { @@ -68,43 +61,35 @@ public class ShrunkShardsAllocatedStep extends ClusterStateWaitStep { return false; } ShrunkShardsAllocatedStep other = (ShrunkShardsAllocatedStep) obj; - return super.equals(obj) && - Objects.equals(numberOfShards, other.numberOfShards) && - Objects.equals(shrunkIndexPrefix, other.shrunkIndexPrefix); + return super.equals(obj) && Objects.equals(shrunkIndexPrefix, other.shrunkIndexPrefix); } public static final class Info implements ToXContentObject { - private final int expectedShards; private final int actualShards; private final boolean shrunkIndexExists; private final boolean allShardsActive; private final String message; - static final ParseField EXPECTED_SHARDS = new ParseField("expected_shards"); static final ParseField ACTUAL_SHARDS = new ParseField("actual_shards"); static final ParseField SHRUNK_INDEX_EXISTS = new ParseField("shrunk_index_exists"); static final ParseField ALL_SHARDS_ACTIVE = new ParseField("all_shards_active"); static final ParseField MESSAGE = new ParseField("message"); static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("shrunk_shards_allocated_step_info", - a -> new Info((boolean) a[0], (int) a[1], (int) a[2], (boolean) a[3])); + a -> new Info((boolean) a[0], (int) a[1], (boolean) a[2])); static { PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), SHRUNK_INDEX_EXISTS); - PARSER.declareInt(ConstructingObjectParser.constructorArg(), EXPECTED_SHARDS); PARSER.declareInt(ConstructingObjectParser.constructorArg(), ACTUAL_SHARDS); PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), ALL_SHARDS_ACTIVE); PARSER.declareString((i, s) -> {}, MESSAGE); } - public Info(boolean shrunkIndexExists, int expectedShards, int actualShards, boolean allShardsActive) { - this.expectedShards = expectedShards; + public Info(boolean shrunkIndexExists, int actualShards, boolean allShardsActive) { this.actualShards = actualShards; this.shrunkIndexExists = shrunkIndexExists; this.allShardsActive = allShardsActive; if (shrunkIndexExists == false) { message = "Waiting for shrunk index to be created"; - } else if (actualShards != expectedShards) { - message = "Waiting for shrunk index shards to be " + expectedShards; } else if (allShardsActive == false) { message = "Waiting for all shard copies to be active"; } else { @@ -112,10 +97,6 @@ public class ShrunkShardsAllocatedStep extends ClusterStateWaitStep { } } - public int getExpectedShards() { - return expectedShards; - } - public int getActualShards() { return actualShards; } @@ -133,7 +114,6 @@ public class ShrunkShardsAllocatedStep extends ClusterStateWaitStep { builder.startObject(); builder.field(MESSAGE.getPreferredName(), message); builder.field(SHRUNK_INDEX_EXISTS.getPreferredName(), shrunkIndexExists); - builder.field(EXPECTED_SHARDS.getPreferredName(), expectedShards); builder.field(ACTUAL_SHARDS.getPreferredName(), actualShards); builder.field(ALL_SHARDS_ACTIVE.getPreferredName(), allShardsActive); builder.endObject(); @@ -142,7 +122,7 @@ public class ShrunkShardsAllocatedStep extends ClusterStateWaitStep { @Override public int hashCode() { - return Objects.hash(shrunkIndexExists, expectedShards, actualShards, allShardsActive); + return Objects.hash(shrunkIndexExists, actualShards, allShardsActive); } @Override @@ -155,7 +135,6 @@ public class ShrunkShardsAllocatedStep extends ClusterStateWaitStep { } Info other = (Info) obj; return Objects.equals(shrunkIndexExists, other.shrunkIndexExists) && - Objects.equals(expectedShards, other.expectedShards) && Objects.equals(actualShards, other.actualShards) && Objects.equals(allShardsActive, other.allShardsActive); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStepInfoTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStepInfoTests.java index 9df2ccb94da..9769fd40e23 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStepInfoTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStepInfoTests.java @@ -17,7 +17,7 @@ public class ReplicasAllocatedStepInfoTests extends AbstractXContentTestCase randomIntBetween(0, 100))).build(); - MetaData metaData = MetaData.builder() - .persistentSettings(settings(Version.CURRENT).build()) - .put(IndexMetaData.builder(indexMetadata)) - .build(); - Index index = indexMetadata.getIndex(); - - String nodeId = randomAlphaOfLength(10); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(Node.NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); - - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) - .metaData(metaData) - .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()) - .routingTable(RoutingTable.builder() - .add(IndexRoutingTable.builder(index).addShard( - TestShardRouting.newShardRouting(new ShardId(index, 0), - nodeId, true, ShardRoutingState.STARTED))) - .build()) - .build(); - - Result result = step.isConditionMet(indexMetadata.getIndex(), clusterState); - assertFalse(result.isComplete()); - assertEquals(new ReplicasAllocatedStep.Info(step.getNumberReplicas(), indexMetadata.getNumberOfReplicas(), true), + assertEquals(new ReplicasAllocatedStep.Info(indexMetadata.getNumberOfReplicas(), false), result.getInfomationContext()); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkActionTests.java index 9a354b35a43..90c5b6240fa 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkActionTests.java @@ -70,7 +70,6 @@ public class ShrinkActionTests extends AbstractSerializingTestCase assertTrue(steps.get(3) instanceof ShrunkShardsAllocatedStep); assertThat(steps.get(3).getKey(), equalTo(expectedFourthKey)); assertThat(steps.get(3).getNextStepKey(), equalTo(expectedFifthKey)); - assertThat(((ShrunkShardsAllocatedStep) steps.get(3)).getNumberOfShards(), equalTo(action.getNumberOfShards())); assertThat(((ShrunkShardsAllocatedStep) steps.get(3)).getShrunkIndexPrefix(), equalTo(ShrinkAction.SHRUNKEN_INDEX_PREFIX)); assertTrue(steps.get(4) instanceof ShrinkSetAliasStep); assertThat(steps.get(4).getKey(), equalTo(expectedFifthKey)); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepInfoTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepInfoTests.java index 1426bbcfc0d..1ff0e045313 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepInfoTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepInfoTests.java @@ -17,7 +17,7 @@ public class ShrunkShardsAllocatedStepInfoTests extends AbstractXContentTestCase @Override protected Info createTestInstance() { - return new Info(randomBoolean(), randomIntBetween(0, 10000), randomIntBetween(0, 10000), randomBoolean()); + return new Info(randomBoolean(), randomIntBetween(0, 10000), randomBoolean()); } @Override @@ -37,31 +37,27 @@ public class ShrunkShardsAllocatedStepInfoTests extends AbstractXContentTestCase } protected final Info copyInstance(Info instance) throws IOException { - return new Info(instance.shrunkIndexExists(), instance.getExpectedShards(), instance.getActualShards(), instance.allShardsActive()); + return new Info(instance.shrunkIndexExists(), instance.getActualShards(), instance.allShardsActive()); } protected Info mutateInstance(Info instance) throws IOException { boolean shrunkIndexExists = instance.shrunkIndexExists(); - int expectedShards = instance.getExpectedShards(); int actualShards = instance.getActualShards(); boolean allShardsActive = instance.allShardsActive(); - switch (between(0, 3)) { + switch (between(0, 2)) { case 0: shrunkIndexExists = shrunkIndexExists == false; break; case 1: - expectedShards += between(1, 20); - break; - case 2: actualShards += between(1, 20); break; - case 3: + case 2: allShardsActive = allShardsActive == false; break; default: throw new AssertionError("Illegal randomisation branch"); } - return new Info(shrunkIndexExists, expectedShards, actualShards, allShardsActive); + return new Info(shrunkIndexExists, actualShards, allShardsActive); } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepTests.java index c05e052dd6a..272b50499d7 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepTests.java @@ -29,19 +29,17 @@ public class ShrunkShardsAllocatedStepTests extends AbstractStepTestCase