Skip to content

Commit

Permalink
Fix inconsistent cluster state and ensure weigh away exception check …
Browse files Browse the repository at this point in the history
…only for data nodes (#6327) (#6407)

Signed-off-by: Anshu Agarwal <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] authored Feb 21, 2023
1 parent 646cbe2 commit 8a16596
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,17 @@ private void executeHealth(
if (validationPredicate.test(currentState)) {
ClusterHealthResponse clusterHealthResponse = getResponse(request, currentState, waitCount, TimeoutState.OK);
if (request.ensureNodeWeighedIn() && clusterHealthResponse.hasDiscoveredClusterManager()) {
DiscoveryNode localNode = clusterService.state().getNodes().getLocalNode();
assert request.local() == true : "local node request false for request for local node weighed in";
boolean weighedAway = WeightedRoutingUtils.isWeighedAway(localNode.getId(), clusterService.state());
if (weighedAway) {
listener.onFailure(new NodeWeighedAwayException("local node is weighed away"));
return;
DiscoveryNode localNode = currentState.getNodes().getLocalNode();
// TODO: make this check more generic, check for node role instead
if (localNode.isDataNode()) {
assert request.local() == true : "local node request false for request for local node weighed in";
boolean weighedAway = WeightedRoutingUtils.isWeighedAway(localNode.getId(), currentState);
if (weighedAway) {
listener.onFailure(new NodeWeighedAwayException("local node is weighed away"));
return;
}
}
}

listener.onResponse(clusterHealthResponse);
} else {
final ClusterStateObserver observer = new ClusterStateObserver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class WeightedRoutingUtils {
*/
public static boolean isWeighedAway(String nodeId, ClusterState clusterState) {
DiscoveryNode node = clusterState.nodes().get(nodeId);
if (node == null) {
return false;
}
WeightedRoutingMetadata weightedRoutingMetadata = clusterState.metadata().weightedRoutingMetadata();
if (weightedRoutingMetadata != null) {
WeightedRouting weightedRouting = weightedRoutingMetadata.getWeightedRouting();
Expand Down

0 comments on commit 8a16596

Please sign in to comment.