Skip to content

Commit b21b7fb

Browse files
committed
Allow proxy mode server name to be updated (#54107)
Currently there is a bug where the proxy strategy will not be rebuilt if the server_name is dynamically updated. This commit fixes this issue.
1 parent 21afc78 commit b21b7fb

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ protected boolean shouldOpenMoreConnections() {
157157
protected boolean strategyMustBeRebuilt(Settings newSettings) {
158158
String address = PROXY_ADDRESS.getConcreteSettingForNamespace(clusterAlias).get(newSettings);
159159
int numOfSockets = REMOTE_SOCKET_CONNECTIONS.getConcreteSettingForNamespace(clusterAlias).get(newSettings);
160-
return numOfSockets != maxNumConnections || configuredAddress.equals(address) == false;
160+
String serverName = SERVER_NAME.getConcreteSettingForNamespace(clusterAlias).get(newSettings);
161+
return numOfSockets != maxNumConnections || configuredAddress.equals(address) == false ||
162+
Objects.equals(serverName, configuredServerName) == false;
161163
}
162164

163165
@Override

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void testProxyStrategyWillResolveAddressesEachConnect() throws Exception
268268
}
269269
}
270270

271-
public void testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesChange() {
271+
public void testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesOrServerNameChange() {
272272
try (MockTransportService remoteTransport = startTransport("node1", Version.CURRENT)) {
273273
TransportAddress remoteAddress = remoteTransport.boundAddress().publishAddress();
274274

@@ -280,7 +280,7 @@ public void testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesChange(
280280
int numOfConnections = randomIntBetween(4, 8);
281281
try (RemoteConnectionManager remoteConnectionManager = new RemoteConnectionManager(clusterAlias, connectionManager);
282282
ProxyConnectionStrategy strategy = new ProxyConnectionStrategy(clusterAlias, localService, remoteConnectionManager,
283-
numOfConnections, remoteAddress.toString())) {
283+
numOfConnections, remoteAddress.toString(), "server-name")) {
284284
PlainActionFuture<Void> connectFuture = PlainActionFuture.newFuture();
285285
strategy.connect(connectFuture);
286286
connectFuture.actionGet();
@@ -295,11 +295,14 @@ public void testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesChange(
295295
.getConcreteSettingForNamespace("cluster-alias");
296296
Setting<?> socketConnections = ProxyConnectionStrategy.REMOTE_SOCKET_CONNECTIONS
297297
.getConcreteSettingForNamespace("cluster-alias");
298+
Setting<?> serverName = ProxyConnectionStrategy.SERVER_NAME
299+
.getConcreteSettingForNamespace("cluster-alias");
298300

299301
Settings noChange = Settings.builder()
300302
.put(modeSetting.getKey(), "proxy")
301303
.put(addressesSetting.getKey(), remoteAddress.toString())
302304
.put(socketConnections.getKey(), numOfConnections)
305+
.put(serverName.getKey(), "server-name")
303306
.build();
304307
assertFalse(strategy.shouldRebuildConnection(noChange));
305308
Settings addressesChanged = Settings.builder()
@@ -313,6 +316,13 @@ public void testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesChange(
313316
.put(socketConnections.getKey(), numOfConnections + 1)
314317
.build();
315318
assertTrue(strategy.shouldRebuildConnection(socketsChanged));
319+
Settings serverNameChange = Settings.builder()
320+
.put(modeSetting.getKey(), "proxy")
321+
.put(addressesSetting.getKey(), remoteAddress.toString())
322+
.put(socketConnections.getKey(), numOfConnections)
323+
.put(serverName.getKey(), "server-name2")
324+
.build();
325+
assertTrue(strategy.shouldRebuildConnection(serverNameChange));
316326
}
317327
}
318328
}

0 commit comments

Comments
 (0)