Skip to content

Commit ed08bc3

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 03b2ec6 commit ed08bc3

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
@@ -92,6 +92,30 @@ public RemoteConnectionInfo(StreamInput input) throws IOException {
9292
skipUnavailable = input.readBoolean();
9393
}
9494

95+
public List<String> getSeedNodes() {
96+
return seedNodes;
97+
}
98+
99+
public int getConnectionsPerCluster() {
100+
return connectionsPerCluster;
101+
}
102+
103+
public TimeValue getInitialConnectionTimeout() {
104+
return initialConnectionTimeout;
105+
}
106+
107+
public int getNumNodesConnected() {
108+
return numNodesConnected;
109+
}
110+
111+
public String getClusterAlias() {
112+
return clusterAlias;
113+
}
114+
115+
public boolean isSkipUnavailable() {
116+
return skipUnavailable;
117+
}
118+
95119
@Override
96120
public void writeTo(StreamOutput out) throws IOException {
97121
if (out.getVersion().onOrAfter(Version.V_7_0_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
@@ -46,6 +46,7 @@
4646
import org.elasticsearch.persistent.PersistentTasksExecutor;
4747
import org.elasticsearch.tasks.TaskId;
4848
import org.elasticsearch.threadpool.ThreadPool;
49+
import org.elasticsearch.transport.NoSuchRemoteClusterException;
4950
import org.elasticsearch.xpack.ccr.Ccr;
5051
import org.elasticsearch.xpack.ccr.CcrSettings;
5152
import org.elasticsearch.xpack.ccr.action.bulk.BulkShardOperationsAction;
@@ -114,7 +115,16 @@ protected void innerUpdateMapping(long minRequiredMappingVersion, LongConsumer h
114115
final Index followerIndex = params.getFollowShardId().getIndex();
115116
final Index leaderIndex = params.getLeaderShardId().getIndex();
116117
final Supplier<TimeValue> timeout = () -> isStopped() ? TimeValue.MINUS_ONE : waitForMetadataTimeOut;
117-
CcrRequests.getIndexMetadata(remoteClient(params), leaderIndex, minRequiredMappingVersion, 0L, timeout, ActionListener.wrap(
118+
119+
final Client remoteClient;
120+
try {
121+
remoteClient = remoteClient(params);
122+
} catch (NoSuchRemoteClusterException e) {
123+
errorHandler.accept(e);
124+
return;
125+
}
126+
127+
CcrRequests.getIndexMetadata(remoteClient, leaderIndex, minRequiredMappingVersion, 0L, timeout, ActionListener.wrap(
118128
indexMetaData -> {
119129
if (indexMetaData.getMappings().isEmpty()) {
120130
assert indexMetaData.getMappingVersion() == 1;
@@ -173,7 +183,7 @@ protected void innerUpdateSettings(final LongConsumer finalHandler, final Consum
173183
};
174184
try {
175185
remoteClient(params).admin().cluster().state(clusterStateRequest, ActionListener.wrap(onResponse, errorHandler));
176-
} catch (Exception e) {
186+
} catch (NoSuchRemoteClusterException e) {
177187
errorHandler.accept(e);
178188
}
179189
}
@@ -231,7 +241,7 @@ protected void innerSendShardChangesRequest(long from, int maxOperationCount, Co
231241
request.setPollTimeout(params.getReadPollTimeout());
232242
try {
233243
remoteClient(params).execute(ShardChangesAction.INSTANCE, request, ActionListener.wrap(handler::accept, errorHandler));
234-
} catch (Exception e) {
244+
} catch (NoSuchRemoteClusterException e) {
235245
errorHandler.accept(e);
236246
}
237247
}

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
@@ -92,7 +92,6 @@ public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Excep
9292
assertThat(client().admin().indices().prepareExists("follower-index").get().isExists(), equalTo(false));
9393
}
9494

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

0 commit comments

Comments
 (0)