-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Segment Replication] Add global primary shard balance constraint dur…
…ing allocation (#6643) * [Segment Replication] Add global primary shard balance constraint during allocation Signed-off-by: Suraj Singh <[email protected]> * Add javadoc Signed-off-by: Suraj Singh <[email protected]> * Fix testAllConstraints test to include all constraints Signed-off-by: Suraj Singh <[email protected]> --------- Signed-off-by: Suraj Singh <[email protected]>
- Loading branch information
1 parent
2ebd644
commit ad823b6
Showing
11 changed files
with
379 additions
and
143 deletions.
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.