60
60
import java .util .stream .Stream ;
61
61
62
62
import static org .elasticsearch .common .settings .Setting .boolSetting ;
63
+ import static org .elasticsearch .common .settings .Setting .timeSetting ;
63
64
64
65
/**
65
66
* Basic service for accessing remote clusters via gateway nodes
@@ -166,6 +167,12 @@ public String getKey(final String key) {
166
167
Setting .Property .NodeScope ),
167
168
REMOTE_CLUSTERS_SEEDS );
168
169
170
+ public static final Setting .AffixSetting <TimeValue > REMOTE_CLUSTER_PING_SCHEDULE = Setting .affixKeySetting (
171
+ "cluster.remote." ,
172
+ "transport.ping_schedule" ,
173
+ key -> timeSetting (key , TcpTransport .PING_SCHEDULE , Setting .Property .NodeScope ),
174
+ REMOTE_CLUSTERS_SEEDS );
175
+
169
176
private static final Predicate <DiscoveryNode > DEFAULT_NODE_PREDICATE = (node ) -> Version .CURRENT .isCompatible (node .getVersion ())
170
177
&& (node .isMasterNode () == false || node .isDataNode () || node .isIngestNode ());
171
178
@@ -211,10 +218,13 @@ private synchronized void updateRemoteClusters(Map<String, Tuple<String, List<Su
211
218
}
212
219
213
220
if (remote == null ) { // this is a new cluster we have to add a new representation
214
- remote = new RemoteClusterConnection (settings , entry .getKey (), seedList , transportService ,
215
- new ConnectionManager (settings , transportService .transport , transportService .threadPool ), numRemoteConnections ,
216
- getNodePredicate (settings ), proxyAddress );
217
- remoteClusters .put (entry .getKey (), remote );
221
+ String clusterAlias = entry .getKey ();
222
+ TimeValue pingSchedule = REMOTE_CLUSTER_PING_SCHEDULE .getConcreteSettingForNamespace (clusterAlias ).get (settings );
223
+ ConnectionManager connectionManager = new ConnectionManager (settings , transportService .transport ,
224
+ transportService .threadPool , pingSchedule );
225
+ remote = new RemoteClusterConnection (settings , clusterAlias , seedList , transportService , connectionManager ,
226
+ numRemoteConnections , getNodePredicate (settings ), proxyAddress );
227
+ remoteClusters .put (clusterAlias , remote );
218
228
}
219
229
220
230
// now update the seed nodes no matter if it's new or already existing
@@ -340,31 +350,27 @@ public void onFailure(Exception e) {
340
350
* @throws IllegalArgumentException if the remote cluster is unknown
341
351
*/
342
352
public Transport .Connection getConnection (DiscoveryNode node , String cluster ) {
343
- RemoteClusterConnection connection = remoteClusters .get (cluster );
344
- if (connection == null ) {
345
- throw new IllegalArgumentException ("no such remote cluster: " + cluster );
346
- }
347
- return connection .getConnection (node );
353
+ return getRemoteClusterConnection (cluster ).getConnection (node );
348
354
}
349
355
350
356
/**
351
357
* Ensures that the given cluster alias is connected. If the cluster is connected this operation
352
358
* will invoke the listener immediately.
353
359
*/
354
- public void ensureConnected (String clusterAlias , ActionListener <Void > listener ) {
355
- RemoteClusterConnection remoteClusterConnection = remoteClusters .get (clusterAlias );
356
- if (remoteClusterConnection == null ) {
357
- throw new IllegalArgumentException ("no such remote cluster: " + clusterAlias );
358
- }
359
- remoteClusterConnection .ensureConnected (listener );
360
+ void ensureConnected (String clusterAlias , ActionListener <Void > listener ) {
361
+ getRemoteClusterConnection (clusterAlias ).ensureConnected (listener );
360
362
}
361
363
362
364
public Transport .Connection getConnection (String cluster ) {
365
+ return getRemoteClusterConnection (cluster ).getConnection ();
366
+ }
367
+
368
+ RemoteClusterConnection getRemoteClusterConnection (String cluster ) {
363
369
RemoteClusterConnection connection = remoteClusters .get (cluster );
364
370
if (connection == null ) {
365
371
throw new IllegalArgumentException ("no such remote cluster: " + cluster );
366
372
}
367
- return connection . getConnection () ;
373
+ return connection ;
368
374
}
369
375
370
376
@ Override
@@ -386,7 +392,6 @@ synchronized void updateSkipUnavailable(String clusterAlias, Boolean skipUnavail
386
392
}
387
393
}
388
394
389
-
390
395
@ Override
391
396
protected void updateRemoteCluster (String clusterAlias , List <String > addresses , String proxyAddress ) {
392
397
updateRemoteCluster (clusterAlias , addresses , proxyAddress , ActionListener .wrap ((x ) -> {}, (x ) -> {}));
0 commit comments