-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Index Balanced Allocation Decider Add index routing filter handling #138741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
8a9a4f8
35f41eb
1d01c0c
fd6ff2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,11 @@ | |
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Supplier; | ||
|
|
||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_PREFIX; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_PREFIX; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_CREATION_DATE; | ||
| import static org.elasticsearch.cluster.routing.TestShardRouting.shardRoutingBuilder; | ||
| import static org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP_PREFIX; | ||
|
|
@@ -77,12 +81,12 @@ public class IndexBalanceAllocationDeciderTests extends ESAllocationTestCase { | |
| private List<RoutingNode> indexTier; | ||
| private List<RoutingNode> searchIier; | ||
|
|
||
| private void setup(Settings settings) { | ||
| private void setup(Settings clusterSettings, Supplier<Settings> indexSettings) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason why indexSettings is a Supplier is due to the need to defer retrieving DiscoveryNode reference until these variables are initialized.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's OK though the filters and the decider behaviour do not depend on the filtered node IDs to match existing nodes. |
||
| final String indexName = "IndexBalanceAllocationDeciderIndex"; | ||
| final Map<DiscoveryNode, List<ShardRouting>> nodeToShardRoutings = new HashMap<>(); | ||
|
|
||
| Settings.Builder builder = Settings.builder() | ||
| .put(settings) | ||
| .put(clusterSettings) | ||
| .put("stateless.enabled", "true") | ||
| .put(IndexBalanceConstraintSettings.INDEX_BALANCE_DECIDER_ENABLED_SETTING.getKey(), "true"); | ||
|
|
||
|
|
@@ -111,10 +115,9 @@ private void setup(Settings settings) { | |
|
|
||
| indexMetadata = IndexMetadata.builder(indexName) | ||
| .settings( | ||
| indexSettings(IndexVersion.current(), numberOfPrimaryShards, replicationFactor).put( | ||
| SETTING_CREATION_DATE, | ||
| System.currentTimeMillis() | ||
| ).build() | ||
| indexSettings(IndexVersion.current(), numberOfPrimaryShards, replicationFactor).put(indexSettings.get()) | ||
| .put(SETTING_CREATION_DATE, System.currentTimeMillis()) | ||
| .build() | ||
| ) | ||
| .timestampRange(IndexLongFieldRange.UNKNOWN) | ||
| .eventIngestedRange(IndexLongFieldRange.UNKNOWN) | ||
|
|
@@ -211,8 +214,8 @@ private void setup(Settings settings) { | |
| } | ||
|
|
||
| public void testCanAllocateUnderThresholdWithExcessShards() { | ||
| Settings settings = allowExcessShards(Settings.EMPTY); | ||
| setup(settings); | ||
| Settings clusterSettings = allowExcessShards(Settings.EMPTY); | ||
| setup(clusterSettings, () -> Settings.EMPTY); | ||
|
|
||
| ShardRouting newIndexShardRouting = TestShardRouting.newShardRouting( | ||
| new ShardId("newIndex", "uuid", 1), | ||
|
|
@@ -279,7 +282,7 @@ private void verifyCanAllocate() { | |
| } | ||
|
|
||
| public void testCanAllocateExceedThreshold() { | ||
| setup(Settings.EMPTY); | ||
| setup(Settings.EMPTY, () -> Settings.EMPTY); | ||
|
|
||
| int ideal = numberOfPrimaryShards / 2; | ||
| int current = numberOfPrimaryShards / 2; | ||
|
|
@@ -316,11 +319,33 @@ public void testCanAllocateExceedThreshold() { | |
| } | ||
|
|
||
| public void testCanAllocateHasDiscoveryNodeFilters() { | ||
| Settings settings = addRandomFilterSetting(Settings.EMPTY); | ||
| Settings clusterSettings = addRandomFilterSetting(Settings.EMPTY); | ||
| if (randomBoolean()) { | ||
| settings = allowExcessShards(settings); | ||
| clusterSettings = allowExcessShards(clusterSettings); | ||
| } | ||
| setup(clusterSettings, () -> Settings.EMPTY); | ||
|
|
||
| for (RoutingNode routingNode : indexTier) { | ||
| assertDecisionMatches( | ||
| "Having DiscoveryNodeFilters disables this decider", | ||
| indexBalanceAllocationDecider.canAllocate(indexTierShardRouting, routingNode, routingAllocation), | ||
| Decision.Type.YES, | ||
| "Decider is disabled." | ||
| ); | ||
| } | ||
|
|
||
| for (RoutingNode routingNode : searchIier) { | ||
| assertDecisionMatches( | ||
| "Having DiscoveryNodeFilters disables this decider", | ||
| indexBalanceAllocationDecider.canAllocate(searchTierShardRouting, routingNode, routingAllocation), | ||
| Decision.Type.YES, | ||
| "Decider is disabled." | ||
| ); | ||
| } | ||
| setup(settings); | ||
| } | ||
|
|
||
| public void testCanAllocateHasIndexRoutingFilters() { | ||
| setup(Settings.EMPTY, this::addRandomIndexRoutingFilters); | ||
|
|
||
| for (RoutingNode routingNode : indexTier) { | ||
| assertDecisionMatches( | ||
|
|
@@ -362,4 +387,29 @@ public Settings allowExcessShards(Settings settings) { | |
| .build(); | ||
| } | ||
|
|
||
| public Settings addRandomIndexRoutingFilters() { | ||
| String setting = randomFrom( | ||
| INDEX_ROUTING_REQUIRE_GROUP_PREFIX, | ||
| INDEX_ROUTING_INCLUDE_GROUP_PREFIX, | ||
| INDEX_ROUTING_EXCLUDE_GROUP_PREFIX | ||
| ); | ||
| String attribute = randomFrom("_ip", "_host", "_id"); | ||
| String ip = randomFrom("192.168.0.1", "192.168.0.2", "192.168.7.1", "10.17.0.1"); | ||
| String id = randomFrom(indexNodeOne.getId(), indexNodeTwo.getId(), searchNodeOne.getId(), searchNodeTwo.getId()); | ||
| String hostName = randomFrom( | ||
| indexNodeOne.getHostName(), | ||
| indexNodeTwo.getHostName(), | ||
| searchNodeOne.getHostName(), | ||
| searchNodeTwo.getHostName() | ||
| ); | ||
|
|
||
| String value = switch (attribute) { | ||
| case "_ip" -> ip; | ||
| case "_host" -> hostName; | ||
| case "_id" -> id; | ||
| default -> throw new IllegalStateException("Unexpected value: " + attribute); | ||
| }; | ||
| return Settings.builder().put(setting + "." + attribute, value).build(); | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.