HADOOP-16238. Add the possbility to set SO_REUSEADDR in IPC Server Listener. Contributed by Peter Bacsko.

Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org>
This commit is contained in:
Peter Bacsko 2019-05-07 17:47:46 -07:00 committed by Wei-Chiu Chuang
parent c4be3ea276
commit 713e8a27ae
3 changed files with 22 additions and 0 deletions

View File

@ -425,6 +425,15 @@ public class CommonConfigurationKeysPublic {
"ipc.server.tcpnodelay";
/** Default value for IPC_SERVER_TCPNODELAY_KEY */
public static final boolean IPC_SERVER_TCPNODELAY_DEFAULT = true;
/**
* @see
* <a href="{@docRoot}/../hadoop-project-dist/hadoop-common/core-default.xml">
* core-default.xml</a>
*/
public static final String IPC_SERVER_REUSEADDR_KEY =
"ipc.server.reuseaddr";
/** Default value for IPC_SERVER_REUSEADDR_KEY. */
public static final boolean IPC_SERVER_REUSEADDR_DEFAULT = true;
/**
* @see
* <a href="{@docRoot}/../hadoop-project-dist/hadoop-common/core-default.xml">

View File

@ -35,6 +35,7 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.StandardSocketOptions;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.CancelledKeyException;
@ -1105,12 +1106,16 @@ public abstract class Server {
private int backlogLength = conf.getInt(
CommonConfigurationKeysPublic.IPC_SERVER_LISTEN_QUEUE_SIZE_KEY,
CommonConfigurationKeysPublic.IPC_SERVER_LISTEN_QUEUE_SIZE_DEFAULT);
private boolean reuseAddr = conf.getBoolean(
CommonConfigurationKeysPublic.IPC_SERVER_REUSEADDR_KEY,
CommonConfigurationKeysPublic.IPC_SERVER_REUSEADDR_DEFAULT);
Listener(int port) throws IOException {
address = new InetSocketAddress(bindAddress, port);
// Create a new server socket and set to non blocking mode
acceptChannel = ServerSocketChannel.open();
acceptChannel.configureBlocking(false);
acceptChannel.setOption(StandardSocketOptions.SO_REUSEADDR, reuseAddr);
// Bind the server socket to the local host and port
bind(acceptChannel.socket(), address, backlogLength, conf, portRangeConfig);

View File

@ -2208,6 +2208,14 @@
</description>
</property>
<property>
<name>ipc.server.reuseaddr</name>
<value>true</value>
<description>Enables the SO_REUSEADDR TCP option on the server.
Useful if BindException often prevents a certain service to be restarted
because the server side is stuck in TIME_WAIT state.
</description>
</property>
<!-- Proxy Configuration -->
<property>