Skip to content

Commit

Permalink
Rename max_single_primary_size to max_primary_shard_size (#69250)
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Feb 19, 2021
1 parent 9108c72 commit 0b3ce96
Show file tree
Hide file tree
Showing 35 changed files with 234 additions and 234 deletions.
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 @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -39,14 +39,14 @@ public void testConstructorAndFieldAssignments() {
MaxAgeCondition maxAgeCondition = new MaxAgeCondition(new TimeValue(10));
MaxDocsCondition maxDocsCondition = new MaxDocsCondition(10000L);
MaxSizeCondition maxSizeCondition = new MaxSizeCondition(new ByteSizeValue(2000));
MaxSinglePrimarySizeCondition maxSinglePrimarySizeCondition = new MaxSinglePrimarySizeCondition(new ByteSizeValue(3000));
MaxPrimaryShardSizeCondition maxPrimaryShardSizeCondition = new MaxPrimaryShardSizeCondition(new ByteSizeValue(3000));
Condition<?>[] expectedConditions = new Condition<?>[]{
maxAgeCondition, maxDocsCondition, maxSizeCondition, maxSinglePrimarySizeCondition
maxAgeCondition, maxDocsCondition, maxSizeCondition, maxPrimaryShardSizeCondition
};
rolloverRequest.addMaxIndexAgeCondition(maxAgeCondition.value());
rolloverRequest.addMaxIndexDocsCondition(maxDocsCondition.value());
rolloverRequest.addMaxIndexSizeCondition(maxSizeCondition.value());
rolloverRequest.addMaxSinglePrimarySizeCondition(maxSinglePrimarySizeCondition.value());
rolloverRequest.addMaxPrimaryShardSizeCondition(maxPrimaryShardSizeCondition.value());
List<Condition<?>> requestConditions = new ArrayList<>(rolloverRequest.getConditions().values());
assertThat(requestConditions, containsInAnyOrder(expectedConditions));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -39,7 +39,7 @@ public class RolloverResponseTests extends ESTestCase {
conditionSuppliers.add(() -> new MaxAgeCondition(new TimeValue(randomNonNegativeLong())));
conditionSuppliers.add(() -> new MaxDocsCondition(randomNonNegativeLong()));
conditionSuppliers.add(() -> new MaxSizeCondition(new ByteSizeValue(randomNonNegativeLong())));
conditionSuppliers.add(() -> new MaxSinglePrimarySizeCondition(new ByteSizeValue(randomNonNegativeLong())));
conditionSuppliers.add(() -> new MaxPrimaryShardSizeCondition(new ByteSizeValue(randomNonNegativeLong())));
}

public void testFromXContent() throws IOException {
Expand Down
4 changes: 2 additions & 2 deletions docs/java-rest/high-level/indices/shrink_index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ include-tagged::{doc-tests-file}[{api}-request-settings]

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-maxSinglePrimarySize]
include-tagged::{doc-tests-file}[{api}-request-maxPrimaryShardSize]
--------------------------------------------------
<1> The max single primary shard size of the target index
<1> The max primary shard size of the target index

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions docs/reference/ilm/actions/ilm-shrink.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ managed indices.
(Optional, integer)
Number of shards to shrink to.
Must be a factor of the number of shards in the source index. This parameter conflicts with
`max_single_primary_size`, only one of them may be set.
`max_primary_shard_size`, only one of them may be set.

`max_single_primary_size`::
`max_primary_shard_size`::
(Optional, <<byte-units, byte units>>)
The max single primary shard size for the target index. Used to find the optimum number of shards for the target index.
The max primary shard size for the target index. Used to find the optimum number of shards for the target index.
When this parameter is set, each shard's storage in the target index will not be greater than the parameter.
The shards count of the target index will still be a factor of the source index's shards count, but if the parameter
is less than the single shard size in the source index, the shards count for the target index will be equal to the source index's shards count.
Expand Down Expand Up @@ -84,7 +84,7 @@ PUT _ilm/policy/my_policy

[[ilm-shrink-size-ex]]
===== Calculate the number of shards of the new shrunken index based on the storage of the
source index and the `max_single_primary_size` parameter
source index and the `max_primary_shard_size` parameter

[source,console]
--------------------------------------------------
Expand All @@ -95,7 +95,7 @@ PUT _ilm/policy/my_policy
"warm": {
"actions": {
"shrink" : {
"max_single_primary_size": "50gb"
"max_primary_shard_size": "50gb"
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions docs/reference/indices/rollover-index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ POST /alias1/_rollover/my-index-000002
"max_age": "7d",
"max_docs": 1000,
"max_size": "5gb",
"max_single_primary_size": "2gb"
"max_primary_shard_size": "2gb"
}
}
----
Expand Down Expand Up @@ -167,7 +167,7 @@ Replicas are not counted toward the maximum index size.
TIP: To see the current index size, use the <<cat-indices, _cat indices>> API.
The `pri.store.size` value shows the combined size of all primary shards.

`max_single_primary_size`::
`max_primary_shard_size`::
(Optional, <<byte-units, byte units>>)
Maximum primary shard size.
This is the maximum size of the primary shards in the index. As with `max_size`,
Expand Down Expand Up @@ -206,7 +206,7 @@ POST /logs_write/_rollover <2>
"max_age": "7d",
"max_docs": 1000,
"max_size": "5gb",
"max_single_primary_size": "2gb"
"max_primary_shard_size": "2gb"
}
}
--------------------------------------------------
Expand All @@ -232,7 +232,7 @@ The API returns the following response:
"[max_age: 7d]": false,
"[max_docs: 1000]": true,
"[max_size: 5gb]": false,
"[max_single_primary_size: 2gb]": false
"[max_primary_shard_size: 2gb]": false
}
}
--------------------------------------------------
Expand Down Expand Up @@ -266,7 +266,7 @@ POST /my-data-stream/_rollover <2>
"max_age": "7d",
"max_docs": 1000,
"max_size": "5gb",
"max_single_primary_size": "2gb"
"max_primary_shard_size": "2gb"
}
}
--------------------------------------------------
Expand Down Expand Up @@ -300,7 +300,7 @@ The API returns the following response:
"[max_age: 7d]": false,
"[max_docs: 1000]": true,
"[max_size: 5gb]": false,
"[max_single_primary_size: 2gb]": false
"[max_primary_shard_size: 2gb]": false
}
}
--------------------------------------------------
Expand Down Expand Up @@ -348,7 +348,7 @@ POST /logs_write/_rollover
"max_age": "7d",
"max_docs": 1000,
"max_size": "5gb",
"max_single_primary_size": "2gb"
"max_primary_shard_size": "2gb"
},
"settings": {
"index.number_of_shards": 2
Expand Down Expand Up @@ -376,7 +376,7 @@ POST /my_alias/_rollover/my_new_index_name
"max_age": "7d",
"max_docs": 1000,
"max_size": "5gb",
"max_single_primary_size": "2gb"
"max_primary_shard_size": "2gb"
}
}
--------------------------------------------------
Expand Down Expand Up @@ -475,7 +475,7 @@ POST /logs_write/_rollover?dry_run
"max_age": "7d",
"max_docs": 1000,
"max_size": "5gb",
"max_single_primary_size": "2gb"
"max_primary_shard_size": "2gb"
}
}
--------------------------------------------------
Expand Down

0 comments on commit 0b3ce96

Please sign in to comment.