Support "default" for tcpNoDelay and tcpKeepAlive

Allow to set the value default to network.tcp.no_delay and network.tcp.keep_alive so they won't be set at all, since on solaris, setting tcpNoDelay can actually cause failure
relates to #7115
This commit is contained in:
Shay Banon 2014-08-02 17:26:48 +02:00
parent 5ccc7beaf4
commit 95762e8126
3 changed files with 25 additions and 28 deletions

View File

@ -72,10 +72,10 @@ share the following allowed settings:
|======================================================================= |=======================================================================
|Setting |Description |Setting |Description
|`network.tcp.no_delay` |Enable or disable tcp no delay setting. |`network.tcp.no_delay` |Enable or disable tcp no delay setting.
Defaults to `true`. Defaults to `true`. coming[1.4,Can be set to `default` to not be set at all.]
|`network.tcp.keep_alive` |Enable or disable tcp keep alive. By default |`network.tcp.keep_alive` |Enable or disable tcp keep alive. Defaults
not explicitly set. to `true`. coming[1.4,Can be set to `default` to not be set at all].
|`network.tcp.reuse_address` |Should an address be reused or not. |`network.tcp.reuse_address` |Should an address be reused or not.
Defaults to `true` on non-windows machines. Defaults to `true` on non-windows machines.

View File

@ -20,6 +20,7 @@
package org.elasticsearch.http.netty; package org.elasticsearch.http.netty;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.netty.NettyUtils; import org.elasticsearch.common.netty.NettyUtils;
@ -88,10 +89,8 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
private final String publishHost; private final String publishHost;
private final Boolean tcpNoDelay; private final String tcpNoDelay;
private final String tcpKeepAlive;
private final Boolean tcpKeepAlive;
private final Boolean reuseAddress; private final Boolean reuseAddress;
private final ByteSizeValue tcpSendBufferSize; private final ByteSizeValue tcpSendBufferSize;
@ -135,8 +134,8 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
this.port = componentSettings.get("port", settings.get("http.port", "9200-9300")); this.port = componentSettings.get("port", settings.get("http.port", "9200-9300"));
this.bindHost = componentSettings.get("bind_host", settings.get("http.bind_host", settings.get("http.host"))); this.bindHost = componentSettings.get("bind_host", settings.get("http.bind_host", settings.get("http.host")));
this.publishHost = componentSettings.get("publish_host", settings.get("http.publish_host", settings.get("http.host"))); this.publishHost = componentSettings.get("publish_host", settings.get("http.publish_host", settings.get("http.host")));
this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true)); this.tcpNoDelay = componentSettings.get("tcp_no_delay", settings.get(TCP_NO_DELAY, "true"));
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, true)); this.tcpKeepAlive = componentSettings.get("tcp_keep_alive", settings.get(TCP_KEEP_ALIVE, "true"));
this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress())); this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
this.tcpSendBufferSize = componentSettings.getAsBytesSize("tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE)); this.tcpSendBufferSize = componentSettings.getAsBytesSize("tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE));
this.tcpReceiveBufferSize = componentSettings.getAsBytesSize("tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE)); this.tcpReceiveBufferSize = componentSettings.getAsBytesSize("tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE));
@ -197,11 +196,11 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
serverBootstrap.setPipelineFactory(configureServerChannelPipelineFactory()); serverBootstrap.setPipelineFactory(configureServerChannelPipelineFactory());
if (tcpNoDelay != null) { if (!"default".equals(tcpNoDelay)) {
serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay); serverBootstrap.setOption("child.tcpNoDelay", Booleans.parseBoolean(tcpNoDelay, null));
} }
if (tcpKeepAlive != null) { if (!"default".equals(tcpKeepAlive)) {
serverBootstrap.setOption("child.keepAlive", tcpKeepAlive); serverBootstrap.setOption("child.keepAlive", Booleans.parseBoolean(tcpKeepAlive, null));
} }
if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) { if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) {
serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize.bytes()); serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize.bytes());

View File

@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.elasticsearch.*; import org.elasticsearch.*;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.ReleasableBytesReference; import org.elasticsearch.common.bytes.ReleasableBytesReference;
import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.component.AbstractLifecycleComponent;
@ -128,11 +129,8 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
final boolean compress; final boolean compress;
final TimeValue connectTimeout; final TimeValue connectTimeout;
final String tcpNoDelay;
final Boolean tcpNoDelay; final String tcpKeepAlive;
final Boolean tcpKeepAlive;
final Boolean reuseAddress; final Boolean reuseAddress;
final ByteSizeValue tcpSendBufferSize; final ByteSizeValue tcpSendBufferSize;
@ -196,8 +194,8 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
this.publishPort = componentSettings.getAsInt("publish_port", settings.getAsInt("transport.publish_port", 0)); this.publishPort = componentSettings.getAsInt("publish_port", settings.getAsInt("transport.publish_port", 0));
this.compress = settings.getAsBoolean(TransportSettings.TRANSPORT_TCP_COMPRESS, false); this.compress = settings.getAsBoolean(TransportSettings.TRANSPORT_TCP_COMPRESS, false);
this.connectTimeout = componentSettings.getAsTime("connect_timeout", settings.getAsTime("transport.tcp.connect_timeout", settings.getAsTime(TCP_CONNECT_TIMEOUT, TCP_DEFAULT_CONNECT_TIMEOUT))); this.connectTimeout = componentSettings.getAsTime("connect_timeout", settings.getAsTime("transport.tcp.connect_timeout", settings.getAsTime(TCP_CONNECT_TIMEOUT, TCP_DEFAULT_CONNECT_TIMEOUT)));
this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true)); this.tcpNoDelay = componentSettings.get("tcp_no_delay", settings.get(TCP_NO_DELAY, "true"));
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, true)); this.tcpKeepAlive = componentSettings.get("tcp_keep_alive", settings.get(TCP_KEEP_ALIVE, "true"));
this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress())); this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
this.tcpSendBufferSize = componentSettings.getAsBytesSize("tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE)); this.tcpSendBufferSize = componentSettings.getAsBytesSize("tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE));
this.tcpReceiveBufferSize = componentSettings.getAsBytesSize("tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE)); this.tcpReceiveBufferSize = componentSettings.getAsBytesSize("tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE));
@ -271,11 +269,11 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
} }
clientBootstrap.setPipelineFactory(configureClientChannelPipelineFactory()); clientBootstrap.setPipelineFactory(configureClientChannelPipelineFactory());
clientBootstrap.setOption("connectTimeoutMillis", connectTimeout.millis()); clientBootstrap.setOption("connectTimeoutMillis", connectTimeout.millis());
if (tcpNoDelay != null) { if (!"default".equals(tcpNoDelay)) {
clientBootstrap.setOption("tcpNoDelay", tcpNoDelay); clientBootstrap.setOption("tcpNoDelay", Booleans.parseBoolean(tcpNoDelay, null));
} }
if (tcpKeepAlive != null) { if (!"default".equals(tcpKeepAlive)) {
clientBootstrap.setOption("keepAlive", tcpKeepAlive); clientBootstrap.setOption("keepAlive", Booleans.parseBoolean(tcpKeepAlive, null));
} }
if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) { if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) {
clientBootstrap.setOption("sendBufferSize", tcpSendBufferSize.bytes()); clientBootstrap.setOption("sendBufferSize", tcpSendBufferSize.bytes());
@ -306,11 +304,11 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
workerCount)); workerCount));
} }
serverBootstrap.setPipelineFactory(configureServerChannelPipelineFactory()); serverBootstrap.setPipelineFactory(configureServerChannelPipelineFactory());
if (tcpNoDelay != null) { if (!"default".equals(tcpNoDelay)) {
serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay); serverBootstrap.setOption("child.tcpNoDelay", Booleans.parseBoolean(tcpNoDelay, null));
} }
if (tcpKeepAlive != null) { if (!"default".equals(tcpKeepAlive)) {
serverBootstrap.setOption("child.keepAlive", tcpKeepAlive); serverBootstrap.setOption("child.keepAlive", Booleans.parseBoolean(tcpKeepAlive, null));
} }
if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) { if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) {
serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize.bytes()); serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize.bytes());