Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Rishab Nahata <[email protected]>
  • Loading branch information
imRishN committed Aug 29, 2024
1 parent 72a10b4 commit c18d44c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public class BalancedShardsAllocator implements ShardsAllocator {

public static final Setting<TimeValue> ALLOCATOR_TIMEOUT_SETTING = Setting.timeSetting(
"cluster.routing.allocation.balanced_shards_allocator.allocator_timeout",
TimeValue.timeValueSeconds(20),
TimeValue.MINUS_ONE,
TimeValue.MINUS_ONE,
timeValue -> {
if (timeValue.compareTo(MIN_ALLOCATOR_TIMEOUT) < 0 && timeValue.compareTo(TimeValue.MINUS_ONE) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ public void testDiskThresholdWithAbsoluteSizes() {
// Primary should initialize, even though both nodes are over the limit initialize
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));

// below checks are unnecessary as the primary shard is always assigned to node2 as BSA always picks up that node
// first as both node1 and node2 have equal weight as both of them contain zero shards.
String nodeWithPrimary, nodeWithoutPrimary;
if (clusterState.getRoutingNodes().node("node1").size() == 1) {
nodeWithPrimary = "node1";
Expand Down Expand Up @@ -679,10 +681,12 @@ public void testDiskThresholdWithAbsoluteSizes() {
clusterState = startInitializingShardsAndReroute(strategy, clusterState);

logShardStates(clusterState);
// primary shard already has been relocated away
assertThat(clusterState.getRoutingNodes().node(nodeWithPrimary).size(), equalTo(0));
// node with increased space still has its shard
assertThat(clusterState.getRoutingNodes().node(nodeWithoutPrimary).size(), equalTo(1));
// primary shard already has been relocated away - this is a wrong expectation as we don't really move
// primary first unless explicitly set by setting. This is caught with PR
// https://github.com/opensearch-project/OpenSearch/pull/14761/
// as it randomises nodes to check for potential moves
// assertThat(clusterState.getRoutingNodes().node(nodeWithPrimary).size(), equalTo(0));
// assertThat(clusterState.getRoutingNodes().node(nodeWithoutPrimary).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node4").size(), equalTo(1));

Expand Down

0 comments on commit c18d44c

Please sign in to comment.