From 67ec3f013eca8f5d9f12847d1929f0bca38f7562 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 27 Jul 2021 18:10:57 -0500 Subject: [PATCH 1/9] Adding total_shards_per_node to the AllocateAction --- .../xpack/core/ilm/AllocateAction.java | 29 +++++++++++++++---- .../xpack/core/ilm/AllocateActionTests.java | 10 ++++--- .../core/ilm/PhaseCacheManagementTests.java | 2 +- .../ilm/TimeseriesLifecycleTypeTests.java | 7 +++-- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java index 171c92662fed7..6548f707f80df 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java @@ -6,6 +6,7 @@ */ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.Version; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.xcontent.ParseField; @@ -29,22 +30,26 @@ public class AllocateAction implements LifecycleAction { public static final String NAME = "allocate"; public static final ParseField NUMBER_OF_REPLICAS_FIELD = new ParseField("number_of_replicas"); + public static final ParseField TOTAL_SHARDS_PER_NODE_FIELD = new ParseField("total_shards_per_node"); public static final ParseField INCLUDE_FIELD = new ParseField("include"); public static final ParseField EXCLUDE_FIELD = new ParseField("exclude"); public static final ParseField REQUIRE_FIELD = new ParseField("require"); @SuppressWarnings("unchecked") private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, - a -> new AllocateAction((Integer) a[0], (Map) a[1], (Map) a[2], (Map) a[3])); + a -> new AllocateAction((Integer) a[0], (Integer) a[1], (Map) a[2], (Map) a[3], + (Map) a[4])); static { PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), NUMBER_OF_REPLICAS_FIELD); + PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), TOTAL_SHARDS_PER_NODE_FIELD); PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.mapStrings(), INCLUDE_FIELD); PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.mapStrings(), EXCLUDE_FIELD); PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.mapStrings(), REQUIRE_FIELD); } private final Integer numberOfReplicas; + private final Integer totalShardsPerNode; private final Map include; private final Map exclude; private final Map require; @@ -53,7 +58,8 @@ public static AllocateAction parse(XContentParser parser) { return PARSER.apply(parser, null); } - public AllocateAction(Integer numberOfReplicas, Map include, Map exclude, Map require) { + public AllocateAction(Integer numberOfReplicas, Integer totalShardsPerNode, Map include, Map exclude, + Map require) { if (include == null) { this.include = Collections.emptyMap(); } else { @@ -78,18 +84,24 @@ public AllocateAction(Integer numberOfReplicas, Map include, Map throw new IllegalArgumentException("[" + NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0"); } this.numberOfReplicas = numberOfReplicas; + this.totalShardsPerNode = totalShardsPerNode; } @SuppressWarnings("unchecked") public AllocateAction(StreamInput in) throws IOException { - this(in.readOptionalVInt(), (Map) in.readGenericValue(), (Map) in.readGenericValue(), - (Map) in.readGenericValue()); + this(in.readOptionalVInt(), in.getVersion().onOrAfter(Version.V_8_0_0) ? in.readOptionalVInt() : null, + (Map) in.readGenericValue(), (Map) in.readGenericValue(), + (Map) in.readGenericValue()); } public Integer getNumberOfReplicas() { return numberOfReplicas; } + public Integer getTotalShardsPerNode() { + return totalShardsPerNode; + } + public Map getInclude() { return include; } @@ -105,6 +117,9 @@ public Map getRequire() { @Override public void writeTo(StreamOutput out) throws IOException { out.writeOptionalVInt(numberOfReplicas); + if (out.getVersion().onOrAfter(Version.V_8_0_0)) { + out.writeOptionalVInt(totalShardsPerNode); + } out.writeGenericValue(include); out.writeGenericValue(exclude); out.writeGenericValue(require); @@ -121,6 +136,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (numberOfReplicas != null) { builder.field(NUMBER_OF_REPLICAS_FIELD.getPreferredName(), numberOfReplicas); } + if (totalShardsPerNode != null) { + builder.field(TOTAL_SHARDS_PER_NODE_FIELD.getPreferredName(), totalShardsPerNode); + } builder.field(INCLUDE_FIELD.getPreferredName(), include); builder.field(EXCLUDE_FIELD.getPreferredName(), exclude); builder.field(REQUIRE_FIELD.getPreferredName(), require); @@ -152,7 +170,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { @Override public int hashCode() { - return Objects.hash(numberOfReplicas, include, exclude, require); + return Objects.hash(numberOfReplicas, totalShardsPerNode, include, exclude, require); } @Override @@ -165,6 +183,7 @@ public boolean equals(Object obj) { } AllocateAction other = (AllocateAction) obj; return Objects.equals(numberOfReplicas, other.numberOfReplicas) && + Objects.equals(totalShardsPerNode, other.totalShardsPerNode) && Objects.equals(include, other.include) && Objects.equals(exclude, other.exclude) && Objects.equals(require, other.require); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java index 2a425a34b3c58..8a69a742c20b2 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java @@ -55,7 +55,8 @@ static AllocateAction randomInstance() { requires = randomBoolean() ? null : Collections.emptyMap(); } Integer numberOfReplicas = randomBoolean() ? null : randomIntBetween(0, 10); - return new AllocateAction(numberOfReplicas, includes, excludes, requires); + Integer totalShardsPerNode = randomBoolean() ? null : randomIntBetween(0, 300); + return new AllocateAction(numberOfReplicas, totalShardsPerNode, includes, excludes, requires); } @@ -70,6 +71,7 @@ protected AllocateAction mutateInstance(AllocateAction instance) { Map exclude = instance.getExclude(); Map require = instance.getRequire(); Integer numberOfReplicas = instance.getNumberOfReplicas(); + Integer totalShardsPerNode = instance.getTotalShardsPerNode(); switch (randomIntBetween(0, 3)) { case 0: include = new HashMap<>(include); @@ -89,7 +91,7 @@ protected AllocateAction mutateInstance(AllocateAction instance) { default: throw new AssertionError("Illegal randomisation branch"); } - return new AllocateAction(numberOfReplicas, include, exclude, require); + return new AllocateAction(numberOfReplicas, totalShardsPerNode, include, exclude, require); } public void testAllMapsNullOrEmpty() { @@ -97,7 +99,7 @@ public void testAllMapsNullOrEmpty() { Map exclude = randomBoolean() ? null : Collections.emptyMap(); Map require = randomBoolean() ? null : Collections.emptyMap(); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> new AllocateAction(null, include, exclude, require)); + () -> new AllocateAction(null, null, include, exclude, require)); assertEquals("At least one of " + AllocateAction.INCLUDE_FIELD.getPreferredName() + ", " + AllocateAction.EXCLUDE_FIELD.getPreferredName() + " or " + AllocateAction.REQUIRE_FIELD.getPreferredName() + "must contain attributes for action " + AllocateAction.NAME, exception.getMessage()); @@ -108,7 +110,7 @@ public void testInvalidNumberOfReplicas() { Map exclude = randomBoolean() ? null : Collections.emptyMap(); Map require = randomBoolean() ? null : Collections.emptyMap(); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> new AllocateAction(randomIntBetween(-1000, -1), include, exclude, require)); + () -> new AllocateAction(randomIntBetween(-1000, -1), randomIntBetween(0, 300), include, exclude, require)); assertEquals("[" + AllocateAction.NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0", exception.getMessage()); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java index d1c7837974c73..e6a86fbd8d62d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java @@ -236,7 +236,7 @@ public void testReadStepKeys() { Map actions = new HashMap<>(); actions.put("forcemerge", new ForceMergeAction(5, null)); - actions.put("allocate", new AllocateAction(1, null, null, null)); + actions.put("allocate", new AllocateAction(1, 20, null, null, null)); PhaseExecutionInfo pei = new PhaseExecutionInfo("policy", new Phase("wonky", TimeValue.ZERO, actions), 1, 1); String phaseDef = Strings.toString(pei); logger.info("--> phaseDef: {}", phaseDef); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java index ad5ab8d75da86..174e2681bd795 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java @@ -55,7 +55,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase { private static final AllocateAction TEST_ALLOCATE_ACTION = - new AllocateAction(2, Collections.singletonMap("node", "node1"),null, null); + new AllocateAction(2, 20, Collections.singletonMap("node", "node1"),null, null); private static final DeleteAction TEST_DELETE_ACTION = new DeleteAction(); private static final WaitForSnapshotAction TEST_WAIT_FOR_SNAPSHOT_ACTION = new WaitForSnapshotAction("policy"); private static final ForceMergeAction TEST_FORCE_MERGE_ACTION = new ForceMergeAction(1, null); @@ -634,7 +634,7 @@ public void testShouldMigrateDataToTiers() { { // the allocate action only specifies the number of replicas Map actions = new HashMap<>(); - actions.put(TEST_ALLOCATE_ACTION.getWriteableName(), new AllocateAction(2, null, null, null)); + actions.put(TEST_ALLOCATE_ACTION.getWriteableName(), new AllocateAction(2, 20, null, null, null)); Phase phase = new Phase(WARM_PHASE, TimeValue.ZERO, actions); assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(true)); } @@ -862,7 +862,8 @@ private ConcurrentMap convertActionNamesToActions(Strin return Arrays.asList(availableActionNames).stream().map(n -> { switch (n) { case AllocateAction.NAME: - return new AllocateAction(null, Collections.singletonMap("foo", "bar"), Collections.emptyMap(), Collections.emptyMap()); + return new AllocateAction(null, null, Collections.singletonMap("foo", "bar"), Collections.emptyMap(), + Collections.emptyMap()); case DeleteAction.NAME: return new DeleteAction(); case ForceMergeAction.NAME: From bc4142d7ad6392843220ff9f880e08ea9e7ecba6 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 3 Aug 2021 15:50:32 -0500 Subject: [PATCH 2/9] Setting config --- .../java/org/elasticsearch/xpack/core/ilm/AllocateAction.java | 4 ++++ .../metadata/MetadataMigrateToDataTiersRoutingService.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java index 6548f707f80df..79acf8de68e14 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java @@ -9,6 +9,7 @@ import org.elasticsearch.Version; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -163,6 +164,9 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { include.forEach((key, value) -> newSettings.put(IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + key, value)); exclude.forEach((key, value) -> newSettings.put(IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + key, value)); require.forEach((key, value) -> newSettings.put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + key, value)); + if (totalShardsPerNode != null) { + newSettings.put(ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey(), totalShardsPerNode); + } UpdateSettingsStep allocateStep = new UpdateSettingsStep(allocateKey, allocationRoutedKey, client, newSettings.build()); AllocationRoutedStep routedCheckStep = new AllocationRoutedStep(allocationRoutedKey, nextStepKey); return Arrays.asList(allocateStep, routedCheckStep); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java index 980c4db279840..0e9df6c08c20e 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java @@ -323,7 +323,8 @@ private static LifecyclePolicy migrateSingleILMPolicy(String nodeAttrName, Lifec if (allocateAction.getNumberOfReplicas() != null) { // keep the number of replicas configuration AllocateAction updatedAllocateAction = - new AllocateAction(allocateAction.getNumberOfReplicas(), null, null, null); + new AllocateAction(allocateAction.getNumberOfReplicas(), allocateAction.getTotalShardsPerNode(), + null, null, null); actionMap.put(allocateAction.getWriteableName(), updatedAllocateAction); logger.debug("ILM policy [{}], phase [{}]: updated the allocate action to [{}]", lifecyclePolicy.getName(), phase.getName(), allocateAction); From 1858059a4b4dd4c372e1a55383ed011f0084b2df Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Wed, 4 Aug 2021 16:18:41 -0500 Subject: [PATCH 3/9] adding a unit test --- .../xpack/core/ilm/AllocateActionTests.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java index 8a69a742c20b2..f4f88ba11e5a6 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Map; +import static org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING; import static org.hamcrest.Matchers.equalTo; public class AllocateActionTests extends AbstractActionTestCase { @@ -154,4 +155,22 @@ public void testToSteps() { assertEquals(nextStepKey, secondStep.getNextStepKey()); } + public void testTotalNumberOfShards() throws Exception { + Integer totalShardsPerNode = randomIntBetween(1, 1000); + Integer numberOfReplicas = randomIntBetween(0, 4); + AllocateAction action = new AllocateAction(numberOfReplicas, totalShardsPerNode, null, null, null); + String phase = randomAlphaOfLengthBetween(1, 10); + StepKey nextStepKey = new StepKey(randomAlphaOfLengthBetween(1, 10), randomAlphaOfLengthBetween(1, 10), + randomAlphaOfLengthBetween(1, 10)); + List steps = action.toSteps(null, phase, nextStepKey); + UpdateSettingsStep firstStep = (UpdateSettingsStep) steps.get(0); + assertEquals(totalShardsPerNode, firstStep.getSettings().getAsInt(INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey(), null)); + + totalShardsPerNode = null; + action = new AllocateAction(numberOfReplicas, totalShardsPerNode, null, null, null); + steps = action.toSteps(null, phase, nextStepKey); + firstStep = (UpdateSettingsStep) steps.get(0); + assertEquals(null, firstStep.getSettings().get(INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey())); + } + } From 9bdfd220692603ec9345b701a6c89c416a1f5567 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Wed, 4 Aug 2021 16:54:35 -0500 Subject: [PATCH 4/9] Added a validation check --- .../org/elasticsearch/xpack/core/ilm/AllocateAction.java | 3 +++ .../xpack/core/ilm/AllocateActionTests.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java index 79acf8de68e14..b0dfe8dc4851c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java @@ -85,6 +85,9 @@ public AllocateAction(Integer numberOfReplicas, Integer totalShardsPerNode, Map< throw new IllegalArgumentException("[" + NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0"); } this.numberOfReplicas = numberOfReplicas; + if (totalShardsPerNode != null && totalShardsPerNode < 0) { + throw new IllegalArgumentException("[" + TOTAL_SHARDS_PER_NODE_FIELD.getPreferredName() + "] must be > 0"); + } this.totalShardsPerNode = totalShardsPerNode; } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java index f4f88ba11e5a6..6a85af2399ddf 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java @@ -115,6 +115,15 @@ public void testInvalidNumberOfReplicas() { assertEquals("[" + AllocateAction.NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0", exception.getMessage()); } + public void testInvalidNumberOfTotalShards() { + Map include = randomAllocationRoutingMap(1, 5); + Map exclude = randomBoolean() ? null : Collections.emptyMap(); + Map require = randomBoolean() ? null : Collections.emptyMap(); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> new AllocateAction(randomIntBetween(0, 300), randomIntBetween(-1000, 0), include, exclude, require)); + assertEquals("[" + AllocateAction.TOTAL_SHARDS_PER_NODE_FIELD.getPreferredName() + "] must be > 0", exception.getMessage()); + } + public static Map randomAllocationRoutingMap(int minEntries, int maxEntries) { Map map = new HashMap<>(); int numIncludes = randomIntBetween(minEntries, maxEntries); From c64963351d9d96609b4ea3c7f24ff15d183070cb Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Wed, 4 Aug 2021 17:30:12 -0500 Subject: [PATCH 5/9] Adding documentation --- .../ilm/actions/ilm-allocate.asciidoc | 11 +++++++++-- .../xpack/core/ilm/AllocateAction.java | 3 --- .../xpack/core/ilm/AllocateActionTests.java | 18 +++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/reference/ilm/actions/ilm-allocate.asciidoc b/docs/reference/ilm/actions/ilm-allocate.asciidoc index fbb9a7e075786..91904e5f74938 100644 --- a/docs/reference/ilm/actions/ilm-allocate.asciidoc +++ b/docs/reference/ilm/actions/ilm-allocate.asciidoc @@ -32,6 +32,11 @@ see <>. (Optional, integer) Number of replicas to assign to the index. +`total_shards_per_node`:: +(Optional, integer) +The maximum number of shards for the index on a single {es} node. Negative values +are interpreted as unlimited. See <>. + `include`:: (Optional, object) Assigns an index to nodes that have at least _one_ of the specified custom attributes. @@ -48,7 +53,8 @@ Assigns an index to nodes that have _all_ of the specified custom attributes. ==== Example The allocate action in the following policy changes the index's number of replicas to `2`. -The index allocation rules are not changed. +No more than 200 shards for the index will be placed on any single node. Otherwise the index +allocation rules are not changed. [source,console] -------------------------------------------------- @@ -59,7 +65,8 @@ PUT _ilm/policy/my_policy "warm": { "actions": { "allocate" : { - "number_of_replicas" : 2 + "number_of_replicas" : 2, + "total_shards_per_node" : 200 } } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java index b0dfe8dc4851c..79acf8de68e14 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java @@ -85,9 +85,6 @@ public AllocateAction(Integer numberOfReplicas, Integer totalShardsPerNode, Map< throw new IllegalArgumentException("[" + NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0"); } this.numberOfReplicas = numberOfReplicas; - if (totalShardsPerNode != null && totalShardsPerNode < 0) { - throw new IllegalArgumentException("[" + TOTAL_SHARDS_PER_NODE_FIELD.getPreferredName() + "] must be > 0"); - } this.totalShardsPerNode = totalShardsPerNode; } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java index 6a85af2399ddf..20968cd5f5bf3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java @@ -8,6 +8,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; @@ -56,7 +57,7 @@ static AllocateAction randomInstance() { requires = randomBoolean() ? null : Collections.emptyMap(); } Integer numberOfReplicas = randomBoolean() ? null : randomIntBetween(0, 10); - Integer totalShardsPerNode = randomBoolean() ? null : randomIntBetween(0, 300); + Integer totalShardsPerNode = randomBoolean() ? null : randomIntBetween(-300, 300); return new AllocateAction(numberOfReplicas, totalShardsPerNode, includes, excludes, requires); } @@ -115,15 +116,6 @@ public void testInvalidNumberOfReplicas() { assertEquals("[" + AllocateAction.NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0", exception.getMessage()); } - public void testInvalidNumberOfTotalShards() { - Map include = randomAllocationRoutingMap(1, 5); - Map exclude = randomBoolean() ? null : Collections.emptyMap(); - Map require = randomBoolean() ? null : Collections.emptyMap(); - IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> new AllocateAction(randomIntBetween(0, 300), randomIntBetween(-1000, 0), include, exclude, require)); - assertEquals("[" + AllocateAction.TOTAL_SHARDS_PER_NODE_FIELD.getPreferredName() + "] must be > 0", exception.getMessage()); - } - public static Map randomAllocationRoutingMap(int minEntries, int maxEntries) { Map map = new HashMap<>(); int numIncludes = randomIntBetween(minEntries, maxEntries); @@ -158,6 +150,10 @@ public void testToSteps() { (key, value) -> expectedSettings.put(IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + key, value)); action.getRequire().forEach( (key, value) -> expectedSettings.put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + key, value)); + if (action.getTotalShardsPerNode() != null) { + expectedSettings.put(ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey(), action.getTotalShardsPerNode()); + } + assertThat(firstStep.getSettings(), equalTo(expectedSettings.build())); AllocationRoutedStep secondStep = (AllocationRoutedStep) steps.get(1); assertEquals(expectedSecondStepKey, secondStep.getKey()); @@ -165,7 +161,7 @@ public void testToSteps() { } public void testTotalNumberOfShards() throws Exception { - Integer totalShardsPerNode = randomIntBetween(1, 1000); + Integer totalShardsPerNode = randomIntBetween(-1000, 1000); Integer numberOfReplicas = randomIntBetween(0, 4); AllocateAction action = new AllocateAction(numberOfReplicas, totalShardsPerNode, null, null, null); String phase = randomAlphaOfLengthBetween(1, 10); From 586d6e3a2270da1e83b02a260341bd72429d389e Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Wed, 4 Aug 2021 17:53:56 -0500 Subject: [PATCH 6/9] Fixing a compile error --- ...MigrateToDataTiersRoutingServiceTests.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java index 48066e09c3346..a738c373b0a1c 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java @@ -90,8 +90,8 @@ public void setupTestEntities() { public void testMigrateIlmPolicyForIndexWithoutILMMetadata() { ShrinkAction shrinkAction = new ShrinkAction(2, null); - AllocateAction warmAllocateAction = new AllocateAction(null, Map.of("data", "warm"), null, Map.of("rack", "rack1")); - AllocateAction coldAllocateAction = new AllocateAction(0, null, null, Map.of("data", "cold")); + AllocateAction warmAllocateAction = new AllocateAction(null, null, Map.of("data", "warm"), null, Map.of("rack", "rack1")); + AllocateAction coldAllocateAction = new AllocateAction(0, null, null, null, Map.of("data", "cold")); SetPriorityAction warmSetPriority = new SetPriorityAction(100); LifecyclePolicyMetadata policyMetadata = getWarmColdPolicyMeta(warmSetPriority, shrinkAction, warmAllocateAction, coldAllocateAction); @@ -125,7 +125,7 @@ public void testMigrateIlmPolicyForIndexWithoutILMMetadata() { public void testMigrateIlmPolicyFOrPhaseWithDeactivatedMigrateAction() { ShrinkAction shrinkAction = new ShrinkAction(2, null); - AllocateAction warmAllocateAction = new AllocateAction(null, Map.of("data", "warm"), null, Map.of("rack", "rack1")); + AllocateAction warmAllocateAction = new AllocateAction(null, null, Map.of("data", "warm"), null, Map.of("rack", "rack1")); MigrateAction deactivatedMigrateAction = new MigrateAction(false); LifecyclePolicy policy = new LifecyclePolicy(lifecycleName, @@ -160,8 +160,8 @@ public void testMigrateIlmPolicyFOrPhaseWithDeactivatedMigrateAction() { @SuppressWarnings("unchecked") public void testMigrateIlmPolicyRefreshesCachedPhase() { ShrinkAction shrinkAction = new ShrinkAction(2, null); - AllocateAction warmAllocateAction = new AllocateAction(null, Map.of("data", "warm"), null, Map.of("rack", "rack1")); - AllocateAction coldAllocateAction = new AllocateAction(0, null, null, Map.of("data", "cold")); + AllocateAction warmAllocateAction = new AllocateAction(null, null, Map.of("data", "warm"), null, Map.of("rack", "rack1")); + AllocateAction coldAllocateAction = new AllocateAction(0, null, null, null, Map.of("data", "cold")); SetPriorityAction warmSetPriority = new SetPriorityAction(100); LifecyclePolicyMetadata policyMetadata = getWarmColdPolicyMeta(warmSetPriority, shrinkAction, warmAllocateAction, coldAllocateAction); @@ -337,11 +337,12 @@ private Settings.Builder getBaseIndexSettings() { } public void testAllocateActionDefinesRoutingRules() { - assertThat(allocateActionDefinesRoutingRules("data", new AllocateAction(null, Map.of("data", "cold"), null, null)), is(true)); - assertThat(allocateActionDefinesRoutingRules("data", new AllocateAction(null, null, Map.of("data", "cold"), null)), is(true)); - assertThat(allocateActionDefinesRoutingRules("data", new AllocateAction(null, Map.of("another_attribute", "rack1"), null, + assertThat(allocateActionDefinesRoutingRules("data", new AllocateAction(null, null, Map.of("data", "cold"), null, null)), is(true)); + assertThat(allocateActionDefinesRoutingRules("data", new AllocateAction(null, null, null, Map.of("data", "cold"), null)), is(true)); + assertThat(allocateActionDefinesRoutingRules("data", new AllocateAction(null, null, Map.of("another_attribute", "rack1"), null, Map.of("data", "cold"))), is(true)); - assertThat(allocateActionDefinesRoutingRules("data", new AllocateAction(null, null, null, Map.of("another_attribute", "cold"))), + assertThat(allocateActionDefinesRoutingRules("data", new AllocateAction(null, null, null, null, Map.of("another_attribute", + "cold"))), is(false)); assertThat(allocateActionDefinesRoutingRules("data", null), is(false)); } @@ -547,8 +548,9 @@ public void testRequireAttributeIndexSettingTakesPriorityOverInclude() { } public void testMigrateToDataTiersRouting() { - AllocateAction allocateActionWithDataAttribute = new AllocateAction(null, Map.of("data", "warm"), null, Map.of("rack", "rack1")); - AllocateAction allocateActionWithOtherAttribute = new AllocateAction(0, null, null, Map.of("other", "cold")); + AllocateAction allocateActionWithDataAttribute = new AllocateAction(null, null, Map.of("data", "warm"), null, Map.of("rack", + "rack1")); + AllocateAction allocateActionWithOtherAttribute = new AllocateAction(0, null, null, null, Map.of("other", "cold")); LifecyclePolicy policyToMigrate = new LifecyclePolicy(lifecycleName, Map.of("warm", From 3394718d754de1bbdf2be15860ad8d33d0fb5e60 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 5 Aug 2021 08:34:05 -0500 Subject: [PATCH 7/9] more compilation fixes --- .../org/elasticsearch/xpack/MigrateToDataTiersIT.java | 8 ++++---- .../org/elasticsearch/xpack/TimeSeriesRestDriver.java | 6 ++++-- .../elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java | 4 ++-- .../xpack/ilm/TimeSeriesLifecycleActionsIT.java | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java index 9f934097959b2..88697dde12b7c 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java @@ -100,11 +100,11 @@ public void testMigrateToDataTiersAction() throws Exception { Map warmActions = new HashMap<>(); warmActions.put(SetPriorityAction.NAME, new SetPriorityAction(50)); warmActions.put(ForceMergeAction.NAME, new ForceMergeAction(1, null)); - warmActions.put(AllocateAction.NAME, new AllocateAction(null, singletonMap("data", "warm"), null, null)); + warmActions.put(AllocateAction.NAME, new AllocateAction(null, null, singletonMap("data", "warm"), null, null)); warmActions.put(ShrinkAction.NAME, new ShrinkAction(1, null)); Map coldActions = new HashMap<>(); coldActions.put(SetPriorityAction.NAME, new SetPriorityAction(0)); - coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, singletonMap("data", "cold"))); + coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, null, singletonMap("data", "cold"))); createPolicy(client(), policy, new Phase("hot", TimeValue.ZERO, hotActions), @@ -221,11 +221,11 @@ public void testMigrationDryRun() throws Exception { Map warmActions = new HashMap<>(); warmActions.put(SetPriorityAction.NAME, new SetPriorityAction(50)); warmActions.put(ForceMergeAction.NAME, new ForceMergeAction(1, null)); - warmActions.put(AllocateAction.NAME, new AllocateAction(null, singletonMap("data", "warm"), null, null)); + warmActions.put(AllocateAction.NAME, new AllocateAction(null, null, singletonMap("data", "warm"), null, null)); warmActions.put(ShrinkAction.NAME, new ShrinkAction(1, null)); Map coldActions = new HashMap<>(); coldActions.put(SetPriorityAction.NAME, new SetPriorityAction(0)); - coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, singletonMap("data", "cold"))); + coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, null, null, singletonMap("data", "cold"))); createPolicy(client(), policy, new Phase("hot", TimeValue.ZERO, hotActions), diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java index d00e52a13f3d8..be94adcb95ea3 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java @@ -176,12 +176,14 @@ public static void createFullPolicy(RestClient client, String policyName, TimeVa Map warmActions = new HashMap<>(); warmActions.put(SetPriorityAction.NAME, new SetPriorityAction(50)); warmActions.put(ForceMergeAction.NAME, new ForceMergeAction(1, null)); - warmActions.put(AllocateAction.NAME, new AllocateAction(1, singletonMap("_name", "javaRestTest-0,javaRestTest-1,javaRestTest-2," + + warmActions.put(AllocateAction.NAME, new AllocateAction(1, null, singletonMap("_name", "javaRestTest-0,javaRestTest-1," + + "javaRestTest-2," + "javaRestTest-3"), null, null)); warmActions.put(ShrinkAction.NAME, new ShrinkAction(1, null)); Map coldActions = new HashMap<>(); coldActions.put(SetPriorityAction.NAME, new SetPriorityAction(0)); - coldActions.put(AllocateAction.NAME, new AllocateAction(0, singletonMap("_name", "javaRestTest-0,javaRestTest-1,javaRestTest-2," + + coldActions.put(AllocateAction.NAME, new AllocateAction(0, null, singletonMap("_name", "javaRestTest-0,javaRestTest-1," + + "javaRestTest-2," + "javaRestTest-3"), null, null)); Map phases = new HashMap<>(); phases.put("hot", new Phase("hot", hotTime, hotActions)); diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java index 1cc3c9d6419b9..e488eb79a39b5 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java @@ -64,13 +64,13 @@ public void testChangePolicyForIndex() throws Exception { Map phases1 = new HashMap<>(); phases1.put("hot", new Phase("hot", TimeValue.ZERO, singletonMap(RolloverAction.NAME, new RolloverAction(null, null, null, 1L)))); phases1.put("warm", new Phase("warm", TimeValue.ZERO, - singletonMap(AllocateAction.NAME, new AllocateAction(1, singletonMap("_name", "foobarbaz"), null, null)))); + singletonMap(AllocateAction.NAME, new AllocateAction(1, null, singletonMap("_name", "foobarbaz"), null, null)))); LifecyclePolicy lifecyclePolicy1 = new LifecyclePolicy("policy_1", phases1); Map phases2 = new HashMap<>(); phases2.put("hot", new Phase("hot", TimeValue.ZERO, singletonMap(RolloverAction.NAME, new RolloverAction(null, null, null, 1000L)))); phases2.put("warm", new Phase("warm", TimeValue.ZERO, singletonMap(AllocateAction.NAME, - new AllocateAction(1, singletonMap("_name", "javaRestTest-0,javaRestTest-1,javaRestTest-2,javaRestTest-3"), + new AllocateAction(1, null, singletonMap("_name", "javaRestTest-0,javaRestTest-1,javaRestTest-2,javaRestTest-3"), null, null)))); LifecyclePolicy lifecyclePolicy2 = new LifecyclePolicy("policy_2", phases2); // PUT policy_1 and policy_2 diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java index d3f23987b0b64..8db7dc0149a55 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java @@ -168,7 +168,7 @@ public void testAllocateOnlyAllocation() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)); String allocateNodeName = "javaRestTest-0,javaRestTest-1,javaRestTest-2,javaRestTest-3"; - AllocateAction allocateAction = new AllocateAction(null, singletonMap("_name", allocateNodeName), null, null); + AllocateAction allocateAction = new AllocateAction(null, null, singletonMap("_name", allocateNodeName), null, null); String endPhase = randomFrom("warm", "cold"); createNewSingletonPolicy(client(), policy, endPhase, allocateAction); updatePolicy(client(), index, policy); @@ -183,7 +183,7 @@ public void testAllocateActionOnlyReplicas() throws Exception { int finalNumReplicas = (numReplicas + 1) % 2; createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numReplicas)); - AllocateAction allocateAction = new AllocateAction(finalNumReplicas, null, null, null); + AllocateAction allocateAction = new AllocateAction(finalNumReplicas, null, null, null, null); String endPhase = randomFrom("warm", "cold"); createNewSingletonPolicy(client(), policy, endPhase, allocateAction); updatePolicy(client(), index, policy); From 33021e054b95177852005e5fdc162df16bae30e2 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Wed, 11 Aug 2021 13:59:52 -0500 Subject: [PATCH 8/9] using int instead of vint --- docs/reference/ilm/actions/ilm-allocate.asciidoc | 4 ++-- .../elasticsearch/xpack/core/ilm/AllocateAction.java | 7 +++++-- .../xpack/core/ilm/AllocateActionTests.java | 11 ++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/reference/ilm/actions/ilm-allocate.asciidoc b/docs/reference/ilm/actions/ilm-allocate.asciidoc index 91904e5f74938..f89cfa064605c 100644 --- a/docs/reference/ilm/actions/ilm-allocate.asciidoc +++ b/docs/reference/ilm/actions/ilm-allocate.asciidoc @@ -34,8 +34,8 @@ Number of replicas to assign to the index. `total_shards_per_node`:: (Optional, integer) -The maximum number of shards for the index on a single {es} node. Negative values -are interpreted as unlimited. See <>. +The maximum number of shards for the index on a single {es} node. A value of `-1` is +interpreted as unlimited. See <>. `include`:: (Optional, object) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java index 79acf8de68e14..959fd94ec4687 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java @@ -85,12 +85,15 @@ public AllocateAction(Integer numberOfReplicas, Integer totalShardsPerNode, Map< throw new IllegalArgumentException("[" + NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0"); } this.numberOfReplicas = numberOfReplicas; + if (totalShardsPerNode != null && totalShardsPerNode < -1) { + throw new IllegalArgumentException("[" + TOTAL_SHARDS_PER_NODE_FIELD.getPreferredName() + "] must be >= -1"); + } this.totalShardsPerNode = totalShardsPerNode; } @SuppressWarnings("unchecked") public AllocateAction(StreamInput in) throws IOException { - this(in.readOptionalVInt(), in.getVersion().onOrAfter(Version.V_8_0_0) ? in.readOptionalVInt() : null, + this(in.readOptionalVInt(), in.getVersion().onOrAfter(Version.V_8_0_0) ? in.readOptionalInt() : null, (Map) in.readGenericValue(), (Map) in.readGenericValue(), (Map) in.readGenericValue()); } @@ -119,7 +122,7 @@ public Map getRequire() { public void writeTo(StreamOutput out) throws IOException { out.writeOptionalVInt(numberOfReplicas); if (out.getVersion().onOrAfter(Version.V_8_0_0)) { - out.writeOptionalVInt(totalShardsPerNode); + out.writeOptionalInt(totalShardsPerNode); } out.writeGenericValue(include); out.writeGenericValue(exclude); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java index 20968cd5f5bf3..204eef6ec5cdc 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java @@ -57,7 +57,7 @@ static AllocateAction randomInstance() { requires = randomBoolean() ? null : Collections.emptyMap(); } Integer numberOfReplicas = randomBoolean() ? null : randomIntBetween(0, 10); - Integer totalShardsPerNode = randomBoolean() ? null : randomIntBetween(-300, 300); + Integer totalShardsPerNode = randomBoolean() ? null : randomIntBetween(-1, 300); return new AllocateAction(numberOfReplicas, totalShardsPerNode, includes, excludes, requires); } @@ -116,6 +116,15 @@ public void testInvalidNumberOfReplicas() { assertEquals("[" + AllocateAction.NUMBER_OF_REPLICAS_FIELD.getPreferredName() + "] must be >= 0", exception.getMessage()); } + public void testInvalidTotalShardsPerNode() { + Map include = randomAllocationRoutingMap(1, 5); + Map exclude = randomBoolean() ? null : Collections.emptyMap(); + Map require = randomBoolean() ? null : Collections.emptyMap(); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> new AllocateAction(randomIntBetween(0, 300), randomIntBetween(-1000, -2), include, exclude, require)); + assertEquals("[" + AllocateAction.TOTAL_SHARDS_PER_NODE_FIELD.getPreferredName() + "] must be >= -1", exception.getMessage()); + } + public static Map randomAllocationRoutingMap(int minEntries, int maxEntries) { Map map = new HashMap<>(); int numIncludes = randomIntBetween(minEntries, maxEntries); From 4eeee13a5a20d414fee39e9d28bc02e5b901524f Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Wed, 11 Aug 2021 14:10:45 -0500 Subject: [PATCH 9/9] restricting total shards per node to >= -1 --- .../org/elasticsearch/xpack/core/ilm/AllocateActionTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java index 204eef6ec5cdc..0e509e827193f 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java @@ -170,7 +170,7 @@ public void testToSteps() { } public void testTotalNumberOfShards() throws Exception { - Integer totalShardsPerNode = randomIntBetween(-1000, 1000); + Integer totalShardsPerNode = randomIntBetween(-1, 1000); Integer numberOfReplicas = randomIntBetween(0, 4); AllocateAction action = new AllocateAction(numberOfReplicas, totalShardsPerNode, null, null, null); String phase = randomAlphaOfLengthBetween(1, 10);