Skip to content

Wait for connect on remote settings update #48497

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

Merged
merged 1 commit into from
Oct 25, 2019
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 @@ -49,6 +49,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -396,7 +397,24 @@ protected void updateRemoteCluster(String clusterAlias, List<String> addresses,
builder.setPingInterval(pingSchedule);
newProfile = builder.build();
}
updateRemoteCluster(clusterAlias, addresses, proxyAddress, newProfile, noopListener);

if (remoteClusters.containsKey(clusterAlias) == false) {
CountDownLatch latch = new CountDownLatch(1);
updateRemoteCluster(clusterAlias, addresses, proxyAddress, newProfile, ActionListener.wrap(latch::countDown));

try {
// Wait 10 seconds for a new cluster. We must use a latch instead of a future because we
// are on the cluster state thread and our custom future implementation will throw an
// assertion.
if (latch.await(10, TimeUnit.SECONDS) == false) {
logger.warn("failed to connect to new remote cluster {} within {}", clusterAlias, TimeValue.timeValueSeconds(10));
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} else {
updateRemoteCluster(clusterAlias, addresses, proxyAddress, newProfile, noopListener);
}
}

void updateRemoteCluster(final String clusterAlias, final List<String> addresses, final String proxyAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -322,7 +323,19 @@ public void testIncrementallyAddClusters() throws IOException {
assertFalse(service.isCrossClusterSearchEnabled());
service.initializeRemoteClusters();
assertFalse(service.isCrossClusterSearchEnabled());
service.updateRemoteCluster("cluster_1", Collections.singletonList(cluster1Seed.getAddress().toString()), null);

PlainActionFuture<Void> clusterAdded = PlainActionFuture.newFuture();
// Add the cluster on a different thread to test that we wait for a new cluster to
// connect before returning.
new Thread(() -> {
try {
service.updateRemoteCluster("cluster_1", Collections.singletonList(cluster1Seed.getAddress().toString()), null);
clusterAdded.onResponse(null);
} catch (Exception e) {
clusterAdded.onFailure(e);
}
}).start();
clusterAdded.actionGet();
assertTrue(service.isCrossClusterSearchEnabled());
assertTrue(service.isRemoteClusterRegistered("cluster_1"));
service.updateRemoteCluster("cluster_2", Collections.singletonList(cluster2Seed.getAddress().toString()), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ public void setupLocalRemote() throws Exception {
updateSettingsRequest.transientSettings(Settings.builder().put("cluster.remote.local.seeds", address));
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());

assertBusy(() -> {
List<RemoteConnectionInfo> infos = client().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
assertThat(infos.size(), equalTo(1));
assertThat(infos.get(0).getNumNodesConnected(), equalTo(1));
});
List<RemoteConnectionInfo> infos = client().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
assertThat(infos.size(), equalTo(1));
assertThat(infos.get(0).getNumNodesConnected(), equalTo(1));
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ private void setupRemoteCluster() throws Exception {
updateSettingsRequest.persistentSettings(Settings.builder().put("cluster.remote.leader_cluster.seeds", address));
assertAcked(followerClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet());

assertBusy(() -> {
List<RemoteConnectionInfo> infos =
followerClient().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
assertThat(infos.size(), equalTo(1));
assertThat(infos.get(0).getNumNodesConnected(), greaterThanOrEqualTo(1));
});
List<RemoteConnectionInfo> infos =
followerClient().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
assertThat(infos.size(), equalTo(1));
assertThat(infos.get(0).getNumNodesConnected(), greaterThanOrEqualTo(1));
}

private void cleanRemoteCluster() throws Exception {
Expand Down