Skip to content

Commit

Permalink
Support "default" for tcpNoDelay and tcpKeepAlive
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kimchy authored and areek committed Sep 8, 2014
1 parent 02d3e3c commit 5c575f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
6 changes: 3 additions & 3 deletions docs/reference/modules/network.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ share the following allowed settings:
|=======================================================================
|Setting |Description
|`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
not explicitly set.
|`network.tcp.keep_alive` |Enable or disable tcp keep alive. Defaults
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.
Defaults to `true` on non-windows machines.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.http.netty;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.netty.NettyUtils;
Expand Down Expand Up @@ -88,10 +89,8 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer

private final String publishHost;

private final Boolean tcpNoDelay;

private final Boolean tcpKeepAlive;

private final String tcpNoDelay;
private final String tcpKeepAlive;
private final Boolean reuseAddress;

private final ByteSizeValue tcpSendBufferSize;
Expand Down Expand Up @@ -135,8 +134,8 @@ public NettyHttpServerTransport(Settings settings, NetworkService networkService
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.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.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, true));
this.tcpNoDelay = componentSettings.get("tcp_no_delay", settings.get(TCP_NO_DELAY, "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.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));
Expand Down Expand Up @@ -197,11 +196,11 @@ protected void doStart() throws ElasticsearchException {

serverBootstrap.setPipelineFactory(configureServerChannelPipelineFactory());

if (tcpNoDelay != null) {
serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
if (!"default".equals(tcpNoDelay)) {
serverBootstrap.setOption("child.tcpNoDelay", Booleans.parseBoolean(tcpNoDelay, null));
}
if (tcpKeepAlive != null) {
serverBootstrap.setOption("child.keepAlive", tcpKeepAlive);
if (!"default".equals(tcpKeepAlive)) {
serverBootstrap.setOption("child.keepAlive", Booleans.parseBoolean(tcpKeepAlive, null));
}
if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) {
serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize.bytes());
Expand Down
28 changes: 13 additions & 15 deletions src/main/java/org/elasticsearch/transport/netty/NettyTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.Lists;
import org.elasticsearch.*;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.ReleasableBytesReference;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
Expand Down Expand Up @@ -128,11 +129,8 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
final boolean compress;

final TimeValue connectTimeout;

final Boolean tcpNoDelay;

final Boolean tcpKeepAlive;

final String tcpNoDelay;
final String tcpKeepAlive;
final Boolean reuseAddress;

final ByteSizeValue tcpSendBufferSize;
Expand Down Expand Up @@ -196,8 +194,8 @@ public NettyTransport(Settings settings, ThreadPool threadPool, NetworkService n
this.publishPort = componentSettings.getAsInt("publish_port", settings.getAsInt("transport.publish_port", 0));
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.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true));
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, true));
this.tcpNoDelay = componentSettings.get("tcp_no_delay", settings.get(TCP_NO_DELAY, "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.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));
Expand Down Expand Up @@ -271,11 +269,11 @@ protected void doStart() throws ElasticsearchException {
}
clientBootstrap.setPipelineFactory(configureClientChannelPipelineFactory());
clientBootstrap.setOption("connectTimeoutMillis", connectTimeout.millis());
if (tcpNoDelay != null) {
clientBootstrap.setOption("tcpNoDelay", tcpNoDelay);
if (!"default".equals(tcpNoDelay)) {
clientBootstrap.setOption("tcpNoDelay", Booleans.parseBoolean(tcpNoDelay, null));
}
if (tcpKeepAlive != null) {
clientBootstrap.setOption("keepAlive", tcpKeepAlive);
if (!"default".equals(tcpKeepAlive)) {
clientBootstrap.setOption("keepAlive", Booleans.parseBoolean(tcpKeepAlive, null));
}
if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) {
clientBootstrap.setOption("sendBufferSize", tcpSendBufferSize.bytes());
Expand Down Expand Up @@ -306,11 +304,11 @@ protected void doStart() throws ElasticsearchException {
workerCount));
}
serverBootstrap.setPipelineFactory(configureServerChannelPipelineFactory());
if (tcpNoDelay != null) {
serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
if (!"default".equals(tcpNoDelay)) {
serverBootstrap.setOption("child.tcpNoDelay", Booleans.parseBoolean(tcpNoDelay, null));
}
if (tcpKeepAlive != null) {
serverBootstrap.setOption("child.keepAlive", tcpKeepAlive);
if (!"default".equals(tcpKeepAlive)) {
serverBootstrap.setOption("child.keepAlive", Booleans.parseBoolean(tcpKeepAlive, null));
}
if (tcpSendBufferSize != null && tcpSendBufferSize.bytes() > 0) {
serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize.bytes());
Expand Down

0 comments on commit 5c575f5

Please sign in to comment.