소스 검색

HADOOP-183. If the namendode is restarted with different minimum or maximum replication counts, existing files' replication counts are now automatically adjusted to be within the newly configured bounds. Contributed by Hairong Kuang.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@398674 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 년 전
부모
커밋
c43b39cc22
2개의 변경된 파일23개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 0
      CHANGES.txt
  2. 19 2
      src/java/org/apache/hadoop/dfs/FSDirectory.java

+ 4 - 0
CHANGES.txt

@@ -138,6 +138,10 @@ Trunk (unreleased)
     to namenode.  This fixes a problem where restarting the namenode
     triggered a lot of uneeded replication. (Hairong Kuang via cutting)
 
+37. HADOOP-183.  If the DFS namenode is restarted with different
+    minimum and/or maximum replication counts, existing files'
+    replication counts are now automatically adjusted to be within the
+    newly configured bounds. (Hairong Kuang via cutting)
 
 Release 0.1.1 - 2006-04-08
 

+ 19 - 2
src/java/org/apache/hadoop/dfs/FSDirectory.java

@@ -403,8 +403,10 @@ class FSDirectory implements FSConstants {
                     UTF8 name = new UTF8();
                     name.readFields(in);
                     // version 0 does not support per file replication
-                    if( !(imgVersion >= 0) )
+                    if( !(imgVersion >= 0) ) {
                       replication = in.readShort(); // other versions do
+                      replication = adjustReplication( replication, conf );
+                    }
                     int numBlocks = in.readInt();
                     Block blocks[] = null;
                     if (numBlocks > 0) {
@@ -484,6 +486,7 @@ class FSDirectory implements FSConstants {
                           name = (UTF8) writables[0];
                           replication = Short.parseShort(
                                               ((UTF8)writables[1]).toString());
+                          replication = adjustReplication( replication, conf );
                         }
                         // get blocks
                         aw = new ArrayWritable(Block.class);
@@ -501,8 +504,11 @@ class FSDirectory implements FSConstants {
                         UTF8 repl = new UTF8();
                         src.readFields(in);
                         repl.readFields(in);
+                        replication=adjustReplication(
+                                fromLogReplication(repl),
+                                conf);
                         unprotectedSetReplication(src.toString(), 
-                                                  fromLogReplication(repl),
+                                                  replication,
                                                   null);
                         break;
                     } 
@@ -541,6 +547,17 @@ class FSDirectory implements FSConstants {
         return numEdits;
     }
 
+    private static short adjustReplication( short replication, Configuration conf) {
+        short minReplication = (short)conf.getInt("dfs.replication.min", 1);
+        if( replication<minReplication ) {
+            replication = minReplication;
+        }
+        short maxReplication = (short)conf.getInt("dfs.replication.max", 512);
+        if( replication>maxReplication ) {
+            replication = maxReplication;
+        }
+        return replication;
+    }
     /**
      * Save the contents of the FS image
      */