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

Fix testFailOverOnFollower #58763

Closed
wants to merge 2 commits into from
Closed
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 @@ -2087,6 +2087,15 @@ private Collection<NodeAndClient> dataNodeAndClients() {
return filterNodes(nodes, DATA_NODE_PREDICATE);
}

public Collection<Node> filterNodes(Predicate<Node> predicate) {
return nodes
.values()
.stream()
.map(NodeAndClient::node)
.filter(predicate)
.collect(Collectors.toCollection(ArrayList::new));
}

private static Collection<NodeAndClient> filterNodes(Map<String, InternalTestCluster.NodeAndClient> map,
Predicate<NodeAndClient> predicate) {
return map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ protected boolean reuseClusters() {
return false;
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/58534")
public void testFailOverOnFollower() throws Exception {
final String leaderIndex = "leader_test_failover";
final String followerIndex = "follower_test_failover";
int numberOfReplicas = between(1, 2);
getFollowerCluster().startMasterOnlyNode();
getFollowerCluster().ensureAtLeastNumDataNodes(numberOfReplicas + between(1, 2));
ensureFollowerHasAtLeastNumDataAndRemoteClusterClientNodes(numberOfReplicas + between(1, 2));
String leaderIndexSettings = getIndexSettings(1, numberOfReplicas);
assertAcked(leaderClient().admin().indices().prepareCreate(leaderIndex).setSource(leaderIndexSettings, XContentType.JSON));
AtomicBoolean stopped = new AtomicBoolean();
Expand Down Expand Up @@ -122,7 +121,7 @@ public void testFailOverOnFollower() throws Exception {
}

public void testFollowIndexAndCloseNode() throws Exception {
getFollowerCluster().ensureAtLeastNumDataNodes(3);
ensureFollowerHasAtLeastNumDataAndRemoteClusterClientNodes(3);
String leaderIndexSettings = getIndexSettings(3, 1);
assertAcked(leaderClient().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON));
ensureLeaderGreen("index1");
Expand Down Expand Up @@ -181,7 +180,7 @@ public void testAddNewReplicasOnFollower() throws Exception {
assertAcked(leaderClient().admin().indices().prepareCreate("leader-index").setSource(leaderIndexSettings, XContentType.JSON));
PutFollowAction.Request follow = putFollow("leader-index", "follower-index");
followerClient().execute(PutFollowAction.INSTANCE, follow).get();
getFollowerCluster().ensureAtLeastNumDataNodes(numberOfReplicas + between(2, 3));
ensureFollowerHasAtLeastNumDataAndRemoteClusterClientNodes(numberOfReplicas + between(2, 3));
ensureFollowerGreen("follower-index");
AtomicBoolean stopped = new AtomicBoolean();
AtomicInteger docID = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.UnassignedInfo;
import org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings;
Expand Down Expand Up @@ -73,6 +75,7 @@
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.MockHttpTransport;
import org.elasticsearch.test.NodeConfigurationSource;
import org.elasticsearch.test.NodeRoles;
import org.elasticsearch.test.TestCluster;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.transport.RemoteConnectionStrategy;
Expand Down Expand Up @@ -751,6 +754,22 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
latch.await();
}

protected void ensureFollowerHasAtLeastNumDataAndRemoteClusterClientNodes(int n) {
final InternalTestCluster followerCluster = getFollowerCluster();
final int currentNodes = followerCluster.filterNodes(node ->
DiscoveryNode.hasRole(node.settings(), DiscoveryNodeRole.DATA_ROLE) &&
DiscoveryNode.hasRole(node.settings(), DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)).size();
if (currentNodes < n) {
followerCluster.startNodes(n - currentNodes,
NodeRoles.onlyRoles(Settings.EMPTY, Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)));
followerCluster.validateClusterFormed();
}
final int newNodes = followerCluster.filterNodes(node ->
DiscoveryNode.hasRole(node.settings(), DiscoveryNodeRole.DATA_ROLE) &&
DiscoveryNode.hasRole(node.settings(), DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)).size();
assertThat(newNodes, greaterThanOrEqualTo(n));
}

static class ClusterGroup implements Closeable {

final InternalTestCluster leaderCluster;
Expand Down