Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <anshukag@amazon.com>
  • Loading branch information
Anshu Agarwal committed Jan 31, 2023
1 parent 8806fc8 commit 122a098
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public static FailAwareWeightedRouting getInstance() {
return INSTANCE;
}

public static WeightedRoutingStats weightedRoutingStats = new WeightedRoutingStats();

/**
* *
* @return true if exception is due to cluster availability issues
Expand Down Expand Up @@ -105,7 +103,7 @@ public SearchShardTarget findNext(final SearchShardIterator shardIt, ClusterStat
SearchShardTarget nextShard = next;
if (canFailOpen(nextShard.getShardId(), exception, clusterState)) {
logger.info(() -> new ParameterizedMessage("{}: Fail open executed due to exception", nextShard.getShardId()), exception);
weightedRoutingStats.updateFailOpenCount();
getWeightedRoutingStats().updateFailOpenCount();
break;
}
next = shardIt.nextOrNull();
Expand All @@ -128,7 +126,7 @@ public ShardRouting findNext(final ShardsIterator shardsIt, ClusterState cluster
ShardRouting nextShard = next;
if (canFailOpen(nextShard.shardId(), exception, clusterState)) {
logger.info(() -> new ParameterizedMessage("{}: Fail open executed due to exception", nextShard.shardId()), exception);
weightedRoutingStats.updateFailOpenCount();
getWeightedRoutingStats().updateFailOpenCount();
break;
}
next = shardsIt.nextOrNull();
Expand All @@ -155,7 +153,7 @@ private boolean hasInActiveShardCopies(ClusterState clusterState, ShardId shardI
return false;
}

public WeightedRoutingStats getStats() {
return weightedRoutingStats;
public WeightedRoutingStats getWeightedRoutingStats() {
return WeightedRoutingStats.getInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public class WeightedRoutingStats implements ToXContentFragment, Writeable {
// number of times fail open has to be executed for search requests
private AtomicInteger failOpenCount;

public WeightedRoutingStats() {
private static final WeightedRoutingStats INSTANCE = new WeightedRoutingStats();

public static WeightedRoutingStats getInstance() {
return INSTANCE;
}

private WeightedRoutingStats() {
failOpenCount = new AtomicInteger(0);
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/org/opensearch/node/NodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

package org.opensearch.node;

import org.opensearch.cluster.routing.FailAwareWeightedRouting;
import org.opensearch.cluster.routing.WeightedRoutingStats;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.Build;
import org.opensearch.Version;
Expand Down Expand Up @@ -204,7 +204,7 @@ public NodeStats stats(
shardIndexingPressure ? this.indexingPressureService.shardStats(indices) : null,
searchBackpressure ? this.searchBackpressureService.nodeStats() : null,
clusterManagerThrottling ? this.clusterService.getClusterManagerService().getThrottlingStats() : null,
weightedRoutingStats ? FailAwareWeightedRouting.getInstance().getStats() : null
weightedRoutingStats ? WeightedRoutingStats.getInstance() : null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public static NodeStats createNodeStats() {
ScriptCacheStats scriptCacheStats = scriptStats != null ? scriptStats.toScriptCacheStats() : null;

WeightedRoutingStats weightedRoutingStats = null;
weightedRoutingStats = new WeightedRoutingStats();
weightedRoutingStats = WeightedRoutingStats.getInstance();
weightedRoutingStats.updateFailOpenCount();

// TODO NodeIndicesStats are not tested here, way too complicated to create, also they need to be migrated to Writeable yet
Expand Down

0 comments on commit 122a098

Please sign in to comment.