Skip to content

Commit 4c641b0

Browse files
author
Hairong Kuang
committed
HADOOP-5412. Simulated DataNode should not write to a block that's being written by another thread. Contributed by Hairong Kuang.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@752609 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2abd3b1 commit 4c641b0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,9 @@ Release 0.18.4 - Unreleased
20842084
HADOOP-5134. FSNamesystem#commitBlockSynchronization adds under-construction
20852085
block locations to blocksMap. (Dhruba Borthakur via hairong)
20862086

2087+
HADOOP-5412. Simulated DataNode should not write to a block that's being
2088+
written by another thread. (hairong)
2089+
20872090
Release 0.18.3 - 2009-01-27
20882091

20892092
IMPROVEMENTS

src/test/org/apache/hadoop/hdfs/TestInjectionForSimulatedStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void testInjection() throws IOException {
171171

172172
cluster = new MiniDFSCluster(0, conf, numDataNodes*2, false,
173173
true, null, null);
174-
174+
cluster.waitActive();
175175
Set<Block> uniqueBlocks = new HashSet<Block>();
176176
for (int i=0; i<blocksList.length; ++i) {
177177
for (int j=0; j < blocksList[i].length; ++j) {

src/test/org/apache/hadoop/hdfs/server/datanode/SimulatedFSDataset.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ public synchronized void finalizeBlock(Block b) throws IOException {
275275
}
276276

277277
public synchronized void unfinalizeBlock(Block b) throws IOException {
278-
blockMap.remove(b);
278+
if (isBeingWritten(b)) {
279+
blockMap.remove(b);
280+
}
279281
}
280282

281283
public synchronized Block[] getBlockReport() {
@@ -365,6 +367,15 @@ public synchronized boolean isValidBlock(Block b) {
365367
return binfo.isFinalized();
366368
}
367369

370+
/* check if a block is created but not finalized */
371+
private synchronized boolean isBeingWritten(Block b) {
372+
BInfo binfo = blockMap.get(b);
373+
if (binfo == null) {
374+
return false;
375+
}
376+
return !binfo.isFinalized();
377+
}
378+
368379
public String toString() {
369380
return getStorageInfo();
370381
}
@@ -376,6 +387,10 @@ public synchronized BlockWriteStreams writeToBlock(Block b,
376387
throw new BlockAlreadyExistsException("Block " + b +
377388
" is valid, and cannot be written to.");
378389
}
390+
if (isBeingWritten(b)) {
391+
throw new BlockAlreadyExistsException("Block " + b +
392+
" is being written, and cannot be written to.");
393+
}
379394
BInfo binfo = new BInfo(b, true);
380395
blockMap.put(b, binfo);
381396
SimulatedOutputStream crcStream = new SimulatedOutputStream();

0 commit comments

Comments
 (0)