Skip to content

Commit

Permalink
Remove obsolete BWC for max_primary_shard_size (#72504)
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo authored Apr 29, 2021
1 parent 6a7298e commit e85889a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package org.elasticsearch.action.admin.indices.rollover;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.ByteSizeUnit;
Expand Down Expand Up @@ -64,9 +63,4 @@ public static MaxPrimaryShardSizeCondition fromXContent(XContentParser parser) t
throw new IllegalArgumentException("invalid token: " + parser.currentToken());
}
}

@Override
boolean includedInVersion(Version version) {
return version.onOrAfter(Version.V_7_12_0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.elasticsearch.action.admin.indices.shrink;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.admin.indices.alias.Alias;
Expand Down Expand Up @@ -59,10 +58,8 @@ public ResizeRequest(StreamInput in) throws IOException {
sourceIndex = in.readString();
type = in.readEnum(ResizeType.class);
copySettings = in.readOptionalBoolean();
if (in.getVersion().onOrAfter(Version.V_7_12_0)) {
if (in.readBoolean()) {
maxPrimaryShardSize = new ByteSizeValue(in);
}
if (in.readBoolean()) {
maxPrimaryShardSize = new ByteSizeValue(in);
}
}

Expand Down Expand Up @@ -106,9 +103,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(sourceIndex);
out.writeEnum(type);
out.writeOptionalBoolean(copySettings);
if (out.getVersion().onOrAfter(Version.V_7_12_0)) {
out.writeOptionalWriteable(maxPrimaryShardSize);
}
out.writeOptionalWriteable(maxPrimaryShardSize);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.elasticsearch.xpack.core.ilm;

import org.elasticsearch.Version;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
Expand Down Expand Up @@ -84,7 +83,7 @@ public RolloverAction(StreamInput in) throws IOException {
} else {
maxSize = null;
}
if (in.getVersion().onOrAfter(Version.V_7_13_0) && in.readBoolean()) {
if (in.readBoolean()) {
maxPrimaryShardSize = new ByteSizeValue(in);
} else {
maxPrimaryShardSize = null;
Expand All @@ -96,26 +95,14 @@ public RolloverAction(StreamInput in) throws IOException {
@Override
public void writeTo(StreamOutput out) throws IOException {
boolean hasMaxSize = maxSize != null;
boolean hasMaxPrimaryShardSize = maxPrimaryShardSize != null;
out.writeBoolean(hasMaxSize);
if (hasMaxSize) {
out.writeBoolean(true);
maxSize.writeTo(out);
} else if (hasMaxPrimaryShardSize && out.getVersion().before(Version.V_7_13_0)) {
// In the case that the outgoing node is on a version that doesn't support maxPrimaryShardSize then
// serialize it as maxSize. When the outgoing node receives that node-to-node response there is no validation
// taking place (see constructors_ and otherwise we could end up with a rollover action instance without any conditions.
// If the node is rebooted then it would be unable to read the cluster state and fail starting up.
// (ilm policies are part of cluster state)
out.writeBoolean(true);
maxPrimaryShardSize.writeTo(out);
} else {
out.writeBoolean(false);
}
if (out.getVersion().onOrAfter(Version.V_7_13_0)) {
out.writeBoolean(hasMaxPrimaryShardSize);
if (hasMaxPrimaryShardSize) {
maxPrimaryShardSize.writeTo(out);
}
boolean hasMaxPrimaryShardSize = maxPrimaryShardSize != null;
out.writeBoolean(hasMaxPrimaryShardSize);
if (hasMaxPrimaryShardSize) {
maxPrimaryShardSize.writeTo(out);
}
out.writeOptionalTimeValue(maxAge);
out.writeOptionalVLong(maxDocs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexAbstraction;
import org.elasticsearch.cluster.metadata.IndexMetadata;
Expand Down Expand Up @@ -81,17 +80,12 @@ public ShrinkAction(@Nullable Integer numberOfShards, @Nullable ByteSizeValue ma
}

public ShrinkAction(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_7_12_0)) {
if (in.readBoolean()) {
this.numberOfShards = in.readVInt();
this.maxPrimaryShardSize = null;
} else {
this.numberOfShards = null;
this.maxPrimaryShardSize = new ByteSizeValue(in);
}
} else {
if (in.readBoolean()) {
this.numberOfShards = in.readVInt();
this.maxPrimaryShardSize = null;
} else {
this.numberOfShards = null;
this.maxPrimaryShardSize = new ByteSizeValue(in);
}
}

Expand All @@ -105,16 +99,12 @@ ByteSizeValue getMaxPrimaryShardSize() {

@Override
public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_7_12_0)) {
boolean hasNumberOfShards = numberOfShards != null;
out.writeBoolean(hasNumberOfShards);
if (hasNumberOfShards) {
out.writeVInt(numberOfShards);
} else {
maxPrimaryShardSize.writeTo(out);
}
} else {
boolean hasNumberOfShards = numberOfShards != null;
out.writeBoolean(hasNumberOfShards);
if (hasNumberOfShards) {
out.writeVInt(numberOfShards);
} else {
maxPrimaryShardSize.writeTo(out);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.elasticsearch.xpack.core.ilm;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
Expand All @@ -17,9 +16,6 @@
import java.io.IOException;
import java.util.List;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;

public class RolloverActionTests extends AbstractActionTestCase<RolloverAction> {

@Override
Expand Down Expand Up @@ -122,18 +118,4 @@ public void testToSteps() {
assertEquals(action.getMaxDocs(), firstStep.getMaxDocs());
assertEquals(nextStepKey, fifthStep.getNextStepKey());
}

public void testBwcSerializationWithMaxPrimaryShardSize() throws Exception {
// In case of serializing to node with older version, replace maxPrimaryShardSize with maxSize.
RolloverAction instance = new RolloverAction(null, new ByteSizeValue(1L), null, null);
RolloverAction deserializedInstance = copyInstance(instance, Version.V_7_11_2);
assertThat(deserializedInstance.getMaxPrimaryShardSize(), nullValue());
assertThat(deserializedInstance.getMaxSize(), equalTo(instance.getMaxPrimaryShardSize()));

// But not if maxSize is also specified:
instance = new RolloverAction(new ByteSizeValue(1L), new ByteSizeValue(2L), null, null);
deserializedInstance = copyInstance(instance, Version.V_7_11_2);
assertThat(deserializedInstance.getMaxPrimaryShardSize(), nullValue());
assertThat(deserializedInstance.getMaxSize(), equalTo(instance.getMaxSize()));
}
}

0 comments on commit e85889a

Please sign in to comment.