Skip to content

Commit 19f14c6

Browse files
Reject RECONNECT_UNLESS_SKIP_UNAVAILABLE in CPS
DisconnectedStrategy.RECONNECT_UNLESS_SKIP_UNAVAILABLE is unsupported in CPS, as skip_unavailable itself is unsupported in CPS. This change adds a check in RemoteClusterService.getRemoteClusterClient() rejecting RECONNECT_UNLESS_SKIP_UNAVAILABLE if stateless is enabled and adds a unit test case for it. Resolves: ES-12610
1 parent 768396d commit 19f14c6

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,13 @@ public RemoteClusterClient getRemoteClusterClient(
651651
DisconnectedStrategy disconnectedStrategy
652652
) {
653653
ensureClientIsEnabled();
654+
if (isStateless && disconnectedStrategy == DisconnectedStrategy.RECONNECT_UNLESS_SKIP_UNAVAILABLE) {
655+
final var message = "DisconnectedStrategy ["
656+
+ DisconnectedStrategy.RECONNECT_UNLESS_SKIP_UNAVAILABLE
657+
+ "] is not supported in stateless environments";
658+
assert false : message;
659+
throw new IllegalArgumentException(message);
660+
}
654661
if (transportService.getRemoteClusterService().getRegisteredRemoteClusterNames().contains(clusterAlias) == false) {
655662
throw new NoSuchRemoteClusterException(clusterAlias);
656663
}

server/src/test/java/org/elasticsearch/transport/RemoteClusterClientTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,34 @@ public void testRemoteClusterServiceNotEnabled() {
244244
}
245245
}
246246

247+
public void testGetRemoteClusterClientRejectsReconnectUnlessSkipUnavailableInStateless() {
248+
final var settings = Settings.builder().put("stateless.enabled", true).putList("node.roles", "remote_cluster_client").build();
249+
try (
250+
MockTransportService service = MockTransportService.createNewService(
251+
settings,
252+
VersionInformation.CURRENT,
253+
TransportVersion.current(),
254+
threadPool,
255+
null
256+
)
257+
) {
258+
final var remoteClusterService = service.getRemoteClusterService();
259+
final var unsupportedDisconnectedStrategy = RemoteClusterService.DisconnectedStrategy.RECONNECT_UNLESS_SKIP_UNAVAILABLE;
260+
final var error = expectThrows(
261+
AssertionError.class,
262+
() -> remoteClusterService.getRemoteClusterClient(
263+
"test",
264+
EsExecutors.DIRECT_EXECUTOR_SERVICE,
265+
unsupportedDisconnectedStrategy
266+
)
267+
);
268+
assertThat(
269+
error.getMessage(),
270+
equalTo("DisconnectedStrategy [" + unsupportedDisconnectedStrategy + "] is not supported in stateless environments")
271+
);
272+
}
273+
}
274+
247275
public void testQuicklySkipUnavailableClusters() throws Exception {
248276
Settings remoteSettings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), "foo_bar_cluster").build();
249277
try (

0 commit comments

Comments
 (0)