-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Segment Replication] Add global primary shard balance constraint during allocation #6643
Merged
dreamer-89
merged 3 commits into
opensearch-project:main
from
dreamer-89:global_primary_balance
Mar 15, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
server/src/main/java/org/opensearch/cluster/routing/allocation/ConstraintTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.routing.allocation; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Defines different constraints definitions | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class ConstraintTypes { | ||
public final static long CONSTRAINT_WEIGHT = 1000000L; | ||
|
||
/** | ||
* Defines per index constraint which is breached when a node contains more than avg number of primary shards for an index | ||
*/ | ||
public final static String INDEX_PRIMARY_SHARD_BALANCE_CONSTRAINT_ID = "index.primary.shard.balance.constraint"; | ||
|
||
/** | ||
* Defines a cluster constraint which is breached when a node contains more than avg primary shards across all indices | ||
*/ | ||
public final static String CLUSTER_PRIMARY_SHARD_BALANCE_CONSTRAINT_ID = "cluster.primary.shard.balance.constraint"; | ||
|
||
/** | ||
* Defines an index constraint which is breached when a node contains more than avg number of shards for an index | ||
*/ | ||
public final static String INDEX_SHARD_PER_NODE_BREACH_CONSTRAINT_ID = "index.shard.count.constraint"; | ||
|
||
/** | ||
* Constraint to control number of shards of an index allocated on a single | ||
* node. | ||
* | ||
* In current weight function implementation, when a node has significantly | ||
* fewer shards than other nodes (e.g. during single new node addition or node | ||
* replacement), its weight is much less than other nodes. All shard allocations | ||
* at this time tend to land on the new node with skewed weight. This breaks | ||
* index level balance in the cluster, by creating all shards of the same index | ||
* on one node, often resulting in a hotspot on that node. | ||
* | ||
* This constraint is breached when balancer attempts to allocate more than | ||
* average shards per index per node. | ||
*/ | ||
public static Predicate<Constraint.ConstraintParams> isIndexShardsPerNodeBreached() { | ||
return (params) -> { | ||
int currIndexShardsOnNode = params.getNode().numShards(params.getIndex()); | ||
int allowedIndexShardsPerNode = (int) Math.ceil(params.getBalancer().avgShardsPerNode(params.getIndex())); | ||
return (currIndexShardsOnNode >= allowedIndexShardsPerNode); | ||
}; | ||
} | ||
|
||
/** | ||
* Defines a predicate which returns true when specific to an index, a node contains more than average number of primary | ||
* shards. This constraint is used in weight calculation during allocation and rebalancing. When breached a high weight | ||
* {@link ConstraintTypes#CONSTRAINT_WEIGHT} is assigned to node resulting in lesser chances of node being selected | ||
* as allocation or rebalancing target | ||
*/ | ||
public static Predicate<Constraint.ConstraintParams> isPerIndexPrimaryShardsPerNodeBreached() { | ||
return (params) -> { | ||
int perIndexPrimaryShardCount = params.getNode().numPrimaryShards(params.getIndex()); | ||
int perIndexAllowedPrimaryShardCount = (int) Math.ceil(params.getBalancer().avgPrimaryShardsPerNode(params.getIndex())); | ||
return perIndexPrimaryShardCount > perIndexAllowedPrimaryShardCount; | ||
}; | ||
} | ||
|
||
/** | ||
* Defines a predicate which returns true when a node contains more than average number of primary shards. This | ||
* constraint is used in weight calculation during allocation only. When breached a high weight {@link ConstraintTypes#CONSTRAINT_WEIGHT} | ||
* is assigned to node resulting in lesser chances of node being selected as allocation target | ||
*/ | ||
public static Predicate<Constraint.ConstraintParams> isPrimaryShardsPerNodeBreached() { | ||
return (params) -> { | ||
int primaryShardCount = params.getNode().numPrimaryShards(); | ||
int allowedPrimaryShardCount = (int) Math.ceil(params.getBalancer().avgPrimaryShardsPerNode()); | ||
return primaryShardCount >= allowedPrimaryShardCount; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add a test case here for allocation/rebalance post failover with these constraints? To simulate rebalance when a shard comes back full of replicas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-balancing is only performed at per index level today. So, allocation on a multiple index failover scenario wouldn't be predictible. The per index allocation/rebalancing scenario is covered in existing ITs. The global re-balancing is tracked in #6642