Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public List<Step> toSteps(Client client, String phase, Step.StepKey nextStepKey)
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@

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
Expand All @@ -41,73 +35,54 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
}
// 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;
}

public boolean allShardsActive() {
return allShardsActive;
}
Expand All @@ -116,7 +91,6 @@ public boolean allShardsActive() {
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();
Expand All @@ -125,7 +99,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public int hashCode() {
return Objects.hash(expectedReplicas, actualReplicas, allShardsActive);
return Objects.hash(actualReplicas, allShardsActive);
}

@Override
Expand All @@ -137,8 +111,7 @@ public boolean equals(Object obj) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public List<Step> toSteps(Client client, String phase, Step.StepKey nextStepKey)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@

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;
}
Expand All @@ -42,23 +36,22 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
// 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) {
Expand All @@ -68,54 +61,42 @@ public boolean equals(Object obj) {
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 {
message = "";
}
}

public int getExpectedShards() {
return expectedShards;
}

public int getActualShards() {
return actualShards;
}
Expand All @@ -133,7 +114,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
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();
Expand All @@ -142,7 +122,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public int hashCode() {
return Objects.hash(shrunkIndexExists, expectedShards, actualShards, allShardsActive);
return Objects.hash(shrunkIndexExists, actualShards, allShardsActive);
}

@Override
Expand All @@ -155,7 +135,6 @@ public boolean equals(Object obj) {
}
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,27 +37,18 @@ public final void testEqualsAndHashcode() {
}

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);
}

}
Loading