1
0
Просмотр исходного кода

HADOOP-1126. Optimize CPU usage for under replicated blocks when cluster restarts. Contributed by Hairong Kuang.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@519437 13f79535-47bb-0310-9956-ffa450edef68
Thomas White 18 лет назад
Родитель
Сommit
b9eec72584
2 измененных файлов с 11 добавлено и 8 удалено
  1. 3 0
      CHANGES.txt
  2. 8 8
      src/java/org/apache/hadoop/dfs/FSNamesystem.java

+ 3 - 0
CHANGES.txt

@@ -76,6 +76,9 @@ Trunk (unreleased changes)
 22. HADOOP-1129.  Fix DFSClient to not hide IOExceptions in
 22. HADOOP-1129.  Fix DFSClient to not hide IOExceptions in
     flush method.  (Hairong Kuang via tomwhite)
     flush method.  (Hairong Kuang via tomwhite)
 
 
+23. HADOOP-1126.  Optimize CPU usage for under replicated blocks
+    when cluster restarts.  (Hairong Kuang via tomwhite)
+
 
 
 Release 0.12.0 - 2007-03-02
 Release 0.12.0 - 2007-03-02
 
 

+ 8 - 8
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -155,7 +155,7 @@ class FSNamesystem implements FSConstants {
     // We also store pending replication-orders.
     // We also store pending replication-orders.
     // Set of: Block
     // Set of: Block
     //
     //
-    private UnderReplicationBlocks neededReplications = new UnderReplicationBlocks();
+    private UnderReplicatedBlocks neededReplications = new UnderReplicatedBlocks();
     private PendingReplicationBlocks pendingReplications;
     private PendingReplicationBlocks pendingReplications;
 
 
     //
     //
@@ -334,12 +334,12 @@ class FSNamesystem implements FSConstants {
      * Blocks have replication priority, with priority 0 indicating the highest
      * Blocks have replication priority, with priority 0 indicating the highest
      * Blocks have only one replicas has the highest
      * Blocks have only one replicas has the highest
      */
      */
-    private class UnderReplicationBlocks {
+    private class UnderReplicatedBlocks {
         private static final int LEVEL = 3;
         private static final int LEVEL = 3;
         TreeSet<Block>[] priorityQueues = new TreeSet[LEVEL];
         TreeSet<Block>[] priorityQueues = new TreeSet[LEVEL];
         
         
         /* constructor */
         /* constructor */
-        UnderReplicationBlocks() {
+        UnderReplicatedBlocks() {
             for(int i=0; i<LEVEL; i++) {
             for(int i=0; i<LEVEL; i++) {
                 priorityQueues[i] = new TreeSet<Block>();
                 priorityQueues[i] = new TreeSet<Block>();
             }
             }
@@ -369,7 +369,7 @@ class FSNamesystem implements FSConstants {
         */
         */
         private int getPriority(Block block, 
         private int getPriority(Block block, 
                 int curReplicas, int expectedReplicas) {
                 int curReplicas, int expectedReplicas) {
-            if (curReplicas==0 || curReplicas>=expectedReplicas) {
+            if (curReplicas<=0 || curReplicas>=expectedReplicas) {
                 return LEVEL; // no need to replicate
                 return LEVEL; // no need to replicate
             } else if(curReplicas==1) {
             } else if(curReplicas==1) {
                 return 0; // highest priority
                 return 0; // highest priority
@@ -414,16 +414,14 @@ class FSNamesystem implements FSConstants {
         /* remove a block from a under replication queue */
         /* remove a block from a under replication queue */
         synchronized boolean remove(Block block, 
         synchronized boolean remove(Block block, 
                 int oldReplicas, int oldExpectedReplicas) {
                 int oldReplicas, int oldExpectedReplicas) {
-            if(oldExpectedReplicas <= oldReplicas) {
-                return false;
-            }
             int priLevel = getPriority(block, oldReplicas, oldExpectedReplicas);
             int priLevel = getPriority(block, oldReplicas, oldExpectedReplicas);
             return remove(block, priLevel);
             return remove(block, priLevel);
         }
         }
         
         
         /* remove a block from a under replication queue given a priority*/
         /* remove a block from a under replication queue given a priority*/
         private boolean remove(Block block, int priLevel ) {
         private boolean remove(Block block, int priLevel ) {
-            if( priorityQueues[priLevel].remove(block) ) {
+            if( priLevel >= 0 && priLevel < LEVEL 
+                    && priorityQueues[priLevel].remove(block) ) {
                 NameNode.stateChangeLog.debug(
                 NameNode.stateChangeLog.debug(
                      "BLOCK* NameSystem.UnderReplicationBlock.remove: "
                      "BLOCK* NameSystem.UnderReplicationBlock.remove: "
                    + "Removing block " + block.getBlockName()
                    + "Removing block " + block.getBlockName()
@@ -3536,6 +3534,8 @@ class FSNamesystem implements FSConstants {
         NameNode.stateChangeLog.info("STATE* Network topology has "
         NameNode.stateChangeLog.info("STATE* Network topology has "
                 +clusterMap.getNumOfRacks()+" racks and "
                 +clusterMap.getNumOfRacks()+" racks and "
                 +clusterMap.getNumOfLeaves()+ " datanodes");
                 +clusterMap.getNumOfLeaves()+ " datanodes");
+        NameNode.stateChangeLog.info("STATE* UnderReplicatedBlocks has "
+                +neededReplications.size()+" blocks" );
       }
       }
       
       
       /** 
       /**