瀏覽代碼

HADOOP-146. Fix DFS to check that newly allocated block id's are not already used. Contributed by Konstantin.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@405890 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 年之前
父節點
當前提交
2ac11b0dd6
共有 3 個文件被更改,包括 11 次插入4 次删除
  1. 4 0
      CHANGES.txt
  2. 1 3
      src/java/org/apache/hadoop/dfs/Block.java
  3. 6 1
      src/java/org/apache/hadoop/dfs/FSNamesystem.java

+ 4 - 0
CHANGES.txt

@@ -12,6 +12,10 @@ Trunk (unreleased)
     copy files within or between file systems in parallel.
     (Milind Bhandarkar via cutting)
 
+ 4. HADOOP-146.  Fix DFS to check when randomly generating a new block
+    id that no existing blocks already have that id.
+    (Konstantin Shvachko via cutting)
+
 
 Release 0.2.1 - 2006-05-12
 

+ 1 - 3
src/java/org/apache/hadoop/dfs/Block.java

@@ -35,8 +35,6 @@ class Block implements Writable, Comparable {
          });
     }
 
-    static Random r = new Random();
-
     /**
      */
     public static boolean isBlockFilename(File f) {
@@ -53,7 +51,7 @@ class Block implements Writable, Comparable {
     /**
      */
     public Block() {
-        this.blkid = r.nextLong();
+        this.blkid = 0;
         this.len = 0;
     }
 

+ 6 - 1
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -585,11 +585,16 @@ class FSNamesystem implements FSConstants {
         return COMPLETE_SUCCESS;
     }
 
+    static Random randBlockId = new Random();
+    
     /**
      * Allocate a block at the given pending filename
      */
     synchronized Block allocateBlock(UTF8 src) {
-        Block b = new Block();
+        Block b = null;
+        do {
+            b = new Block(FSNamesystem.randBlockId.nextLong(), 0);
+        } while (dir.isValidBlock(b));
         FileUnderConstruction v = 
           (FileUnderConstruction) pendingCreates.get(src);
         v.getBlocks().add(b);