HADOOP-9106. Merge 1433747 from trunk.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1433752 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2013-01-15 23:59:43 +00:00
parent 2324fb59b5
commit 93100304eb
5 changed files with 51 additions and 4 deletions

View File

@ -121,6 +121,9 @@ Release 2.0.3-alpha - Unreleased
HADOOP-8712. Change default hadoop.security.group.mapping to HADOOP-8712. Change default hadoop.security.group.mapping to
JniBasedUnixGroupsNetgroupMappingWithFallback (Robert Parker via todd) JniBasedUnixGroupsNetgroupMappingWithFallback (Robert Parker via todd)
HADOOP-9106. Allow configuration of IPC connect timeout.
(Rober Parker via suresh)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang

View File

@ -171,6 +171,11 @@ public class CommonConfigurationKeysPublic {
/** Default value for IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY */ /** Default value for IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY */
public static final int IPC_CLIENT_CONNECTION_MAXIDLETIME_DEFAULT = 10000; // 10s public static final int IPC_CLIENT_CONNECTION_MAXIDLETIME_DEFAULT = 10000; // 10s
/** See <a href="{@docRoot}/../core-default.html">core-default.xml</a> */ /** See <a href="{@docRoot}/../core-default.html">core-default.xml</a> */
public static final String IPC_CLIENT_CONNECT_TIMEOUT_KEY =
"ipc.client.connect.timeout";
/** Default value for IPC_CLIENT_CONNECT_TIMEOUT_KEY */
public static final int IPC_CLIENT_CONNECT_TIMEOUT_DEFAULT = 20000; // 20s
/** See <a href="{@docRoot}/../core-default.html">core-default.xml</a> */
public static final String IPC_CLIENT_CONNECT_MAX_RETRIES_KEY = public static final String IPC_CLIENT_CONNECT_MAX_RETRIES_KEY =
"ipc.client.connect.max.retries"; "ipc.client.connect.max.retries";
/** Default value for IPC_CLIENT_CONNECT_MAX_RETRIES_KEY */ /** Default value for IPC_CLIENT_CONNECT_MAX_RETRIES_KEY */

View File

@ -106,6 +106,8 @@ public class Client {
private SocketFactory socketFactory; // how to create sockets private SocketFactory socketFactory; // how to create sockets
private int refCount = 1; private int refCount = 1;
private final int connectionTimeout;
final static int PING_CALL_ID = -1; final static int PING_CALL_ID = -1;
/** /**
@ -158,6 +160,15 @@ public class Client {
} }
return -1; return -1;
} }
/**
* set the connection timeout value in configuration
*
* @param conf Configuration
* @param timeout the socket connect timeout value
*/
public static final void setConnectTimeout(Configuration conf, int timeout) {
conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_TIMEOUT_KEY, timeout);
}
/** /**
* Increment this client's reference count * Increment this client's reference count
@ -493,8 +504,7 @@ public class Client {
} }
} }
// connection time out is 20s NetUtils.connect(this.socket, server, connectionTimeout);
NetUtils.connect(this.socket, server, 20000);
if (rpcTimeout > 0) { if (rpcTimeout > 0) {
pingInterval = rpcTimeout; // rpcTimeout overwrites pingInterval pingInterval = rpcTimeout; // rpcTimeout overwrites pingInterval
} }
@ -1032,6 +1042,8 @@ public class Client {
this.valueClass = valueClass; this.valueClass = valueClass;
this.conf = conf; this.conf = conf;
this.socketFactory = factory; this.socketFactory = factory;
this.connectionTimeout = conf.getInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_TIMEOUT_KEY,
CommonConfigurationKeys.IPC_CLIENT_CONNECT_TIMEOUT_DEFAULT);
} }
/** /**

View File

@ -565,6 +565,14 @@
</description> </description>
</property> </property>
<property>
<name>ipc.client.connect.timeout</name>
<value>20000</value>
<description>Indicates the number of milliseconds a client will wait for the
socket to establish a server connection.
</description>
</property>
<property> <property>
<name>ipc.client.connect.max.retries.on.timeouts</name> <name>ipc.client.connect.max.retries.on.timeouts</name>
<value>45</value> <value>45</value>

View File

@ -62,7 +62,6 @@ public class TestIPC {
final private static Configuration conf = new Configuration(); final private static Configuration conf = new Configuration();
final static private int PING_INTERVAL = 1000; final static private int PING_INTERVAL = 1000;
final static private int MIN_SLEEP_TIME = 1000; final static private int MIN_SLEEP_TIME = 1000;
/** /**
* Flag used to turn off the fault injection behavior * Flag used to turn off the fault injection behavior
* of the various writables. * of the various writables.
@ -500,6 +499,26 @@ public class TestIPC {
addr, null, null, 3*PING_INTERVAL+MIN_SLEEP_TIME, conf); addr, null, null, 3*PING_INTERVAL+MIN_SLEEP_TIME, conf);
} }
@Test
public void testIpcConnectTimeout() throws Exception {
// start server
Server server = new TestServer(1, true);
InetSocketAddress addr = NetUtils.getConnectAddress(server);
//Intentionally do not start server to get a connection timeout
// start client
Client.setConnectTimeout(conf, 100);
Client client = new Client(LongWritable.class, conf);
// set the rpc timeout to twice the MIN_SLEEP_TIME
try {
client.call(new LongWritable(RANDOM.nextLong()),
addr, null, null, MIN_SLEEP_TIME*2, conf);
fail("Expected an exception to have been thrown");
} catch (SocketTimeoutException e) {
LOG.info("Get a SocketTimeoutException ", e);
}
}
/** /**
* Check that file descriptors aren't leaked by starting * Check that file descriptors aren't leaked by starting
* and stopping IPC servers. * and stopping IPC servers.