41
41
import org .elasticsearch .cluster .node .DiscoveryNodes ;
42
42
import org .elasticsearch .common .collect .Tuple ;
43
43
import org .elasticsearch .common .io .stream .StreamInput ;
44
+ import org .elasticsearch .common .settings .Setting ;
44
45
import org .elasticsearch .common .settings .Settings ;
45
46
import org .elasticsearch .common .transport .TransportAddress ;
46
47
import org .elasticsearch .common .unit .TimeValue ;
86
87
* {@link RemoteClusterService#REMOTE_CONNECTIONS_PER_CLUSTER} until either all eligible nodes are exhausted or the maximum number of
87
88
* connections per cluster has been reached.
88
89
*/
89
- final class RemoteClusterConnection implements TransportConnectionListener , Closeable {
90
+ public final class RemoteClusterConnection implements TransportConnectionListener , Closeable {
90
91
91
92
private static final Logger logger = LogManager .getLogger (RemoteClusterConnection .class );
92
93
@@ -102,8 +103,14 @@ final class RemoteClusterConnection implements TransportConnectionListener, Clos
102
103
private volatile boolean skipUnavailable ;
103
104
private final ConnectHandler connectHandler ;
104
105
private final TimeValue initialConnectionTimeout ;
106
+ private final int maxPendingConnectionListeners ;
107
+
105
108
private SetOnce <ClusterName > remoteClusterName = new SetOnce <>();
106
109
110
+ // this setting is intentionally not registered, it is only used in tests
111
+ public static final Setting <Integer > REMOTE_MAX_PENDING_CONNECTION_LISTENERS =
112
+ Setting .intSetting ("cluster.remote.max_pending_connection_listeners" , 1000 , Setting .Property .NodeScope );
113
+
107
114
/**
108
115
* Creates a new {@link RemoteClusterConnection}
109
116
* @param settings the nodes settings object
@@ -142,6 +149,7 @@ final class RemoteClusterConnection implements TransportConnectionListener, Clos
142
149
connectionManager .addListener (transportService );
143
150
this .proxyAddress = proxyAddress ;
144
151
initialConnectionTimeout = RemoteClusterService .REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING .get (settings );
152
+ this .maxPendingConnectionListeners = REMOTE_MAX_PENDING_CONNECTION_LISTENERS .get (settings );
145
153
}
146
154
147
155
@@ -393,14 +401,14 @@ public List<Tuple<String, Supplier<DiscoveryNode>>> getSeedNodes() {
393
401
* There is at most one connect job running at any time. If such a connect job is triggered
394
402
* while another job is running the provided listeners are queued and batched up until the current running job returns.
395
403
*
396
- * The handler has a built-in queue that can hold up to 100 connect attempts and will reject requests once the queue is full.
404
+ * The handler has a built-in queue that can hold up to 1000 connect attempts and will reject requests once the queue is full.
397
405
* In a scenario when a remote cluster becomes unavailable we will queue requests up but if we can't connect quick enough
398
406
* we will just reject the connect trigger which will lead to failing searches.
399
407
*/
400
408
private class ConnectHandler implements Closeable {
401
409
private final Semaphore running = new Semaphore (1 );
402
410
private final AtomicBoolean closed = new AtomicBoolean (false );
403
- private final BlockingQueue <ActionListener <Void >> queue = new ArrayBlockingQueue <>(100 );
411
+ private final BlockingQueue <ActionListener <Void >> queue = new ArrayBlockingQueue <>(maxPendingConnectionListeners );
404
412
private final CancellableThreads cancellableThreads = new CancellableThreads ();
405
413
406
414
/**
0 commit comments