remove requirement for shards/replicas in allocation check steps (#30855)
As we are preparing to support policy updates/changes, we noticed that restricting allocation wait steps with pinned replicas/shard counts makes this difficult to continue from. For example, as user may update or switch a policy to increase replicas. If this is done, then the check will never pass and user intervention will be required. If we simply remove this restriction, we still check that the index is allocated correctly, but without depending on the newly configured replicas setting in the policy.
This commit is contained in:
parent
b0ab71e2fe
commit
abbe8ceffe
|
@ -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() {
|
||||
|
|
|
@ -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,69 +35,50 @@ 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<Info, Void> 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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,21 +36,20 @@ 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
|
||||
|
@ -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<Info, Void> 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);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class ReplicasAllocatedStepInfoTests extends AbstractXContentTestCase<Rep
|
|||
|
||||
@Override
|
||||
protected Info createTestInstance() {
|
||||
return new Info(randomNonNegativeLong(), randomNonNegativeLong(), randomBoolean());
|
||||
return new Info(randomNonNegativeLong(), randomBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,27 +37,18 @@ public class ReplicasAllocatedStepInfoTests extends AbstractXContentTestCase<Rep
|
|||
}
|
||||
|
||||
protected final Info copyInstance(Info instance) throws IOException {
|
||||
return new Info(instance.getExpectedReplicas(), instance.getActualReplicas(), instance.allShardsActive());
|
||||
return new Info(instance.getActualReplicas(), instance.allShardsActive());
|
||||
}
|
||||
|
||||
protected Info mutateInstance(Info instance) throws IOException {
|
||||
long expectedReplicas = instance.getExpectedReplicas();
|
||||
long actualReplicas = instance.getActualReplicas();
|
||||
boolean allShardsActive = instance.allShardsActive();
|
||||
switch (between(0, 2)) {
|
||||
case 0:
|
||||
expectedReplicas += between(1, 20);
|
||||
break;
|
||||
case 1:
|
||||
if (randomBoolean()) {
|
||||
actualReplicas += between(1, 20);
|
||||
break;
|
||||
case 2:
|
||||
} else {
|
||||
allShardsActive = allShardsActive == false;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
return new Info(expectedReplicas, actualReplicas, allShardsActive);
|
||||
return new Info(actualReplicas, allShardsActive);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,35 +31,24 @@ public class ReplicasAllocatedStepTests extends AbstractStepTestCase<ReplicasAll
|
|||
public ReplicasAllocatedStep createRandomInstance() {
|
||||
StepKey stepKey = randomStepKey();
|
||||
StepKey nextStepKey = randomStepKey();
|
||||
int numberReplicas = randomIntBetween(0, 100);
|
||||
return new ReplicasAllocatedStep(stepKey, nextStepKey, numberReplicas);
|
||||
return new ReplicasAllocatedStep(stepKey, nextStepKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplicasAllocatedStep mutateInstance(ReplicasAllocatedStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
int numberReplicas = instance.getNumberReplicas();
|
||||
switch (between(0, 2)) {
|
||||
case 0:
|
||||
if (randomBoolean()) {
|
||||
key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
break;
|
||||
case 1:
|
||||
} else {
|
||||
nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
break;
|
||||
case 2:
|
||||
numberReplicas += randomIntBetween(1, 5);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
|
||||
return new ReplicasAllocatedStep(key, nextKey, numberReplicas);
|
||||
return new ReplicasAllocatedStep(key, nextKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplicasAllocatedStep copyInstance(ReplicasAllocatedStep instance) {
|
||||
return new ReplicasAllocatedStep(instance.getKey(), instance.getNextStepKey(), instance.getNumberReplicas());
|
||||
return new ReplicasAllocatedStep(instance.getKey(), instance.getNextStepKey());
|
||||
}
|
||||
|
||||
public void testConditionMet() {
|
||||
|
@ -67,7 +56,7 @@ public class ReplicasAllocatedStepTests extends AbstractStepTestCase<ReplicasAll
|
|||
IndexMetaData indexMetadata = IndexMetaData.builder(randomAlphaOfLength(5))
|
||||
.settings(settings(Version.CURRENT))
|
||||
.numberOfShards(1)
|
||||
.numberOfReplicas(step.getNumberReplicas()).build();
|
||||
.numberOfReplicas(randomIntBetween(0, 5)).build();
|
||||
MetaData metaData = MetaData.builder()
|
||||
.persistentSettings(settings(Version.CURRENT).build())
|
||||
.put(IndexMetaData.builder(indexMetadata))
|
||||
|
@ -98,7 +87,7 @@ public class ReplicasAllocatedStepTests extends AbstractStepTestCase<ReplicasAll
|
|||
IndexMetaData indexMetadata = IndexMetaData.builder(randomAlphaOfLength(5))
|
||||
.settings(settings(Version.CURRENT))
|
||||
.numberOfShards(1)
|
||||
.numberOfReplicas(step.getNumberReplicas()).build();
|
||||
.numberOfReplicas(randomIntBetween(0, 5)).build();
|
||||
MetaData metaData = MetaData.builder()
|
||||
.persistentSettings(settings(Version.CURRENT).build())
|
||||
.put(IndexMetaData.builder(indexMetadata))
|
||||
|
@ -122,40 +111,7 @@ public class ReplicasAllocatedStepTests extends AbstractStepTestCase<ReplicasAll
|
|||
|
||||
Result result = step.isConditionMet(indexMetadata.getIndex(), clusterState);
|
||||
assertFalse(result.isComplete());
|
||||
assertEquals(new ReplicasAllocatedStep.Info(step.getNumberReplicas(), step.getNumberReplicas(), false),
|
||||
result.getInfomationContext());
|
||||
}
|
||||
|
||||
public void testConditionNotMetNumberReplicas() {
|
||||
ReplicasAllocatedStep step = createRandomInstance();
|
||||
IndexMetaData indexMetadata = IndexMetaData.builder(randomAlphaOfLength(5))
|
||||
.settings(settings(Version.CURRENT))
|
||||
.numberOfShards(1)
|
||||
.numberOfReplicas(randomValueOtherThan(step.getNumberReplicas(), () -> 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,6 @@ public class ShrinkActionTests extends AbstractSerializingTestCase<ShrinkAction>
|
|||
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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,19 +29,17 @@ public class ShrunkShardsAllocatedStepTests extends AbstractStepTestCase<ShrunkS
|
|||
public ShrunkShardsAllocatedStep createRandomInstance() {
|
||||
StepKey stepKey = randomStepKey();
|
||||
StepKey nextStepKey = randomStepKey();
|
||||
int numberOfShards = randomIntBetween(1, 10);
|
||||
String shrunkIndexPrefix = randomAlphaOfLength(10);
|
||||
return new ShrunkShardsAllocatedStep(stepKey, nextStepKey, numberOfShards, shrunkIndexPrefix);
|
||||
return new ShrunkShardsAllocatedStep(stepKey, nextStepKey, shrunkIndexPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShrunkShardsAllocatedStep mutateInstance(ShrunkShardsAllocatedStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
int numberOfShards = instance.getNumberOfShards();
|
||||
String shrunkIndexPrefix = instance.getShrunkIndexPrefix();
|
||||
|
||||
switch (between(0, 3)) {
|
||||
switch (between(0, 2)) {
|
||||
case 0:
|
||||
key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
break;
|
||||
|
@ -49,28 +47,24 @@ public class ShrunkShardsAllocatedStepTests extends AbstractStepTestCase<ShrunkS
|
|||
nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
break;
|
||||
case 2:
|
||||
numberOfShards = numberOfShards + 1;
|
||||
break;
|
||||
case 3:
|
||||
shrunkIndexPrefix += randomAlphaOfLength(5);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
|
||||
return new ShrunkShardsAllocatedStep(key, nextKey, numberOfShards, shrunkIndexPrefix);
|
||||
return new ShrunkShardsAllocatedStep(key, nextKey, shrunkIndexPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShrunkShardsAllocatedStep copyInstance(ShrunkShardsAllocatedStep instance) {
|
||||
return new ShrunkShardsAllocatedStep(instance.getKey(), instance.getNextStepKey(), instance.getNumberOfShards(),
|
||||
instance.getShrunkIndexPrefix());
|
||||
return new ShrunkShardsAllocatedStep(instance.getKey(), instance.getNextStepKey(), instance.getShrunkIndexPrefix());
|
||||
}
|
||||
|
||||
public void testConditionMet() {
|
||||
ShrunkShardsAllocatedStep step = createRandomInstance();
|
||||
int shrinkNumberOfShards = step.getNumberOfShards();
|
||||
int originalNumberOfShards = step.getNumberOfShards();
|
||||
int shrinkNumberOfShards = randomIntBetween(1, 5);
|
||||
int originalNumberOfShards = randomIntBetween(1, 5);
|
||||
String originalIndexName = randomAlphaOfLength(5);
|
||||
IndexMetaData originalIndexMetadata = IndexMetaData.builder(originalIndexName)
|
||||
.settings(settings(Version.CURRENT))
|
||||
|
@ -109,8 +103,8 @@ public class ShrunkShardsAllocatedStepTests extends AbstractStepTestCase<ShrunkS
|
|||
|
||||
public void testConditionNotMetBecauseOfActive() {
|
||||
ShrunkShardsAllocatedStep step = createRandomInstance();
|
||||
int shrinkNumberOfShards = step.getNumberOfShards();
|
||||
int originalNumberOfShards = step.getNumberOfShards();
|
||||
int shrinkNumberOfShards = randomIntBetween(1, 5);
|
||||
int originalNumberOfShards = randomIntBetween(1, 5);
|
||||
String originalIndexName = randomAlphaOfLength(5);
|
||||
IndexMetaData originalIndexMetadata = IndexMetaData.builder(originalIndexName)
|
||||
.settings(settings(Version.CURRENT))
|
||||
|
@ -144,55 +138,13 @@ public class ShrunkShardsAllocatedStepTests extends AbstractStepTestCase<ShrunkS
|
|||
|
||||
Result result = step.isConditionMet(originalIndexMetadata.getIndex(), clusterState);
|
||||
assertFalse(result.isComplete());
|
||||
assertEquals(new ShrunkShardsAllocatedStep.Info(true, shrinkNumberOfShards, shrinkNumberOfShards, false),
|
||||
result.getInfomationContext());
|
||||
}
|
||||
|
||||
public void testConditionNotMetBecauseOfShardCount() {
|
||||
ShrunkShardsAllocatedStep step = createRandomInstance();
|
||||
int shrinkNumberOfShards = step.getNumberOfShards();
|
||||
int actualShrinkNumberShards = shrinkNumberOfShards + randomIntBetween(1, 5);
|
||||
int originalNumberOfShards = step.getNumberOfShards();
|
||||
String originalIndexName = randomAlphaOfLength(5);
|
||||
IndexMetaData originalIndexMetadata = IndexMetaData.builder(originalIndexName)
|
||||
.settings(settings(Version.CURRENT))
|
||||
.numberOfShards(originalNumberOfShards)
|
||||
.numberOfReplicas(0).build();
|
||||
IndexMetaData shrunkIndexMetadata = IndexMetaData.builder(step.getShrunkIndexPrefix() + originalIndexName)
|
||||
.settings(settings(Version.CURRENT))
|
||||
.numberOfShards(actualShrinkNumberShards)
|
||||
.numberOfReplicas(0).build();
|
||||
MetaData metaData = MetaData.builder()
|
||||
.persistentSettings(settings(Version.CURRENT).build())
|
||||
.put(IndexMetaData.builder(originalIndexMetadata))
|
||||
.put(IndexMetaData.builder(shrunkIndexMetadata))
|
||||
.build();
|
||||
Index shrinkIndex = shrunkIndexMetadata.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);
|
||||
|
||||
IndexRoutingTable.Builder builder = IndexRoutingTable.builder(shrinkIndex);
|
||||
for (int i = 0; i < actualShrinkNumberShards; i++) {
|
||||
builder.addShard(TestShardRouting.newShardRouting(new ShardId(shrinkIndex, i),
|
||||
nodeId, true, ShardRoutingState.STARTED));
|
||||
}
|
||||
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT)
|
||||
.metaData(metaData)
|
||||
.nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build())
|
||||
.routingTable(RoutingTable.builder().add(builder.build()).build()).build();
|
||||
|
||||
Result result = step.isConditionMet(originalIndexMetadata.getIndex(), clusterState);
|
||||
assertFalse(result.isComplete());
|
||||
assertEquals(new ShrunkShardsAllocatedStep.Info(true, shrinkNumberOfShards, actualShrinkNumberShards, true),
|
||||
assertEquals(new ShrunkShardsAllocatedStep.Info(true, shrinkNumberOfShards, false),
|
||||
result.getInfomationContext());
|
||||
}
|
||||
|
||||
public void testConditionNotMetBecauseOfShrunkIndexDoesntExistYet() {
|
||||
ShrunkShardsAllocatedStep step = createRandomInstance();
|
||||
int originalNumberOfShards = step.getNumberOfShards();
|
||||
int originalNumberOfShards = randomIntBetween(1, 5);
|
||||
String originalIndexName = randomAlphaOfLength(5);
|
||||
IndexMetaData originalIndexMetadata = IndexMetaData.builder(originalIndexName)
|
||||
.settings(settings(Version.CURRENT))
|
||||
|
@ -214,6 +166,6 @@ public class ShrunkShardsAllocatedStepTests extends AbstractStepTestCase<ShrunkS
|
|||
|
||||
Result result = step.isConditionMet(originalIndexMetadata.getIndex(), clusterState);
|
||||
assertFalse(result.isComplete());
|
||||
assertEquals(new ShrunkShardsAllocatedStep.Info(false, -1, -1, false), result.getInfomationContext());
|
||||
assertEquals(new ShrunkShardsAllocatedStep.Info(false, -1, false), result.getInfomationContext());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue