Skip to content

Commit 9967ad8

Browse files
author
zengqiang.xu
committed
HDFS-16703. Enable RPC Timeout for some protocols of NameNode.
1 parent be4c638 commit 9967ad8

File tree

4 files changed

+151
-9
lines changed

4 files changed

+151
-9
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/NameNodeProxiesClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.hadoop.hdfs.server.namenode.ha.ClientHAProxyFactory;
3333
import org.apache.hadoop.hdfs.server.namenode.ha.HAProxyFactory;
3434
import org.apache.hadoop.ipc.AlignmentContext;
35+
import org.apache.hadoop.ipc.Client;
3536
import org.slf4j.Logger;
3637
import org.slf4j.LoggerFactory;
3738

@@ -365,7 +366,7 @@ public static ClientProtocol createProxyWithAlignmentContext(
365366
ClientNamenodeProtocolPB proxy = RPC.getProtocolProxy(
366367
ClientNamenodeProtocolPB.class, version, address, ugi, conf,
367368
NetUtils.getDefaultSocketFactory(conf),
368-
org.apache.hadoop.ipc.Client.getTimeout(conf), defaultPolicy,
369+
Client.getRpcTimeout(conf), defaultPolicy,
369370
fallbackToSimpleAuth, alignmentContext).getProxy();
370371

371372
if (withRetries) { // create the proxy with retries

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,5 +2031,33 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
20312031
public static final long DFS_LEASE_HARDLIMIT_DEFAULT =
20322032
HdfsClientConfigKeys.DFS_LEASE_HARDLIMIT_DEFAULT;
20332033

2034+
public static final String IPC_RPC_TIMEOUT_FOR_ALIASHMAP_PROTOCOL =
2035+
"ipc.rpc-timeout.for.aliash-map.ms";
2036+
public static final long IPC_RPC_TIMEOUT_FOR_ALIASHMAP_PROTOCOL_DEFAULT =
2037+
TimeUnit.SECONDS.toMillis(30);
2038+
public static final String IPC_RPC_TIMEOUT_FOR_JOURNAL_PROTOCOL =
2039+
"ipc.rpc-timeout.for.journal.ms";
2040+
public static final long IPC_RPC_TIMEOUT_FOR_JOURNAL_PROTOCOL_DEFAULT =
2041+
TimeUnit.SECONDS.toMillis(30);
2042+
public static final String IPC_RPC_TIMEOUT_FOR_REFRESH_AUTHORIZATION_PROTOCOL =
2043+
"ipc.rpc-timeout.for.refresh-authorization.ms";
2044+
public static final long IPC_RPC_TIMEOUT_FOR_REFRESH_AUTHORIZATION_PROTOCOL_DEFAULT =
2045+
TimeUnit.SECONDS.toMillis(0);
2046+
public static final String IPC_RPC_TIMEOUT_FOR_REFRESH_USER_MAPPING_PROTOCOL =
2047+
"ipc.rpc-timeout.for.refresh-user-mappings.ms";
2048+
public static final long IPC_RPC_TIMEOUT_FOR_REFRESH_USER_MAPPING_PROTOCOL_DEFAULT =
2049+
TimeUnit.SECONDS.toMillis(0);
2050+
public static final String IPC_RPC_TIMEOUT_FOR_REFRESH_CALL_QUEUE_PROTOCOL =
2051+
"ipc.rpc-timeout.for.refresh-call-queue.ms";
2052+
public static final long IPC_RPC_TIMEOUT_FOR_REFRESH_CALL_QUEUE_PROTOCOL_DEFAULT =
2053+
TimeUnit.SECONDS.toMillis(0);
2054+
public static final String IPC_RPC_TIMEOUT_FOR_GET_USER_MAPPING_PROTOCOL =
2055+
"ipc.rpc-timeout.for.get-user-mappings.ms";
2056+
public static final long IPC_RPC_TIMEOUT_FOR_GET_USER_MAPPING_PROTOCOL_DEFAULT =
2057+
TimeUnit.SECONDS.toMillis(0);
2058+
public static final String IPC_RPC_TIMEOUT_FOR_NAMENODE_PROTOCOL =
2059+
"ipc.rpc-timeout.for.namenode.ms";
2060+
public static final long IPC_RPC_TIMEOUT_FOR_NAMENODE_PROTOCOL_DEFAULT =
2061+
TimeUnit.SECONDS.toMillis(0);
20342062

20352063
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/NameNodeProxies.java

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,34 @@ public static <T> ProxyAndInfo<T> createNonHAProxy(
217217
private static InMemoryAliasMapProtocol createNNProxyWithInMemoryAliasMapProtocol(
218218
InetSocketAddress address, Configuration conf, UserGroupInformation ugi,
219219
AlignmentContext alignmentContext) throws IOException {
220+
int timeout = getRPCTimeout(conf,
221+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_ALIASHMAP_PROTOCOL,
222+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_ALIASHMAP_PROTOCOL_DEFAULT);
220223
AliasMapProtocolPB proxy = createNameNodeProxy(
221-
address, conf, ugi, AliasMapProtocolPB.class, 30000, alignmentContext);
224+
address, conf, ugi, AliasMapProtocolPB.class, timeout, alignmentContext);
222225
return new InMemoryAliasMapProtocolClientSideTranslatorPB(proxy);
223226
}
224227

225228
private static JournalProtocol createNNProxyWithJournalProtocol(
226229
InetSocketAddress address, Configuration conf, UserGroupInformation ugi,
227230
AlignmentContext alignmentContext) throws IOException {
231+
int timeout = getRPCTimeout(conf,
232+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_JOURNAL_PROTOCOL,
233+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_JOURNAL_PROTOCOL_DEFAULT);
228234
JournalProtocolPB proxy = createNameNodeProxy(address,
229-
conf, ugi, JournalProtocolPB.class, 30000, alignmentContext);
235+
conf, ugi, JournalProtocolPB.class, timeout, alignmentContext);
230236
return new JournalProtocolTranslatorPB(proxy);
231237
}
232238

233239
private static RefreshAuthorizationPolicyProtocol
234240
createNNProxyWithRefreshAuthorizationPolicyProtocol(InetSocketAddress address,
235241
Configuration conf, UserGroupInformation ugi,
236242
AlignmentContext alignmentContext) throws IOException {
243+
int timeout = getRPCTimeout(conf,
244+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_REFRESH_AUTHORIZATION_PROTOCOL,
245+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_REFRESH_AUTHORIZATION_PROTOCOL_DEFAULT);
237246
RefreshAuthorizationPolicyProtocolPB proxy = createNameNodeProxy(address,
238-
conf, ugi, RefreshAuthorizationPolicyProtocolPB.class, 0,
247+
conf, ugi, RefreshAuthorizationPolicyProtocolPB.class, timeout,
239248
alignmentContext);
240249
return new RefreshAuthorizationPolicyProtocolClientSideTranslatorPB(proxy);
241250
}
@@ -244,34 +253,46 @@ private static JournalProtocol createNNProxyWithJournalProtocol(
244253
createNNProxyWithRefreshUserMappingsProtocol(InetSocketAddress address,
245254
Configuration conf, UserGroupInformation ugi,
246255
AlignmentContext alignmentContext) throws IOException {
256+
int timeout = getRPCTimeout(conf,
257+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_REFRESH_USER_MAPPING_PROTOCOL,
258+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_REFRESH_USER_MAPPING_PROTOCOL_DEFAULT);
247259
RefreshUserMappingsProtocolPB proxy = createNameNodeProxy(address, conf,
248-
ugi, RefreshUserMappingsProtocolPB.class, 0, alignmentContext);
260+
ugi, RefreshUserMappingsProtocolPB.class, timeout, alignmentContext);
249261
return new RefreshUserMappingsProtocolClientSideTranslatorPB(proxy);
250262
}
251263

252264
private static RefreshCallQueueProtocol
253265
createNNProxyWithRefreshCallQueueProtocol(InetSocketAddress address,
254266
Configuration conf, UserGroupInformation ugi,
255267
AlignmentContext alignmentContext) throws IOException {
268+
int timeout = getRPCTimeout(conf,
269+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_REFRESH_CALL_QUEUE_PROTOCOL,
270+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_REFRESH_CALL_QUEUE_PROTOCOL_DEFAULT);
256271
RefreshCallQueueProtocolPB proxy = createNameNodeProxy(address, conf, ugi,
257-
RefreshCallQueueProtocolPB.class, 0, alignmentContext);
272+
RefreshCallQueueProtocolPB.class, timeout, alignmentContext);
258273
return new RefreshCallQueueProtocolClientSideTranslatorPB(proxy);
259274
}
260275

261276
private static GetUserMappingsProtocol createNNProxyWithGetUserMappingsProtocol(
262277
InetSocketAddress address, Configuration conf, UserGroupInformation ugi,
263278
AlignmentContext alignmentContext) throws IOException {
279+
int timeout = getRPCTimeout(conf,
280+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_GET_USER_MAPPING_PROTOCOL,
281+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_GET_USER_MAPPING_PROTOCOL_DEFAULT);
264282
GetUserMappingsProtocolPB proxy = createNameNodeProxy(address, conf, ugi,
265-
GetUserMappingsProtocolPB.class, 0, alignmentContext);
283+
GetUserMappingsProtocolPB.class, timeout, alignmentContext);
266284
return new GetUserMappingsProtocolClientSideTranslatorPB(proxy);
267285
}
268286

269287
private static NamenodeProtocol createNNProxyWithNamenodeProtocol(
270288
InetSocketAddress address, Configuration conf, UserGroupInformation ugi,
271289
boolean withRetries, AlignmentContext alignmentContext)
272290
throws IOException {
273-
NamenodeProtocolPB proxy = createNameNodeProxy(
274-
address, conf, ugi, NamenodeProtocolPB.class, 0, alignmentContext);
291+
int timeout = getRPCTimeout(conf,
292+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_NAMENODE_PROTOCOL,
293+
DFSConfigKeys.IPC_RPC_TIMEOUT_FOR_NAMENODE_PROTOCOL_DEFAULT);
294+
NamenodeProtocolPB proxy = createNameNodeProxy(address, conf, ugi,
295+
NamenodeProtocolPB.class, timeout, alignmentContext);
275296
if (withRetries) { // create the proxy with retries
276297
RetryPolicy timeoutPolicy = RetryPolicies.exponentialBackoffRetry(5, 200,
277298
TimeUnit.MILLISECONDS);
@@ -312,4 +333,21 @@ private static <T> T createNameNodeProxy(InetSocketAddress address,
312333
alignmentContext).getProxy();
313334
}
314335

336+
/**
337+
* Try to obtain the timeout for confKey from Conf.
338+
* If the value is invalid, just print some warn log and return the default value.
339+
* @param conf input Configuration.
340+
* @param confKey input conf key.
341+
* @param defaultValue input default conf value.
342+
* @return a non negative number.
343+
*/
344+
private static int getRPCTimeout(Configuration conf, String confKey, long defaultValue) {
345+
long tmpTimeout = conf.getTimeDuration(confKey, defaultValue, TimeUnit.MILLISECONDS);
346+
if (tmpTimeout < 0) {
347+
LOG.warn("Invalid value {} configured for {} should be greater than or equal to 0. " +
348+
"Using default value of : {}ms instead.", tmpTimeout, conf, defaultValue);
349+
tmpTimeout = defaultValue;
350+
}
351+
return (int) tmpTimeout;
352+
}
315353
}

hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6462,4 +6462,79 @@
64626462
If the namespace is DEFAULT, it's best to change this conf to other value.
64636463
</description>
64646464
</property>
6465+
<property>
6466+
<name>ipc.rpc-timeout.for.aliash-map.ms</name>
6467+
<value>30s</value>
6468+
</property>
6469+
<property>
6470+
<description>
6471+
The amount of time the aliasMapProtocol client will wait to read from the namenode
6472+
before timing out. If the namenode does not report progress more
6473+
frequently than this time, the client will give up waiting.
6474+
</description>
6475+
</property>
6476+
<property>
6477+
<name>ipc.rpc-timeout.for.journal.ms</name>
6478+
<value>30s</value>
6479+
<description>
6480+
The amount of time the journalProtocol client will wait to read from the journalnode
6481+
before timing out. If the journalnode does not report progress more
6482+
frequently than this time, the client will give up waiting.
6483+
</description>
6484+
</property>
6485+
<property>
6486+
<name>ipc.rpc-timeout.for.refresh-authorization.ms</name>
6487+
<value>0s</value>
6488+
<description>
6489+
The amount of time the refreshAuthorizationPolicyProtocol client will wait
6490+
to read from the namenode before timing out. If the namenode does not
6491+
report progress more frequently than this time, the client will give up waiting.
6492+
The default value of 0 indicates that timeout is disabled,
6493+
which can be set to the same as ipc.client.rpc-timeout.ms, such as 120s.
6494+
</description>
6495+
</property>
6496+
<property>
6497+
<name>ipc.rpc-timeout.for.refresh-user-mappings.ms</name>
6498+
<value>0s</value>
6499+
<description>
6500+
The amount of time the refreshUserMappingsProtocol client will wait
6501+
to read from the namenode before timing out. If the namenode does not
6502+
report progress more frequently than this time, the client will give up waiting.
6503+
The default value of 0 indicates that timeout is disabled,
6504+
which can be set to the same as ipc.client.rpc-timeout.ms, such as 120s.
6505+
</description>
6506+
</property>
6507+
<property>
6508+
<name>ipc.rpc-timeout.for.refresh-call-queue.ms</name>
6509+
<value>0s</value>
6510+
<description>
6511+
The amount of time the refreshCallQueueProtocol client will wait
6512+
to read from the namenode before timing out. If the namenode does not
6513+
report progress more frequently than this time, the client will give up waiting.
6514+
The default value of 0 indicates that timeout is disabled,
6515+
which can be set to the same as ipc.client.rpc-timeout.ms, such as 120s.
6516+
</description>
6517+
</property>
6518+
<property>
6519+
<name>ipc.rpc-timeout.for.get-user-mappings.ms</name>
6520+
<value>0s</value>
6521+
<description>
6522+
The amount of time the getUserMappingsProtocol client will wait
6523+
to read from the namenode before timing out. If the namenode does not
6524+
report progress more frequently than this time, the client will give up waiting.
6525+
The default value of 0 indicates that timeout is disabled,
6526+
which can be set to the same as ipc.client.rpc-timeout.ms, such as 120s.
6527+
</description>
6528+
</property>
6529+
<property>
6530+
<name>ipc.rpc-timeout.for.namenode.ms</name>
6531+
<value>0s</value>
6532+
<description>
6533+
The amount of time the namenodeProtocol client will wait
6534+
to read from the namenode before timing out. If the namenode does not
6535+
report progress more frequently than this time, the client will give up waiting.
6536+
The default value of 0 indicates that timeout is disabled,
6537+
which can be set to the same as ipc.client.rpc-timeout.ms, such as 120s.
6538+
</description>
6539+
</property>
64656540
</configuration>

0 commit comments

Comments
 (0)