Skip to content

Commit

Permalink
Fix failing tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Rabi Panda <adnapibar@gmail.com>
  • Loading branch information
adnapibar authored and getsaurabh02 committed Oct 6, 2021
1 parent e9cfb0b commit 67b0be6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,15 @@ private void verifyShardInfo(XContentParser parser, boolean primary, boolean inc
assertTrue(parser.currentName().equals("id")
|| parser.currentName().equals("name")
|| parser.currentName().equals("transport_address")
|| parser.currentName().equals("weight_ranking"));
|| parser.currentName().equals("weight_ranking")
|| parser.currentName().equals("attributes"));
// Skip past attributes object
if (parser.currentName().equals("attributes")) {
while(!parser.nextToken().equals(Token.END_OBJECT)) {
parser.nextToken();
}
break;
}
} else {
assertTrue(token.isValue());
assertNotNull(parser.text());
Expand Down Expand Up @@ -1403,6 +1411,11 @@ private String verifyNodeDecisionPrologue(XContentParser parser) throws IOExcept
parser.nextToken();
assertNotNull(parser.text());
parser.nextToken();
assertEquals("node_attributes", parser.currentName());
// skip past node_attributes object
while (!parser.currentName().equals("node_decision")) {
parser.nextToken();
}
assertEquals("node_decision", parser.currentName());
parser.nextToken();
return nodeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ public ClusterState state() {
return clusterState;
}

/**
* Returns true if the appliedClusterState is not null
*/
public boolean isInitialClusterStateSet() {
return Objects.nonNull(this.state.get());
}

/**
* Adds a high priority applier of updated cluster states.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.opensearch.common.settings.Settings;

import java.util.Iterator;
import java.util.Objects;

/**
* This class contains all the settings which are required and owned by {TODO link ShardIndexingPressure}. These will be
Expand Down Expand Up @@ -77,10 +78,14 @@ public ShardIndexingPressureSettings(ClusterService clusterService, Settings set
}

public static boolean isShardIndexingPressureAttributeEnabled() {
Iterator<DiscoveryNode> nodes = clusterService.state().getNodes().getNodes().valuesIt();
while (nodes.hasNext()) {
if (Boolean.parseBoolean(nodes.next().getAttributes().get(SHARD_INDEXING_PRESSURE_ENABLED_ATTRIBUTE_KEY)) == false) {
return false;
// Null check is required only for bwc tests which start node without initializing cluster service.
// In actual run time, clusterService will never be null.
if (Objects.nonNull(clusterService) && clusterService.getClusterApplierService().isInitialClusterStateSet()) {
Iterator<DiscoveryNode> nodes = clusterService.state().getNodes().getNodes().valuesIt();
while (nodes.hasNext()) {
if (Boolean.parseBoolean(nodes.next().getAttributes().get(SHARD_INDEXING_PRESSURE_ENABLED_ATTRIBUTE_KEY)) == false) {
return false;
}
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ public void testCoordinatingPrimaryThreadedUpdateToShardLimitsAndRejections() th
assertTrue(nodeStats.getCurrentCombinedCoordinatingAndPrimaryBytes() < 50 * 200);
assertTrue(shardStats.getIndexingPressureShardStats(shardId1).getCurrentCombinedCoordinatingAndPrimaryBytes() < 50 * 200);

for (int i = 0; i < NUM_THREADS - rejectionCount.get(); i++) {
releasables[i].close();
for (Releasable releasable : releasables) {
if (releasable != null) {
releasable.close();
}
}

nodeStats = shardIndexingPressure.stats();
Expand Down Expand Up @@ -290,9 +292,9 @@ public void testReplicaThreadedUpdateToShardLimitsAndRejections() throws Excepti
ShardIndexingPressureStats shardStats = shardIndexingPressure.shardStats();
assertTrue(shardStats.getIndexingPressureShardStats(shardId1).getCurrentReplicaBytes() < 50 * 300);

for (int i = 0; i < releasables.length - 1; i++) {
if(releasables[i] != null) {
releasables[i].close();
for (Releasable releasable : releasables) {
if (releasable != null) {
releasable.close();
}
}

Expand Down

0 comments on commit 67b0be6

Please sign in to comment.