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:
parent
c4be3ea276
commit
713e8a27ae
@ -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">
|
||||
|
@ -35,6 +35,7 @@
|
||||
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 @@ private class Listener extends Thread {
|
||||
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);
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user