From a64d2a5fe7a23dd308e8f1a25bab599a76d5b0b3 Mon Sep 17 00:00:00 2001 From: Anshu Agarwal Date: Tue, 10 Jan 2023 14:58:39 +0530 Subject: [PATCH] Address fail open comments (#5778) [Weighted Shard Routing] Refactor and fix singleton in FailAwareWeightedRouting Signed-off-by: Anshu Agarwal --- .../cluster/routing/FailAwareWeightedRouting.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/routing/FailAwareWeightedRouting.java b/server/src/main/java/org/opensearch/cluster/routing/FailAwareWeightedRouting.java index 1445254ef1b09..0ddaed2157514 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/FailAwareWeightedRouting.java +++ b/server/src/main/java/org/opensearch/cluster/routing/FailAwareWeightedRouting.java @@ -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 internalErrorRestStatusList = List.of( @@ -44,7 +44,6 @@ public enum FailAwareWeightedRouting { public static FailAwareWeightedRouting getInstance() { return INSTANCE; - } /** @@ -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(); @@ -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();