2929import org .elasticsearch .action .support .PlainActionFuture ;
3030import org .elasticsearch .cluster .node .DiscoveryNode ;
3131import org .elasticsearch .common .Booleans ;
32- import org .elasticsearch .common .Nullable ;
3332import org .elasticsearch .common .Strings ;
3433import org .elasticsearch .common .breaker .CircuitBreaker ;
3534import org .elasticsearch .common .bytes .BytesArray ;
@@ -135,30 +134,16 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
135134 // the scheduled internal ping interval setting, defaults to disabled (-1)
136135 public static final Setting <TimeValue > PING_SCHEDULE =
137136 timeSetting ("transport.ping_schedule" , TimeValue .timeValueSeconds (-1 ), Setting .Property .NodeScope );
138- public static final Setting <Integer > CONNECTIONS_PER_NODE_RECOVERY =
139- intSetting ("transport.connections_per_node.recovery" , 2 , 1 , Setting .Property .NodeScope );
140- public static final Setting <Integer > CONNECTIONS_PER_NODE_BULK =
141- intSetting ("transport.connections_per_node.bulk" , 3 , 1 , Setting .Property .NodeScope );
142- public static final Setting <Integer > CONNECTIONS_PER_NODE_REG =
143- intSetting ("transport.connections_per_node.reg" , 6 , 1 , Setting .Property .NodeScope );
144- public static final Setting <Integer > CONNECTIONS_PER_NODE_STATE =
145- intSetting ("transport.connections_per_node.state" , 1 , 1 , Setting .Property .NodeScope );
146- public static final Setting <Integer > CONNECTIONS_PER_NODE_PING =
147- intSetting ("transport.connections_per_node.ping" , 1 , 1 , Setting .Property .NodeScope );
148- public static final Setting <TimeValue > TCP_CONNECT_TIMEOUT =
149- timeSetting ("transport.tcp.connect_timeout" , NetworkService .TCP_CONNECT_TIMEOUT , Setting .Property .NodeScope );
150137 public static final Setting <Boolean > TCP_NO_DELAY =
151138 boolSetting ("transport.tcp_no_delay" , NetworkService .TCP_NO_DELAY , Setting .Property .NodeScope );
152139 public static final Setting <Boolean > TCP_KEEP_ALIVE =
153140 boolSetting ("transport.tcp.keep_alive" , NetworkService .TCP_KEEP_ALIVE , Setting .Property .NodeScope );
154141 public static final Setting <Boolean > TCP_REUSE_ADDRESS =
155142 boolSetting ("transport.tcp.reuse_address" , NetworkService .TCP_REUSE_ADDRESS , Setting .Property .NodeScope );
156143 public static final Setting <ByteSizeValue > TCP_SEND_BUFFER_SIZE =
157- Setting .byteSizeSetting ("transport.tcp.send_buffer_size" , NetworkService .TCP_SEND_BUFFER_SIZE ,
158- Setting .Property .NodeScope );
144+ Setting .byteSizeSetting ("transport.tcp.send_buffer_size" , NetworkService .TCP_SEND_BUFFER_SIZE , Setting .Property .NodeScope );
159145 public static final Setting <ByteSizeValue > TCP_RECEIVE_BUFFER_SIZE =
160- Setting .byteSizeSetting ("transport.tcp.receive_buffer_size" , NetworkService .TCP_RECEIVE_BUFFER_SIZE ,
161- Setting .Property .NodeScope );
146+ Setting .byteSizeSetting ("transport.tcp.receive_buffer_size" , NetworkService .TCP_RECEIVE_BUFFER_SIZE , Setting .Property .NodeScope );
162147
163148
164149 public static final Setting .AffixSetting <Boolean > TCP_NO_DELAY_PROFILE = affixKeySetting ("transport.profiles." , "tcp_no_delay" ,
@@ -213,7 +198,6 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
213198 protected final boolean compress ;
214199 private volatile BoundTransportAddress boundAddress ;
215200 private final String transportName ;
216- protected final ConnectionProfile defaultConnectionProfile ;
217201
218202 private final ConcurrentMap <Long , HandshakeResponseHandler > pendingHandshakes = new ConcurrentHashMap <>();
219203 private final CounterMetric numHandshakes = new CounterMetric ();
@@ -237,7 +221,6 @@ public TcpTransport(String transportName, Settings settings, ThreadPool threadPo
237221 this .compress = Transport .TRANSPORT_TCP_COMPRESS .get (settings );
238222 this .networkService = networkService ;
239223 this .transportName = transportName ;
240- defaultConnectionProfile = buildDefaultConnectionProfile (settings );
241224 final Settings defaultFeatures = DEFAULT_FEATURES_SETTING .get (settings );
242225 if (defaultFeatures == null ) {
243226 this .features = new String [0 ];
@@ -261,25 +244,6 @@ public TcpTransport(String transportName, Settings settings, ThreadPool threadPo
261244 }
262245 }
263246
264- static ConnectionProfile buildDefaultConnectionProfile (Settings settings ) {
265- int connectionsPerNodeRecovery = CONNECTIONS_PER_NODE_RECOVERY .get (settings );
266- int connectionsPerNodeBulk = CONNECTIONS_PER_NODE_BULK .get (settings );
267- int connectionsPerNodeReg = CONNECTIONS_PER_NODE_REG .get (settings );
268- int connectionsPerNodeState = CONNECTIONS_PER_NODE_STATE .get (settings );
269- int connectionsPerNodePing = CONNECTIONS_PER_NODE_PING .get (settings );
270- ConnectionProfile .Builder builder = new ConnectionProfile .Builder ();
271- builder .setConnectTimeout (TCP_CONNECT_TIMEOUT .get (settings ));
272- builder .setHandshakeTimeout (TCP_CONNECT_TIMEOUT .get (settings ));
273- builder .addConnections (connectionsPerNodeBulk , TransportRequestOptions .Type .BULK );
274- builder .addConnections (connectionsPerNodePing , TransportRequestOptions .Type .PING );
275- // if we are not master eligible we don't need a dedicated channel to publish the state
276- builder .addConnections (DiscoveryNode .isMasterNode (settings ) ? connectionsPerNodeState : 0 , TransportRequestOptions .Type .STATE );
277- // if we are not a data-node we don't need any dedicated channels for recovery
278- builder .addConnections (DiscoveryNode .isDataNode (settings ) ? connectionsPerNodeRecovery : 0 , TransportRequestOptions .Type .RECOVERY );
279- builder .addConnections (connectionsPerNodeReg , TransportRequestOptions .Type .REG );
280- return builder .build ();
281- }
282-
283247 @ Override
284248 protected void doStart () {
285249 }
@@ -456,41 +420,21 @@ public void sendRequest(long requestId, String action, TransportRequest request,
456420 }
457421 }
458422
459- /**
460- * takes a {@link ConnectionProfile} that have been passed as a parameter to the public methods
461- * and resolves it to a fully specified (i.e., no nulls) profile
462- */
463- protected static ConnectionProfile resolveConnectionProfile (@ Nullable ConnectionProfile connectionProfile ,
464- ConnectionProfile defaultConnectionProfile ) {
465- Objects .requireNonNull (defaultConnectionProfile );
466- if (connectionProfile == null ) {
467- return defaultConnectionProfile ;
468- } else if (connectionProfile .getConnectTimeout () != null && connectionProfile .getHandshakeTimeout () != null ) {
469- return connectionProfile ;
470- } else {
471- ConnectionProfile .Builder builder = new ConnectionProfile .Builder (connectionProfile );
472- if (connectionProfile .getConnectTimeout () == null ) {
473- builder .setConnectTimeout (defaultConnectionProfile .getConnectTimeout ());
474- }
475- if (connectionProfile .getHandshakeTimeout () == null ) {
476- builder .setHandshakeTimeout (defaultConnectionProfile .getHandshakeTimeout ());
477- }
478- return builder .build ();
479- }
480- }
481-
482- protected ConnectionProfile resolveConnectionProfile (ConnectionProfile connectionProfile ) {
483- return resolveConnectionProfile (connectionProfile , defaultConnectionProfile );
423+ // This allows transport implementations to potentially override specific connection profiles. This
424+ // primarily exists for the test implementations.
425+ protected ConnectionProfile maybeOverrideConnectionProfile (ConnectionProfile connectionProfile ) {
426+ return connectionProfile ;
484427 }
485428
486429 @ Override
487430 public NodeChannels openConnection (DiscoveryNode node , ConnectionProfile connectionProfile ) {
431+ Objects .requireNonNull (connectionProfile , "connection profile cannot be null" );
488432 if (node == null ) {
489433 throw new ConnectTransportException (null , "can't open connection to a null node" );
490434 }
491435 boolean success = false ;
492436 NodeChannels nodeChannels = null ;
493- connectionProfile = resolveConnectionProfile (connectionProfile );
437+ connectionProfile = maybeOverrideConnectionProfile (connectionProfile );
494438 closeLock .readLock ().lock (); // ensure we don't open connections while we are closing
495439 try {
496440 ensureOpen ();
0 commit comments