Selaa lähdekoodia

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 vuotta sitten
vanhempi
commit
c43b39cc22
2 muutettua tiedostoa jossa 23 lisäystä ja 2 poistoa
  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
     to namenode.  This fixes a problem where restarting the namenode
     triggered a lot of uneeded replication. (Hairong Kuang via cutting)
     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
 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();
                     UTF8 name = new UTF8();
                     name.readFields(in);
                     name.readFields(in);
                     // version 0 does not support per file replication
                     // version 0 does not support per file replication
-                    if( !(imgVersion >= 0) )
+                    if( !(imgVersion >= 0) ) {
                       replication = in.readShort(); // other versions do
                       replication = in.readShort(); // other versions do
+                      replication = adjustReplication( replication, conf );
+                    }
                     int numBlocks = in.readInt();
                     int numBlocks = in.readInt();
                     Block blocks[] = null;
                     Block blocks[] = null;
                     if (numBlocks > 0) {
                     if (numBlocks > 0) {
@@ -484,6 +486,7 @@ class FSDirectory implements FSConstants {
                           name = (UTF8) writables[0];
                           name = (UTF8) writables[0];
                           replication = Short.parseShort(
                           replication = Short.parseShort(
                                               ((UTF8)writables[1]).toString());
                                               ((UTF8)writables[1]).toString());
+                          replication = adjustReplication( replication, conf );
                         }
                         }
                         // get blocks
                         // get blocks
                         aw = new ArrayWritable(Block.class);
                         aw = new ArrayWritable(Block.class);
@@ -501,8 +504,11 @@ class FSDirectory implements FSConstants {
                         UTF8 repl = new UTF8();
                         UTF8 repl = new UTF8();
                         src.readFields(in);
                         src.readFields(in);
                         repl.readFields(in);
                         repl.readFields(in);
+                        replication=adjustReplication(
+                                fromLogReplication(repl),
+                                conf);
                         unprotectedSetReplication(src.toString(), 
                         unprotectedSetReplication(src.toString(), 
-                                                  fromLogReplication(repl),
+                                                  replication,
                                                   null);
                                                   null);
                         break;
                         break;
                     } 
                     } 
@@ -541,6 +547,17 @@ class FSDirectory implements FSConstants {
         return numEdits;
         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
      * Save the contents of the FS image
      */
      */