Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Fix Flaky Test SpecificClusterManagerNodesIT.testElectOnlyBetweenClusterManagerNodes #17265

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.opensearch.test.OpenSearchIntegTestCase.Scope;

import java.io.IOException;
import java.util.function.Supplier;

import static org.opensearch.test.NodeRoles.clusterManagerNode;
import static org.opensearch.test.NodeRoles.dataOnlyNode;
Expand Down Expand Up @@ -254,9 +255,9 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception {
logger.info("--> closing cluster-manager node (1)");
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(clusterManagerNodeName)).get();
// removing the cluster-manager from the voting configuration immediately triggers the cluster-manager to step down
assertBusy(() -> {
assertThat(
internalCluster().nonClusterManagerClient()
Supplier<String> getClusterManagerIfElected = () -> {
try {
return internalCluster().nonClusterManagerClient()
.admin()
.cluster()
.prepareState()
Expand All @@ -265,9 +266,14 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception {
.getState()
.nodes()
.getClusterManagerNode()
.getName(),
equalTo(nextClusterManagerEligableNodeName)
);
.getName();
} catch (ClusterManagerNotDiscoveredException e) {
logger.debug("failed to get cluster-manager name", e);
return null;
}
};
assertBusy(() -> {
assertThat(getClusterManagerIfElected.get(), equalTo(nextClusterManagerEligableNodeName));
assertThat(
internalCluster().clusterManagerClient()
.admin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.core.indices.breaker.CircuitBreakerService;
import org.opensearch.core.util.FileSystemUtils;
import org.opensearch.discovery.ClusterManagerNotDiscoveredException;
import org.opensearch.env.Environment;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.env.ShardLockObtainFailedException;
Expand Down Expand Up @@ -2155,13 +2156,12 @@ public String getClusterManagerName() {
* in the viaNode parameter. If viaNode isn't specified a random node will be picked to the send the request to.
*/
public String getClusterManagerName(@Nullable String viaNode) {
try {
Client client = viaNode != null ? client(viaNode) : client();
return client.admin().cluster().prepareState().get().getState().nodes().getClusterManagerNode().getName();
} catch (Exception e) {
logger.warn("Can't fetch cluster state", e);
throw new RuntimeException("Can't get cluster-manager node " + e.getMessage(), e);
Client client = viaNode != null ? client(viaNode) : client();
DiscoveryNode clusterManagerNode = client.admin().cluster().prepareState().get().getState().nodes().getClusterManagerNode();
if (clusterManagerNode == null) {
throw new ClusterManagerNotDiscoveredException("Cluster manager node not discovered");
}
return clusterManagerNode.getName();
}

/**
Expand Down
Loading