Skip to content

Commit 2220bed

Browse files
committed
Fix LocalIndexFollowingIT#testRemoveRemoteConnection() test (#38709)
* During fetching remote mapping if remote client is missing then `NoSuchRemoteClusterException` was not handled. * When adding remote connection, check that it is really connected before continue-ing to run the tests. Relates to #38695
1 parent dab92ed commit 2220bed

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteInfoResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public final class RemoteInfoResponse extends ActionResponse implements ToXConte
4343
this.infos = Collections.unmodifiableList(new ArrayList<>(infos));
4444
}
4545

46+
public List<RemoteConnectionInfo> getInfos() {
47+
return infos;
48+
}
49+
4650
@Override
4751
public void writeTo(StreamOutput out) throws IOException {
4852
super.writeTo(out);

server/src/main/java/org/elasticsearch/transport/RemoteConnectionInfo.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,30 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
111111
return builder;
112112
}
113113

114+
public List<String> getSeedNodes() {
115+
return seedNodes;
116+
}
117+
118+
public int getConnectionsPerCluster() {
119+
return connectionsPerCluster;
120+
}
121+
122+
public TimeValue getInitialConnectionTimeout() {
123+
return initialConnectionTimeout;
124+
}
125+
126+
public int getNumNodesConnected() {
127+
return numNodesConnected;
128+
}
129+
130+
public String getClusterAlias() {
131+
return clusterAlias;
132+
}
133+
134+
public boolean isSkipUnavailable() {
135+
return skipUnavailable;
136+
}
137+
114138
@Override
115139
public void writeTo(StreamOutput out) throws IOException {
116140
if (out.getVersion().onOrAfter(Version.V_6_6_0)) {

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.elasticsearch.persistent.PersistentTasksExecutor;
4848
import org.elasticsearch.tasks.TaskId;
4949
import org.elasticsearch.threadpool.ThreadPool;
50+
import org.elasticsearch.transport.NoSuchRemoteClusterException;
5051
import org.elasticsearch.xpack.ccr.Ccr;
5152
import org.elasticsearch.xpack.ccr.CcrSettings;
5253
import org.elasticsearch.xpack.ccr.action.bulk.BulkShardOperationsAction;
@@ -124,7 +125,16 @@ protected void innerUpdateMapping(long minRequiredMappingVersion, LongConsumer h
124125
final Index followerIndex = params.getFollowShardId().getIndex();
125126
final Index leaderIndex = params.getLeaderShardId().getIndex();
126127
final Supplier<TimeValue> timeout = () -> isStopped() ? TimeValue.MINUS_ONE : waitForMetadataTimeOut;
127-
CcrRequests.getIndexMetadata(remoteClient(params), leaderIndex, minRequiredMappingVersion, 0L, timeout, ActionListener.wrap(
128+
129+
final Client remoteClient;
130+
try {
131+
remoteClient = remoteClient(params);
132+
} catch (NoSuchRemoteClusterException e) {
133+
errorHandler.accept(e);
134+
return;
135+
}
136+
137+
CcrRequests.getIndexMetadata(remoteClient, leaderIndex, minRequiredMappingVersion, 0L, timeout, ActionListener.wrap(
128138
indexMetaData -> {
129139
if (indexMetaData.getMappings().isEmpty()) {
130140
assert indexMetaData.getMappingVersion() == 1;
@@ -183,7 +193,7 @@ protected void innerUpdateSettings(final LongConsumer finalHandler, final Consum
183193
};
184194
try {
185195
remoteClient(params).admin().cluster().state(clusterStateRequest, ActionListener.wrap(onResponse, errorHandler));
186-
} catch (Exception e) {
196+
} catch (NoSuchRemoteClusterException e) {
187197
errorHandler.accept(e);
188198
}
189199
}
@@ -241,7 +251,7 @@ protected void innerSendShardChangesRequest(long from, int maxOperationCount, Co
241251
request.setPollTimeout(params.getReadPollTimeout());
242252
try {
243253
remoteClient(params).execute(ShardChangesAction.INSTANCE, request, ActionListener.wrap(handler::accept, errorHandler));
244-
} catch (Exception e) {
254+
} catch (NoSuchRemoteClusterException e) {
245255
errorHandler.accept(e);
246256
}
247257
}

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package org.elasticsearch.xpack;
88

9+
import org.elasticsearch.action.admin.cluster.remote.RemoteInfoAction;
10+
import org.elasticsearch.action.admin.cluster.remote.RemoteInfoRequest;
911
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
1012
import org.elasticsearch.action.support.ActiveShardCount;
1113
import org.elasticsearch.cluster.service.ClusterService;
@@ -15,6 +17,7 @@
1517
import org.elasticsearch.license.LicensesMetaData;
1618
import org.elasticsearch.plugins.Plugin;
1719
import org.elasticsearch.test.ESSingleNodeTestCase;
20+
import org.elasticsearch.transport.RemoteConnectionInfo;
1821
import org.elasticsearch.transport.TransportService;
1922
import org.elasticsearch.xpack.ccr.CcrSettings;
2023
import org.elasticsearch.xpack.ccr.LocalStateCcr;
@@ -30,6 +33,7 @@
3033

3134
import java.util.Collection;
3235
import java.util.Collections;
36+
import java.util.List;
3337

3438
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3539
import static org.elasticsearch.xpack.CcrIntegTestCase.removeCCRRelatedMetadataFromClusterState;
@@ -57,11 +61,17 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
5761
}
5862

5963
@Before
60-
public void setupLocalRemote() {
64+
public void setupLocalRemote() throws Exception {
6165
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
6266
String address = getInstanceFromNode(TransportService.class).boundAddress().publishAddress().toString();
6367
updateSettingsRequest.transientSettings(Settings.builder().put("cluster.remote.local.seeds", address));
6468
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
69+
70+
assertBusy(() -> {
71+
List<RemoteConnectionInfo> infos = client().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
72+
assertThat(infos.size(), equalTo(1));
73+
assertThat(infos.get(0).getNumNodesConnected(), equalTo(1));
74+
});
6575
}
6676

6777
@Before
@@ -76,10 +86,15 @@ public void purgeCCRMetadata() throws Exception {
7686
}
7787

7888
@After
79-
public void removeLocalRemote() {
89+
public void removeLocalRemote() throws Exception {
8090
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
8191
updateSettingsRequest.transientSettings(Settings.builder().put("cluster.remote.local.seeds", (String) null));
8292
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
93+
94+
assertBusy(() -> {
95+
List<RemoteConnectionInfo> infos = client().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
96+
assertThat(infos.size(), equalTo(0));
97+
});
8398
}
8499

85100
protected AutoFollowStats getAutoFollowStats() {

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Excep
9393
assertThat(client().admin().indices().prepareExists("follower-index").get().isExists(), equalTo(false));
9494
}
9595

96-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/38695")
9796
public void testRemoveRemoteConnection() throws Exception {
9897
PutAutoFollowPatternAction.Request request = new PutAutoFollowPatternAction.Request();
9998
request.setName("my_pattern");

0 commit comments

Comments
 (0)