Skip to content

Commit b735a77

Browse files
committed
HDFS-15398. EC: hdfs client hangs due to exception during addBlock. Contributed by Hongbing Wang.
1 parent 635e6a1 commit b735a77

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,14 @@ private void allocateNewBlock() throws IOException {
503503

504504
LOG.debug("Allocating new block group. The previous block group: "
505505
+ prevBlockGroup);
506-
final LocatedBlock lb = addBlock(excludedNodes, dfsClient, src,
507-
prevBlockGroup, fileId, favoredNodes, getAddBlockFlags());
506+
final LocatedBlock lb;
507+
try {
508+
lb = addBlock(excludedNodes, dfsClient, src,
509+
prevBlockGroup, fileId, favoredNodes, getAddBlockFlags());
510+
} catch (IOException ioe) {
511+
closeAllStreamers();
512+
throw ioe;
513+
}
508514
assert lb.isStriped();
509515
// assign the new block to the current block group
510516
currentBlockGroup = lb.getBlock();

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,40 @@ public void testDFSStripedOutputStreamUpdatePipeline() throws Exception {
6161
}
6262
}
6363
}
64+
65+
/**
66+
* Test writing ec file hang when applying the second block group occurs
67+
* an addBlock exception (e.g. quota exception).
68+
*/
69+
@Test(timeout = 90000)
70+
public void testECWriteHangWhenAddBlockWithException() throws Exception {
71+
Configuration conf = new HdfsConfiguration();
72+
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1 * 1024 * 1024);
73+
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
74+
.numDataNodes(3).build()) {
75+
cluster.waitActive();
76+
final DistributedFileSystem dfs = cluster.getFileSystem();
77+
// Create a file with EC policy
78+
Path dir = new Path("/test");
79+
dfs.mkdirs(dir);
80+
dfs.enableErasureCodingPolicy("XOR-2-1-1024k");
81+
dfs.setErasureCodingPolicy(dir, "XOR-2-1-1024k");
82+
Path filePath = new Path("/test/file");
83+
FSDataOutputStream out = dfs.create(filePath);
84+
for (int i = 0; i < 1024 * 1024 * 2; i++) {
85+
out.write(i);
86+
}
87+
dfs.setQuota(dir, 5, 0);
88+
try {
89+
for (int i = 0; i < 1024 * 1024 * 2; i++) {
90+
out.write(i);
91+
}
92+
} catch (Exception e) {
93+
dfs.delete(filePath, true);
94+
} finally {
95+
// The close should be success, shouldn't get stuck.
96+
IOUtils.closeStream(out);
97+
}
98+
}
99+
}
64100
}

0 commit comments

Comments
 (0)