Browse Source

HADOOP-987. Fix a problem in HDFS where blocks were not removed from neededReplications after a replication targer was selected. Contributed by Hairong.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@504664 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 years ago
parent
commit
c99954b820
2 changed files with 17 additions and 3 deletions
  1. 4 0
      CHANGES.txt
  2. 13 3
      src/java/org/apache/hadoop/dfs/FSNamesystem.java

+ 4 - 0
CHANGES.txt

@@ -12,6 +12,10 @@ Trunk (unreleased changes)
     HADOOP-331.  If a map output is unavailable, the job tracker is
     once more informed.  (Arun C Murthy via cutting)
 
+ 4. HADOOP-987.  Fix a problem in HDFS where blocks were not removed
+    from neededReplications after a replication target was selected.
+    (Hairong Kuang via cutting)
+
 
 Release 0.11.0 - 2007-02-02
 

+ 13 - 3
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -330,6 +330,14 @@ class FSNamesystem implements FSConstants {
             return size;
         }
         
+        /* Check if a block is in the neededReplication queue */
+        synchronized boolean contains(Block block) {
+            for(TreeSet<Block> set:priorityQueues) {
+                if(set.contains(block)) return true;
+            }
+            return false;
+        }
+        
         /* Return the priority of a block
         * @param block a under replication block
         * @param curReplicas current number of replicas of the block
@@ -1867,7 +1875,9 @@ class FSNamesystem implements FSConstants {
         
         // handle underReplication/overReplication
         short fileReplication = fileINode.getReplication();
-        neededReplications.update(block, curReplicaDelta, 0);
+        if(neededReplications.contains(block)) {
+            neededReplications.update(block, curReplicaDelta, 0);
+        }
         if (numCurrentReplica >= fileReplication ) {
             pendingReplications.remove(block);
         }        
@@ -2471,9 +2481,9 @@ class FSNamesystem implements FSConstants {
                       (DatanodeDescriptor[]) replicateTargetSets.get(i);
             int numCurrentReplica = numCurrentReplicas.get(i).intValue();
             int numExpectedReplica = dir.getFileByBlock( block).getReplication(); 
-            neededReplications.update(
-                    block, numCurrentReplica, numExpectedReplica);
             if (numCurrentReplica + targets.length >= numExpectedReplica) {
+              neededReplications.remove(
+                      block, numCurrentReplica, numExpectedReplica);
               pendingReplications.add(block);
               NameNode.stateChangeLog.debug(
                 "BLOCK* NameSystem.pendingTransfer: "