Skip to content

Commit

Permalink
Address fail open comments (opensearch-project#5778)
Browse files Browse the repository at this point in the history
[Weighted Shard Routing] Refactor and fix singleton in FailAwareWeightedRouting

Signed-off-by: Anshu Agarwal <[email protected]>
  • Loading branch information
anshu1106 authored and Anshu Agarwal committed Jan 10, 2023
1 parent 0e2e61b commit ffa89fd
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
* nodes whose attribute value weight for weighted shard routing is set to zero.
*/

public enum FailAwareWeightedRouting {
INSTANCE;
public class FailAwareWeightedRouting {

public static final FailAwareWeightedRouting INSTANCE = new FailAwareWeightedRouting();
private static final Logger logger = LogManager.getLogger(FailAwareWeightedRouting.class);

private final static List<RestStatus> internalErrorRestStatusList = List.of(
Expand All @@ -44,7 +44,6 @@ public enum FailAwareWeightedRouting {

public static FailAwareWeightedRouting getInstance() {
return INSTANCE;

}

/**
Expand Down Expand Up @@ -103,9 +102,7 @@ public SearchShardTarget findNext(final SearchShardIterator shardIt, ClusterStat
while (next != null && isWeighedAway(next.getNodeId(), clusterState)) {
SearchShardTarget nextShard = next;
if (canFailOpen(nextShard.getShardId(), exception, clusterState)) {
logger.info(
() -> new ParameterizedMessage("{}: Fail open executed due to exception {}", nextShard.getShardId(), exception)
);
logger.info(() -> new ParameterizedMessage("{}: Fail open executed due to exception", nextShard.getShardId()), exception);
break;
}
next = shardIt.nextOrNull();
Expand All @@ -127,7 +124,7 @@ public ShardRouting findNext(final ShardsIterator shardsIt, ClusterState cluster
while (next != null && isWeighedAway(next.currentNodeId(), clusterState)) {
ShardRouting nextShard = next;
if (canFailOpen(nextShard.shardId(), exception, clusterState)) {
logger.info(() -> new ParameterizedMessage("{}: Fail open executed due to exception {}", nextShard.shardId(), exception));
logger.info(() -> new ParameterizedMessage("{}: Fail open executed due to exception", nextShard.shardId()), exception);
break;
}
next = shardsIt.nextOrNull();
Expand Down

0 comments on commit ffa89fd

Please sign in to comment.