Skip to content

Commit 86fd99e

Browse files
authored
Merge branch '2.x' into backport/backport-4597-to-2.x
2 parents 6fd8fe5 + 785e4a6 commit 86fd99e

File tree

7 files changed

+1084
-943
lines changed

7 files changed

+1084
-943
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
5858
- [Bug]: Alias filter lost after rollover ([#4499](https://github.com/opensearch-project/OpenSearch/pull/4499))
5959
- Fixing Gradle warnings associated with publishPluginZipPublicationToXxx tasks ([#4696](https://github.com/opensearch-project/OpenSearch/pull/4696))
6060
- Fixed randomly failing test ([4774](https://github.com/opensearch-project/OpenSearch/pull/4774))
61-
6261
### Security
6362
- CVE-2022-25857 org.yaml:snakeyaml DOS vulnerability ([#4341](https://github.com/opensearch-project/OpenSearch/pull/4341))
63+
6464
## [2.x]
6565
### Added
6666
- Github workflow for changelog verification ([#4085](https://github.com/opensearch-project/OpenSearch/pull/4085))
@@ -79,6 +79,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
7979
- Update Jackson Databind to 2.13.4.2 (addressing CVE-2022-42003) ([#4781](https://github.com/opensearch-project/OpenSearch/pull/4781))
8080
- Install and configure Log4j JUL Adapter for Lucene 9.4 ([#4754](https://github.com/opensearch-project/OpenSearch/pull/4754))
8181
### Changed
82+
- Refactored BalancedAllocator.Balancer to LocalShardsBalancer ([#4818](https://github.com/opensearch-project/OpenSearch/pull/4818))
8283
### Deprecated
8384
### Removed
8485
- Remove RepositoryData.MIN_VERSION support for next major release ([4729](https://github.com/opensearch-project/OpenSearch/pull/4729))

server/src/main/java/org/opensearch/cluster/routing/allocation/AllocationConstraints.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.cluster.routing.allocation;
77

88
import org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
9+
import org.opensearch.cluster.routing.allocation.allocator.ShardsBalancer;
910

1011
import java.util.ArrayList;
1112
import java.util.List;
@@ -27,11 +28,11 @@ public AllocationConstraints() {
2728
}
2829

2930
class ConstraintParams {
30-
private BalancedShardsAllocator.Balancer balancer;
31+
private ShardsBalancer balancer;
3132
private BalancedShardsAllocator.ModelNode node;
3233
private String index;
3334

34-
ConstraintParams(BalancedShardsAllocator.Balancer balancer, BalancedShardsAllocator.ModelNode node, String index) {
35+
ConstraintParams(ShardsBalancer balancer, BalancedShardsAllocator.ModelNode node, String index) {
3536
this.balancer = balancer;
3637
this.node = node;
3738
this.index = index;
@@ -50,7 +51,7 @@ class ConstraintParams {
5051
* This weight function is used only in case of unassigned shards to avoid overloading a newly added node.
5152
* Weight calculation in other scenarios like shard movement and re-balancing remain unaffected by this function.
5253
*/
53-
public long weight(BalancedShardsAllocator.Balancer balancer, BalancedShardsAllocator.ModelNode node, String index) {
54+
public long weight(ShardsBalancer balancer, BalancedShardsAllocator.ModelNode node, String index) {
5455
int constraintsBreached = 0;
5556
ConstraintParams params = new ConstraintParams(balancer, node, index);
5657
for (Predicate<ConstraintParams> predicate : constraintPredicates) {

server/src/main/java/org/opensearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java

+31-936
Large diffs are not rendered by default.

server/src/main/java/org/opensearch/cluster/routing/allocation/allocator/LocalShardsBalancer.java

+967
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.cluster.routing.allocation.allocator;
10+
11+
import org.opensearch.cluster.routing.ShardRouting;
12+
import org.opensearch.cluster.routing.allocation.AllocateUnassignedDecision;
13+
import org.opensearch.cluster.routing.allocation.MoveDecision;
14+
15+
/**
16+
* <p>
17+
* A {@link ShardsBalancer} helps the {@link BalancedShardsAllocator} to perform allocation and balancing
18+
* operations on the cluster.
19+
* </p>
20+
*
21+
* @opensearch.internal
22+
*/
23+
public abstract class ShardsBalancer {
24+
25+
/**
26+
* Performs allocation of unassigned shards on nodes within the cluster.
27+
*/
28+
abstract void allocateUnassigned();
29+
30+
/**
31+
* Moves shards that cannot be allocated to a node anymore.
32+
*/
33+
abstract void moveShards();
34+
35+
/**
36+
* Balances the nodes on the cluster model.
37+
*/
38+
abstract void balance();
39+
40+
/**
41+
* Make a decision for allocating an unassigned shard.
42+
* @param shardRouting the shard for which the decision has to be made
43+
* @return the allocation decision
44+
*/
45+
abstract AllocateUnassignedDecision decideAllocateUnassigned(ShardRouting shardRouting);
46+
47+
/**
48+
* Makes a decision on whether to move a started shard to another node.
49+
* @param shardRouting the shard for which the decision has to be made
50+
* @return a move decision for the shard
51+
*/
52+
abstract MoveDecision decideMove(ShardRouting shardRouting);
53+
54+
/**
55+
* Makes a decision about moving a single shard to a different node to form a more
56+
* optimally balanced cluster.
57+
* @param shardRouting the shard for which the move decision has to be made
58+
* @return a move decision for the shard
59+
*/
60+
abstract MoveDecision decideRebalance(ShardRouting shardRouting);
61+
62+
/**
63+
* Returns the average of shards per node for the given index
64+
*/
65+
public float avgShardsPerNode() {
66+
return Float.MAX_VALUE;
67+
}
68+
69+
/**
70+
* Returns the global average of shards per node
71+
*/
72+
public float avgShardsPerNode(String index) {
73+
return Float.MAX_VALUE;
74+
}
75+
}

server/src/test/java/org/opensearch/cluster/routing/allocation/AllocationConstraintsTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import org.opensearch.cluster.OpenSearchAllocationTestCase;
1212
import org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
13+
import org.opensearch.cluster.routing.allocation.allocator.LocalShardsBalancer;
14+
import org.opensearch.cluster.routing.allocation.allocator.ShardsBalancer;
1315
import org.opensearch.common.settings.ClusterSettings;
1416
import org.opensearch.common.settings.Settings;
1517

@@ -45,7 +47,7 @@ public void testSettings() {
4547
* for IndexShardPerNode constraint satisfied and breached.
4648
*/
4749
public void testIndexShardsPerNodeConstraint() {
48-
BalancedShardsAllocator.Balancer balancer = mock(BalancedShardsAllocator.Balancer.class);
50+
ShardsBalancer balancer = mock(LocalShardsBalancer.class);
4951
BalancedShardsAllocator.ModelNode node = mock(BalancedShardsAllocator.ModelNode.class);
5052
AllocationConstraints constraints = new AllocationConstraints();
5153

server/src/test/java/org/opensearch/cluster/routing/allocation/BalancedSingleShardTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.opensearch.cluster.routing.ShardRouting;
4444
import org.opensearch.cluster.routing.ShardRoutingState;
4545
import org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
46-
import org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.Balancer;
46+
import org.opensearch.cluster.routing.allocation.allocator.ShardsBalancer;
4747
import org.opensearch.cluster.routing.allocation.decider.AllocationDecider;
4848
import org.opensearch.cluster.routing.allocation.decider.AllocationDeciders;
4949
import org.opensearch.cluster.routing.allocation.decider.Decision;
@@ -65,7 +65,7 @@
6565
import static org.hamcrest.Matchers.startsWith;
6666

6767
/**
68-
* Tests for balancing a single shard, see {@link Balancer#decideRebalance(ShardRouting)}.
68+
* Tests for balancing a single shard, see {@link ShardsBalancer#decideRebalance(ShardRouting)}.
6969
*/
7070
public class BalancedSingleShardTests extends OpenSearchAllocationTestCase {
7171

0 commit comments

Comments
 (0)