Преглед на файлове

Merge -r 752608:752609 to move the change of HADOOP-5412 from main to branch 0.18.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.18@752625 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang преди 16 години
родител
ревизия
03df45a5cc
променени са 3 файла, в които са добавени 20 реда и са изтрити 2 реда
  1. 3 0
      CHANGES.txt
  2. 16 1
      src/test/org/apache/hadoop/dfs/SimulatedFSDataset.java
  3. 1 1
      src/test/org/apache/hadoop/dfs/TestInjectionForSimulatedStorage.java

+ 3 - 0
CHANGES.txt

@@ -13,6 +13,9 @@ Release 0.18.4 - Unreleased
     HADOOP-5134. FSNamesystem#commitBlockSynchronization adds under-construction
     block locations to blocksMap. (Dhruba Borthakur via hairong)
 
+    HADOOP-5412. Simulated DataNode should not write to a block that's being
+    written by another thread. (hairong)
+
 Release 0.18.3 - 2009-01-27
 
   IMPROVEMENTS

+ 16 - 1
src/test/org/apache/hadoop/dfs/SimulatedFSDataset.java

@@ -270,7 +270,9 @@ public class SimulatedFSDataset  implements FSConstants, FSDatasetInterface, Con
   }
 
   public synchronized void unfinalizeBlock(Block b) throws IOException {
-    blockMap.remove(b);
+    if (isBeingWritten(b)) {
+      blockMap.remove(b);
+    }
   }
 
   public synchronized Block[] getBlockReport() {
@@ -364,6 +366,15 @@ public class SimulatedFSDataset  implements FSConstants, FSDatasetInterface, Con
     return binfo.isFinalized();
   }
 
+  /* check if a block is created but not finalized */
+  private synchronized boolean isBeingWritten(Block b) {
+    BInfo binfo = blockMap.get(b);
+    if (binfo == null) {
+      return false;
+    }
+    return !binfo.isFinalized();  
+  }
+  
   public String toString() {
     return getStorageInfo();
   }
@@ -375,6 +386,10 @@ public class SimulatedFSDataset  implements FSConstants, FSDatasetInterface, Con
           throw new BlockAlreadyExistsException("Block " + b + 
               " is valid, and cannot be written to.");
       }
+    if (isBeingWritten(b)) {
+        throw new BlockAlreadyExistsException("Block " + b + 
+            " is being written, and cannot be written to.");
+    }
       BInfo binfo = new BInfo(b, true);
       blockMap.put(b, binfo);
       SimulatedOutputStream crcStream = new SimulatedOutputStream();

+ 1 - 1
src/test/org/apache/hadoop/dfs/TestInjectionForSimulatedStorage.java

@@ -166,7 +166,7 @@ public class TestInjectionForSimulatedStorage extends TestCase {
       
       cluster = new MiniDFSCluster(0, conf, numDataNodes*2, false,
                                    true, null, null);
-      
+      cluster.waitActive();
       Set<Block> uniqueBlocks = new HashSet<Block>();
       for (int i=0; i<blocksList.length; ++i) {
         for (int j=0; j < blocksList[i].length; ++j) {