Skip to content

Commit

Permalink
Rename max_single_primary_size to max_primary_shard_size (#69239) (#6…
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Feb 19, 2021
1 parent 7f7dc9d commit 53bcef0
Show file tree
Hide file tree
Showing 44 changed files with 323 additions and 323 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ tasks.register("verifyVersions") {
* after the backport of the backcompat code is complete.
*/

boolean bwc_tests_enabled = true
String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
boolean bwc_tests_enabled = false
String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/69239" /* place a PR link here when committing bwc changes */
/*
* FIPS 140-2 behavior was fixed in 7.11.0. Before that there is no way to run elasticsearch in a
* JVM that is properly configured to be in fips mode with BCFIPS. For now we need to disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class RolloverAction implements LifecycleAction, ToXContentObject {
public static final String NAME = "rollover";
private static final ParseField MAX_SIZE_FIELD = new ParseField("max_size");
private static final ParseField MAX_SINGLE_PRIMARY_SIZE_FIELD = new ParseField("max_single_primary_size");
private static final ParseField MAX_PRIMARY_SHARD_SIZE_FIELD = new ParseField("max_primary_shard_size");
private static final ParseField MAX_AGE_FIELD = new ParseField("max_age");
private static final ParseField MAX_DOCS_FIELD = new ParseField("max_docs");

Expand All @@ -35,29 +35,29 @@ public class RolloverAction implements LifecycleAction, ToXContentObject {
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_SIZE_FIELD.getPreferredName()),
MAX_SIZE_FIELD, ValueType.VALUE);
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_SINGLE_PRIMARY_SIZE_FIELD.getPreferredName()),
MAX_SINGLE_PRIMARY_SIZE_FIELD, ValueType.VALUE);
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_PRIMARY_SHARD_SIZE_FIELD.getPreferredName()),
MAX_PRIMARY_SHARD_SIZE_FIELD, ValueType.VALUE);
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> TimeValue.parseTimeValue(p.text(), MAX_AGE_FIELD.getPreferredName()),
MAX_AGE_FIELD, ValueType.VALUE);
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), MAX_DOCS_FIELD);
}

private final ByteSizeValue maxSize;
private final ByteSizeValue maxSinglePrimarySize;
private final ByteSizeValue maxPrimaryShardSize;
private final TimeValue maxAge;
private final Long maxDocs;

public static RolloverAction parse(XContentParser parser) {
return PARSER.apply(parser, null);
}

public RolloverAction(ByteSizeValue maxSize, ByteSizeValue maxSinglePrimarySize, TimeValue maxAge, Long maxDocs) {
if (maxSize == null && maxSinglePrimarySize == null && maxAge == null && maxDocs == null) {
public RolloverAction(ByteSizeValue maxSize, ByteSizeValue maxPrimaryShardSize, TimeValue maxAge, Long maxDocs) {
if (maxSize == null && maxPrimaryShardSize == null && maxAge == null && maxDocs == null) {
throw new IllegalArgumentException("At least one rollover condition must be set.");
}
this.maxSize = maxSize;
this.maxSinglePrimarySize = maxSinglePrimarySize;
this.maxPrimaryShardSize = maxPrimaryShardSize;
this.maxAge = maxAge;
this.maxDocs = maxDocs;
}
Expand All @@ -66,8 +66,8 @@ public ByteSizeValue getMaxSize() {
return maxSize;
}

public ByteSizeValue getMaxSinglePrimarySize() {
return maxSinglePrimarySize;
public ByteSizeValue getMaxPrimaryShardSize() {
return maxPrimaryShardSize;
}

public TimeValue getMaxAge() {
Expand All @@ -89,8 +89,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (maxSize != null) {
builder.field(MAX_SIZE_FIELD.getPreferredName(), maxSize.getStringRep());
}
if (maxSinglePrimarySize != null) {
builder.field(MAX_SINGLE_PRIMARY_SIZE_FIELD.getPreferredName(), maxSinglePrimarySize.getStringRep());
if (maxPrimaryShardSize != null) {
builder.field(MAX_PRIMARY_SHARD_SIZE_FIELD.getPreferredName(), maxPrimaryShardSize.getStringRep());
}
if (maxAge != null) {
builder.field(MAX_AGE_FIELD.getPreferredName(), maxAge.getStringRep());
Expand All @@ -104,7 +104,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public int hashCode() {
return Objects.hash(maxSize, maxSinglePrimarySize, maxAge, maxDocs);
return Objects.hash(maxSize, maxPrimaryShardSize, maxAge, maxDocs);
}

@Override
Expand All @@ -117,7 +117,7 @@ public boolean equals(Object obj) {
}
RolloverAction other = (RolloverAction) obj;
return Objects.equals(maxSize, other.maxSize) &&
Objects.equals(maxSinglePrimarySize, other.maxSinglePrimarySize) &&
Objects.equals(maxPrimaryShardSize, other.maxPrimaryShardSize) &&
Objects.equals(maxAge, other.maxAge) &&
Objects.equals(maxDocs, other.maxDocs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,37 @@
public class ShrinkAction implements LifecycleAction, ToXContentObject {
public static final String NAME = "shrink";
private static final ParseField NUMBER_OF_SHARDS_FIELD = new ParseField("number_of_shards");
private static final ParseField MAX_SINGLE_PRIMARY_SIZE = new ParseField("max_single_primary_size");
private static final ParseField MAX_PRIMARY_SHARD_SIZE = new ParseField("max_primary_shard_size");

private static final ConstructingObjectParser<ShrinkAction, Void> PARSER =
new ConstructingObjectParser<>(NAME, true, a -> new ShrinkAction((Integer) a[0], (ByteSizeValue) a[1]));

static {
PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), NUMBER_OF_SHARDS_FIELD);
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_SINGLE_PRIMARY_SIZE.getPreferredName()),
MAX_SINGLE_PRIMARY_SIZE, ObjectParser.ValueType.STRING);
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_PRIMARY_SHARD_SIZE.getPreferredName()),
MAX_PRIMARY_SHARD_SIZE, ObjectParser.ValueType.STRING);
}

private Integer numberOfShards;
private ByteSizeValue maxSinglePrimarySize;
private ByteSizeValue maxPrimaryShardSize;

public static ShrinkAction parse(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

public ShrinkAction(@Nullable Integer numberOfShards, ByteSizeValue maxSinglePrimarySize) {
if (numberOfShards != null && maxSinglePrimarySize != null) {
throw new IllegalArgumentException("Cannot set both [number_of_shards] and [max_single_primary_size]");
public ShrinkAction(@Nullable Integer numberOfShards, ByteSizeValue maxPrimaryShardSize) {
if (numberOfShards != null && maxPrimaryShardSize != null) {
throw new IllegalArgumentException("Cannot set both [number_of_shards] and [max_primary_shard_size]");
}
if (numberOfShards == null && maxSinglePrimarySize == null) {
throw new IllegalArgumentException("Either [number_of_shards] or [max_single_primary_size] must be set");
if (numberOfShards == null && maxPrimaryShardSize == null) {
throw new IllegalArgumentException("Either [number_of_shards] or [max_primary_shard_size] must be set");
}
if (maxSinglePrimarySize != null) {
if (maxSinglePrimarySize.getBytes() <= 0) {
throw new IllegalArgumentException("[max_single_primary_size] must be greater than 0");
if (maxPrimaryShardSize != null) {
if (maxPrimaryShardSize.getBytes() <= 0) {
throw new IllegalArgumentException("[max_primary_shard_size] must be greater than 0");
}
this.maxSinglePrimarySize = maxSinglePrimarySize;
this.maxPrimaryShardSize = maxPrimaryShardSize;
} else {
if (numberOfShards <= 0) {
throw new IllegalArgumentException("[" + NUMBER_OF_SHARDS_FIELD.getPreferredName() + "] must be greater than 0");
Expand All @@ -66,8 +66,8 @@ Integer getNumberOfShards() {
return numberOfShards;
}

ByteSizeValue getMaxSinglePrimarySize() {
return maxSinglePrimarySize;
ByteSizeValue getMaxPrimaryShardSize() {
return maxPrimaryShardSize;
}

@Override
Expand All @@ -81,8 +81,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (numberOfShards != null) {
builder.field(NUMBER_OF_SHARDS_FIELD.getPreferredName(), numberOfShards);
}
if (maxSinglePrimarySize != null) {
builder.field(MAX_SINGLE_PRIMARY_SIZE.getPreferredName(), maxSinglePrimarySize);
if (maxPrimaryShardSize != null) {
builder.field(MAX_PRIMARY_SHARD_SIZE.getPreferredName(), maxPrimaryShardSize);
}
builder.endObject();
return builder;
Expand All @@ -95,12 +95,12 @@ public boolean equals(Object o) {
ShrinkAction that = (ShrinkAction) o;

return Objects.equals(numberOfShards, that.numberOfShards) &&
Objects.equals(maxSinglePrimarySize, that.maxSinglePrimarySize);
Objects.equals(maxPrimaryShardSize, that.maxPrimaryShardSize);
}

@Override
public int hashCode() {
return Objects.hash(numberOfShards, maxSinglePrimarySize);
return Objects.hash(numberOfShards, maxPrimaryShardSize);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ResizeRequest extends TimedRequest implements Validatable, ToXConte
private final String targetIndex;
private Settings settings = Settings.EMPTY;
private Set<Alias> aliases = new HashSet<>();
private ByteSizeValue maxSinglePrimarySize;
private ByteSizeValue maxPrimaryShardSize;

/**
* Creates a new resize request
Expand Down Expand Up @@ -79,17 +79,17 @@ public Set<Alias> getAliases() {
}

/**
* Sets the max single primary shard size of the target index
* Sets the max primary shard size of the target index
*/
public void setMaxSinglePrimarySize(ByteSizeValue maxSinglePrimarySize) {
this.maxSinglePrimarySize = maxSinglePrimarySize;
public void setMaxPrimaryShardSize(ByteSizeValue maxPrimaryShardSize) {
this.maxPrimaryShardSize = maxPrimaryShardSize;
}

/**
* Return the max single primary shard size of the target index
* Return the max primary shard size of the target index
*/
public ByteSizeValue getMaxSinglePrimarySize() {
return maxSinglePrimarySize;
public ByteSizeValue getMaxPrimaryShardSize() {
return maxPrimaryShardSize;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.elasticsearch.action.admin.indices.rollover.Condition;
import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition;
import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition;
import org.elasticsearch.action.admin.indices.rollover.MaxSinglePrimarySizeCondition;
import org.elasticsearch.action.admin.indices.rollover.MaxPrimaryShardSizeCondition;
import org.elasticsearch.action.admin.indices.rollover.MaxSizeCondition;
import org.elasticsearch.client.TimedRequest;
import org.elasticsearch.client.indices.CreateIndexRequest;
Expand Down Expand Up @@ -111,12 +111,12 @@ public RolloverRequest addMaxIndexSizeCondition(ByteSizeValue size) {
/**
* Adds a size-based condition to check if the size of the largest primary shard is at least <code>size</code>.
*/
public RolloverRequest addMaxSinglePrimarySizeCondition(ByteSizeValue size) {
MaxSinglePrimarySizeCondition maxSinglePrimarySizeCondition = new MaxSinglePrimarySizeCondition(size);
if (this.conditions.containsKey(maxSinglePrimarySizeCondition.name())) {
throw new IllegalArgumentException(maxSinglePrimarySizeCondition + " condition is already set");
public RolloverRequest addMaxPrimaryShardSizeCondition(ByteSizeValue size) {
MaxPrimaryShardSizeCondition maxPrimaryShardSizeCondition = new MaxPrimaryShardSizeCondition(size);
if (this.conditions.containsKey(maxPrimaryShardSizeCondition.name())) {
throw new IllegalArgumentException(maxPrimaryShardSizeCondition + " condition is already set");
}
this.conditions.put(maxSinglePrimarySizeCondition.name(), maxSinglePrimarySizeCondition);
this.conditions.put(maxPrimaryShardSizeCondition.name(), maxPrimaryShardSizeCondition);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ public void testRollover() throws IOException {
rolloverRequest.getCreateIndexRequest().mapping(mappings, XContentType.JSON);
rolloverRequest.dryRun(false);
rolloverRequest.addMaxIndexSizeCondition(new ByteSizeValue(1, ByteSizeUnit.MB));
rolloverRequest.addMaxSinglePrimarySizeCondition(new ByteSizeValue(1, ByteSizeUnit.MB));
rolloverRequest.addMaxPrimaryShardSizeCondition(new ByteSizeValue(1, ByteSizeUnit.MB));
RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover,
highLevelClient().indices()::rolloverAsync);
assertTrue(rolloverResponse.isRolledOver());
Expand All @@ -1223,7 +1223,7 @@ public void testRollover() throws IOException {
assertTrue(conditionStatus.get("[max_docs: 1]"));
assertTrue(conditionStatus.get("[max_age: 1ms]"));
assertFalse(conditionStatus.get("[max_size: 1mb]"));
assertFalse(conditionStatus.get("[max_single_primary_size: 1mb]"));
assertFalse(conditionStatus.get("[max_primary_shard_size: 1mb]"));
assertEquals("test", rolloverResponse.getOldIndex());
assertEquals("test_new", rolloverResponse.getNewIndex());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ private void resizeTest(ResizeType resizeType, CheckedFunction<ResizeRequest, Re
resizeRequest.setSettings(Settings.builder().put("index.number_of_shards", 2).build());
}
if (resizeType == ResizeType.SHRINK) {
resizeRequest.setMaxSinglePrimarySize(new ByteSizeValue(randomIntBetween(1, 100)));
resizeRequest.setMaxPrimaryShardSize(new ByteSizeValue(randomIntBetween(1, 100)));
}

Request request = function.apply(resizeRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1704,9 +1704,9 @@ public void testShrinkIndex() throws Exception {
} else {
request.getTargetIndexRequest().settings(Settings.builder()
.putNull("index.routing.allocation.require._name"));
// tag::shrink-index-request-maxSinglePrimarySize
request.setMaxSinglePrimarySize(new ByteSizeValue(50, ByteSizeUnit.GB)); // <1>
// end::shrink-index-request-maxSinglePrimarySize
// tag::shrink-index-request-maxPrimaryShardSize
request.setMaxPrimaryShardSize(new ByteSizeValue(50, ByteSizeUnit.GB)); // <1>
// end::shrink-index-request-maxPrimaryShardSize
}
// tag::shrink-index-request-aliases
request.getTargetIndexRequest().alias(new Alias("target_alias")); // <1>
Expand Down Expand Up @@ -1899,7 +1899,7 @@ public void testRolloverIndex() throws Exception {
request.addMaxIndexAgeCondition(new TimeValue(7, TimeUnit.DAYS)); // <2>
request.addMaxIndexDocsCondition(1000); // <3>
request.addMaxIndexSizeCondition(new ByteSizeValue(5, ByteSizeUnit.GB)); // <4>
request.addMaxSinglePrimarySizeCondition(new ByteSizeValue(2, ByteSizeUnit.GB)); // <5>
request.addMaxPrimaryShardSizeCondition(new ByteSizeValue(2, ByteSizeUnit.GB)); // <5>
// end::rollover-index-request

// tag::rollover-index-request-timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ static RolloverAction randomInstance() {
ByteSizeUnit maxSizeUnit = randomFrom(ByteSizeUnit.values());
ByteSizeValue maxSize = randomBoolean()
? null : new ByteSizeValue(randomNonNegativeLong() / maxSizeUnit.toBytes(1), maxSizeUnit);
ByteSizeUnit maxSinglePrimarySizeUnit = randomFrom(ByteSizeUnit.values());
ByteSizeValue maxSinglePrimarySize = randomBoolean()
? null : new ByteSizeValue(randomNonNegativeLong() / maxSinglePrimarySizeUnit.toBytes(1), maxSinglePrimarySizeUnit);
ByteSizeUnit maxPrimaryShardSizeUnit = randomFrom(ByteSizeUnit.values());
ByteSizeValue maxPrimaryShardSize = randomBoolean()
? null : new ByteSizeValue(randomNonNegativeLong() / maxPrimaryShardSizeUnit.toBytes(1), maxPrimaryShardSizeUnit);
TimeValue maxAge = randomBoolean()
? null : TimeValue.parseTimeValue(randomPositiveTimeValue(), "rollover_action_test");
Long maxDocs = (maxSize == null && maxSinglePrimarySize == null && maxAge == null || randomBoolean())
Long maxDocs = (maxSize == null && maxPrimaryShardSize == null && maxAge == null || randomBoolean())
? randomNonNegativeLong() : null;
return new RolloverAction(maxSize, maxSinglePrimarySize, maxAge, maxDocs);
return new RolloverAction(maxSize, maxPrimaryShardSize, maxAge, maxDocs);
}

public void testNoConditions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public void testNonPositiveShardNumber() {
assertThat(e.getMessage(), equalTo("[number_of_shards] must be greater than 0"));
}

public void testMaxSinglePrimarySize() {
ByteSizeValue maxSinglePrimarySize1 = new ByteSizeValue(10);
Exception e1 = expectThrows(Exception.class, () -> new ShrinkAction(randomIntBetween(1, 100), maxSinglePrimarySize1));
assertThat(e1.getMessage(), equalTo("Cannot set both [number_of_shards] and [max_single_primary_size]"));

ByteSizeValue maxSinglePrimarySize2 = new ByteSizeValue(0);
Exception e2 = expectThrows(Exception.class, () -> new ShrinkAction(null, maxSinglePrimarySize2));
assertThat(e2.getMessage(), equalTo("[max_single_primary_size] must be greater than 0"));
public void testMaxPrimaryShardSize() {
ByteSizeValue maxPrimaryShardSize1 = new ByteSizeValue(10);
Exception e1 = expectThrows(Exception.class, () -> new ShrinkAction(randomIntBetween(1, 100), maxPrimaryShardSize1));
assertThat(e1.getMessage(), equalTo("Cannot set both [number_of_shards] and [max_primary_shard_size]"));

ByteSizeValue maxPrimaryShardSize2 = new ByteSizeValue(0);
Exception e2 = expectThrows(Exception.class, () -> new ShrinkAction(null, maxPrimaryShardSize2));
assertThat(e2.getMessage(), equalTo("[max_primary_shard_size] must be greater than 0"));
}
}

0 comments on commit 53bcef0

Please sign in to comment.