-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fail open login to all write paths with search retries
- Loading branch information
Anshu Agarwal
committed
Nov 9, 2022
1 parent
e64c59e
commit d0015fb
Showing
6 changed files
with
101 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
server/src/main/java/org/opensearch/cluster/routing/WeightedRoutingHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.routing; | ||
|
||
import org.opensearch.ExceptionsHelper; | ||
import org.opensearch.action.NoShardAvailableActionException; | ||
import org.opensearch.action.UnavailableShardsException; | ||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.cluster.metadata.WeightedRoutingMetadata; | ||
import org.opensearch.cluster.node.DiscoveryNode; | ||
import org.opensearch.transport.NodeNotConnectedException; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
public class WeightedRoutingHelper { | ||
|
||
public static boolean isInternalFailure(Exception e) { | ||
final Throwable cause = ExceptionsHelper.unwrapCause(e); | ||
if (e instanceof NoShardAvailableActionException | ||
|| e instanceof UnavailableShardsException | ||
|| e instanceof NodeNotConnectedException) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static boolean shardInWeighedAwayAZ(ShardRouting nextShard, ClusterState clusterState) { | ||
DiscoveryNode targetNode = clusterState.nodes().get(nextShard.currentNodeId()); | ||
WeightedRoutingMetadata weightedRoutingMetadata = clusterState.metadata().weightedRoutingMetadata(); | ||
|
||
if (weightedRoutingMetadata != null) { | ||
WeightedRouting weightedRouting = weightedRoutingMetadata.getWeightedRouting(); | ||
if (weightedRouting != null) { | ||
// Fetch weighted routing attributes with weight set as zero | ||
Stream<String> keys = weightedRouting.weights() | ||
.entrySet() | ||
.stream() | ||
.filter(entry -> entry.getValue().intValue() == 0) | ||
.map(Map.Entry::getKey); | ||
if (keys != null && targetNode.getAttributes().get("zone").equals(keys.findFirst().get())) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |