Skip to content

Commit 1561231

Browse files
author
Yongjun Zhang
committed
HDFS-7835. make initial sleeptime in locateFollowingBlock configurable for DFSClient. Contributed by Zhihai Xu.
1 parent 43dde50 commit 1561231

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ Release 2.8.0 - UNRELEASED
323323

324324
HDFS-2360. Ugly stacktrace when quota exceeds. (harsh)
325325

326+
HDFS-7835. make initial sleeptime in locateFollowingBlock configurable for
327+
DFSClient. (Zhihai Xu via Yongjun Zhang)
328+
326329
OPTIMIZATIONS
327330

328331
BUG FIXES

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_KEY;
2525
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_DEFAULT;
2626
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY;
27+
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_DEFAULT;
28+
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_KEY;
2729
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_RETRIES_DEFAULT;
2830
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_RETRIES_KEY;
2931
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_CACHED_CONN_RETRY_DEFAULT;
@@ -305,6 +307,7 @@ public static class Conf {
305307
final int nCachedConnRetry;
306308
final int nBlockWriteRetry;
307309
final int nBlockWriteLocateFollowingRetry;
310+
final int blockWriteLocateFollowingInitialDelayMs;
308311
final long defaultBlockSize;
309312
final long prefetchSize;
310313
final short defaultReplication;
@@ -416,6 +419,9 @@ public Conf(Configuration conf) {
416419
nBlockWriteLocateFollowingRetry = conf.getInt(
417420
DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY,
418421
DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_DEFAULT);
422+
blockWriteLocateFollowingInitialDelayMs = conf.getInt(
423+
DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_KEY,
424+
DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_DEFAULT);
419425
uMask = FsPermission.getUMask(conf);
420426
connectToDnViaHostname = conf.getBoolean(DFS_CLIENT_USE_DN_HOSTNAME,
421427
DFS_CLIENT_USE_DN_HOSTNAME_DEFAULT);
@@ -566,6 +572,11 @@ private DataChecksum createChecksum(ChecksumOpt userOpt) {
566572
}
567573
return dataChecksum;
568574
}
575+
576+
@VisibleForTesting
577+
public int getBlockWriteLocateFollowingInitialDelayMs() {
578+
return blockWriteLocateFollowingInitialDelayMs;
579+
}
569580
}
570581

571582
public Conf getConf() {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
399399
// Much code in hdfs is not yet updated to use these keys.
400400
public static final String DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY = "dfs.client.block.write.locateFollowingBlock.retries";
401401
public static final int DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_DEFAULT = 5;
402+
// the initial delay (unit is ms) for locateFollowingBlock, the delay time will increase exponentially(double) for each retry.
403+
public static final String DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_KEY = "dfs.client.block.write.locateFollowingBlock.initial.delay.ms";
404+
public static final int DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_DEFAULT = 400;
402405
public static final String DFS_CLIENT_BLOCK_WRITE_RETRIES_KEY = "dfs.client.block.write.retries";
403406
public static final int DFS_CLIENT_BLOCK_WRITE_RETRIES_DEFAULT = 3;
404407
public static final String DFS_CLIENT_MAX_BLOCK_ACQUIRE_FAILURES_KEY = "dfs.client.max.block.acquire.failures";

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,8 @@ private boolean[] getPinnings(DatanodeInfo[] nodes, boolean shouldLog) {
14331433
private LocatedBlock locateFollowingBlock(long start,
14341434
DatanodeInfo[] excludedNodes) throws IOException {
14351435
int retries = dfsClient.getConf().nBlockWriteLocateFollowingRetry;
1436-
long sleeptime = 400;
1436+
long sleeptime = dfsClient.getConf().
1437+
blockWriteLocateFollowingInitialDelayMs;
14371438
while (true) {
14381439
long localstart = Time.now();
14391440
while (true) {
@@ -2253,7 +2254,8 @@ private synchronized void closeImpl() throws IOException {
22532254
// be called during unit tests
22542255
private void completeFile(ExtendedBlock last) throws IOException {
22552256
long localstart = Time.now();
2256-
long localTimeout = 400;
2257+
long sleeptime = dfsClient.getConf().
2258+
blockWriteLocateFollowingInitialDelayMs;
22572259
boolean fileComplete = false;
22582260
int retries = dfsClient.getConf().nBlockWriteLocateFollowingRetry;
22592261
while (!fileComplete) {
@@ -2276,8 +2278,8 @@ private void completeFile(ExtendedBlock last) throws IOException {
22762278
+ " does not have enough number of replicas.");
22772279
}
22782280
retries--;
2279-
Thread.sleep(localTimeout);
2280-
localTimeout *= 2;
2281+
Thread.sleep(sleeptime);
2282+
sleeptime *= 2;
22812283
if (Time.now() - localstart > 5000) {
22822284
DFSClient.LOG.info("Could not complete " + src + " retrying...");
22832285
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,4 +2314,11 @@
23142314
<description>Whether pin blocks on favored DataNode.</description>
23152315
</property>
23162316

2317+
<property>
2318+
<name>dfs.client.block.write.locateFollowingBlock.initial.delay.ms</name>
2319+
<value>400</value>
2320+
<description>The initial delay (unit is ms) for locateFollowingBlock,
2321+
the delay time will increase exponentially(double) for each retry.
2322+
</description>
2323+
</property>
23172324
</configuration>

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,4 +1131,26 @@ static void parseMultipleLinearRandomRetry(String expected, String s) {
11311131
assertEquals("MultipleLinearRandomRetry" + expected, r.toString());
11321132
}
11331133
}
1134+
1135+
@Test
1136+
public void testDFSClientConfigurationLocateFollowingBlockInitialDelay()
1137+
throws Exception {
1138+
// test if DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_KEY
1139+
// is not configured, verify DFSClient uses the default value 400.
1140+
Configuration dfsConf = new HdfsConfiguration();
1141+
MiniDFSCluster cluster = new MiniDFSCluster.Builder(dfsConf).build();
1142+
cluster.waitActive();
1143+
NamenodeProtocols nn = cluster.getNameNodeRpc();
1144+
DFSClient client = new DFSClient(null, nn, dfsConf, null);
1145+
assertEquals(client.getConf().
1146+
getBlockWriteLocateFollowingInitialDelayMs(), 400);
1147+
1148+
// change DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_KEY,
1149+
// verify DFSClient uses the configured value 1000.
1150+
dfsConf.setInt(DFSConfigKeys.
1151+
DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_INITIAL_DELAY_KEY, 1000);
1152+
client = new DFSClient(null, nn, dfsConf, null);
1153+
assertEquals(client.getConf().
1154+
getBlockWriteLocateFollowingInitialDelayMs(), 1000);
1155+
}
11341156
}

0 commit comments

Comments
 (0)