hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r1104649 - in /hadoop/hdfs/trunk: CHANGES.txt src/java/org/apache/hadoop/hdfs/server/namenode/BlockPlacementPolicyDefault.java src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
Date Wed, 18 May 2011 01:24:47 GMT
Author: szetszwo
Date: Wed May 18 01:24:47 2011
New Revision: 1104649

URL: http://svn.apache.org/viewvc?rev=1104649&view=rev
Log:
HDFS-1332.  Include more information in exceptions and debug messages when BlockPlacementPolicy
cannot be satisfied.  Contributed by Ted Yu

Modified:
    hadoop/hdfs/trunk/CHANGES.txt
    hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/BlockPlacementPolicyDefault.java
    hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1104649&r1=1104648&r2=1104649&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Wed May 18 01:24:47 2011
@@ -433,6 +433,9 @@ Trunk (unreleased changes)
     HDFS-1939.  In ivy.xml, test conf should not extend common conf.
     (Eric Yang via szetszwo)
 
+    HDFS-1332.  Include more information in exceptions and debug messages
+    when BlockPlacementPolicy cannot be satisfied.  (Ted Yu via szetszwo)
+
   OPTIMIZATIONS
 
     HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/BlockPlacementPolicyDefault.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/BlockPlacementPolicyDefault.java?rev=1104649&r1=1104648&r2=1104649&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/BlockPlacementPolicyDefault.java
(original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/BlockPlacementPolicyDefault.java
Wed May 18 01:24:47 2011
@@ -49,6 +49,9 @@ public class BlockPlacementPolicyDefault
   private boolean considerLoad; 
   private NetworkTopology clusterMap;
   private FSClusterStats stats;
+  static final String enableDebugLogging = "For more information, please enable"
+    + " DEBUG level logging on the "
+    + "org.apache.hadoop.hdfs.server.namenode.FSNamesystem logger.";
 
   BlockPlacementPolicyDefault(Configuration conf,  FSClusterStats stats,
                            NetworkTopology clusterMap) {
@@ -66,6 +69,14 @@ public class BlockPlacementPolicyDefault
     this.clusterMap = clusterMap;
   }
 
+  private ThreadLocal<StringBuilder> threadLocalBuilder =
+    new ThreadLocal<StringBuilder>() {
+    @Override
+    protected StringBuilder initialValue() {
+      return new StringBuilder();
+    }
+  };
+
   /** {@inheritDoc} */
   public DatanodeDescriptor[] chooseTarget(String srcPath,
                                     int numOfReplicas,
@@ -157,6 +168,7 @@ public class BlockPlacementPolicyDefault
     if (numOfReplicas == 0 || clusterMap.getNumOfLeaves()==0) {
       return writer;
     }
+    int totalReplicasExpected = numOfReplicas;
       
     int numOfResults = results.size();
     boolean newBlock = (numOfResults==0);
@@ -198,7 +210,8 @@ public class BlockPlacementPolicyDefault
                    blocksize, maxNodesPerRack, results);
     } catch (NotEnoughReplicasException e) {
       FSNamesystem.LOG.warn("Not able to place enough replicas, still in need of "
-               + numOfReplicas);
+               + numOfReplicas + " to reach " + totalReplicasExpected + "\n"
+               + e.getMessage());
     }
     return writer;
   }
@@ -326,6 +339,13 @@ public class BlockPlacementPolicyDefault
     throws NotEnoughReplicasException {
     int numOfAvailableNodes =
       clusterMap.countNumOfAvailableNodes(nodes, excludedNodes.keySet());
+    StringBuilder builder = null;
+    if (FSNamesystem.LOG.isDebugEnabled()) {
+      builder = threadLocalBuilder.get();
+      builder.setLength(0);
+      builder.append("[");
+    }
+    boolean badTarget = false;
     while(numOfAvailableNodes > 0) {
       DatanodeDescriptor chosenNode = 
         (DatanodeDescriptor)(clusterMap.chooseRandom(nodes));
@@ -336,12 +356,20 @@ public class BlockPlacementPolicyDefault
         if (isGoodTarget(chosenNode, blocksize, maxNodesPerRack, results)) {
           results.add(chosenNode);
           return chosenNode;
+        } else {
+          badTarget = true;
         }
       }
     }
 
-    throw new NotEnoughReplicasException(
-        "Not able to place enough replicas");
+    String detail = enableDebugLogging;
+    if (FSNamesystem.LOG.isDebugEnabled()) {
+      if (badTarget && builder != null) {
+        detail = builder.append("]").toString();
+        builder.setLength(0);
+      } else detail = "";
+    }
+    throw new NotEnoughReplicasException(detail);
   }
     
   /* Randomly choose <i>numOfReplicas</i> targets from <i>nodes</i>.
@@ -356,6 +384,13 @@ public class BlockPlacementPolicyDefault
       
     int numOfAvailableNodes =
       clusterMap.countNumOfAvailableNodes(nodes, excludedNodes.keySet());
+    StringBuilder builder = null;
+    if (FSNamesystem.LOG.isDebugEnabled()) {
+      builder = threadLocalBuilder.get();
+      builder.setLength(0);
+      builder.append("[");
+    }
+    boolean badTarget = false;
     while(numOfReplicas > 0 && numOfAvailableNodes > 0) {
       DatanodeDescriptor chosenNode = 
         (DatanodeDescriptor)(clusterMap.chooseRandom(nodes));
@@ -366,13 +401,21 @@ public class BlockPlacementPolicyDefault
         if (isGoodTarget(chosenNode, blocksize, maxNodesPerRack, results)) {
           numOfReplicas--;
           results.add(chosenNode);
+        } else {
+          badTarget = true;
         }
       }
     }
       
     if (numOfReplicas>0) {
-      throw new NotEnoughReplicasException(
-                                           "Not able to place enough replicas");
+      String detail = enableDebugLogging;
+      if (FSNamesystem.LOG.isDebugEnabled()) {
+        if (badTarget && builder != null) {
+          detail = builder.append("]").toString();
+          builder.setLength(0);
+        } else detail = "";
+      }
+      throw new NotEnoughReplicasException(detail);
     }
   }
     
@@ -394,8 +437,9 @@ public class BlockPlacementPolicyDefault
     // check if the node is (being) decommissed
     if (node.isDecommissionInProgress() || node.isDecommissioned()) {
       if(FSNamesystem.LOG.isDebugEnabled()) {
-        FSNamesystem.LOG.debug("Node "+NodeBase.getPath(node)+
-            " is not chosen because the node is (being) decommissioned");
+        threadLocalBuilder.get().append(node.toString()).append(": ")
+          .append("Node ").append(NodeBase.getPath(node))
+          .append(" is not chosen because the node is (being) decommissioned ");
       }
       return false;
     }
@@ -405,8 +449,9 @@ public class BlockPlacementPolicyDefault
     // check the remaining capacity of the target machine
     if (blockSize* FSConstants.MIN_BLOCKS_FOR_WRITE>remaining) {
       if(FSNamesystem.LOG.isDebugEnabled()) {
-        FSNamesystem.LOG.debug("Node "+NodeBase.getPath(node)+
-            " is not chosen because the node does not have enough space");
+        threadLocalBuilder.get().append(node.toString()).append(": ")
+          .append("Node ").append(NodeBase.getPath(node))
+          .append(" is not chosen because the node does not have enough space ");
       }
       return false;
     }
@@ -420,8 +465,9 @@ public class BlockPlacementPolicyDefault
       }
       if (node.getXceiverCount() > (2.0 * avgLoad)) {
         if(FSNamesystem.LOG.isDebugEnabled()) {
-          FSNamesystem.LOG.debug("Node "+NodeBase.getPath(node)+
-              " is not chosen because the node is too busy");
+          threadLocalBuilder.get().append(node.toString()).append(": ")
+            .append("Node ").append(NodeBase.getPath(node))
+            .append(" is not chosen because the node is too busy ");
         }
         return false;
       }
@@ -439,8 +485,9 @@ public class BlockPlacementPolicyDefault
     }
     if (counter>maxTargetPerLoc) {
       if(FSNamesystem.LOG.isDebugEnabled()) {
-        FSNamesystem.LOG.debug("Node "+NodeBase.getPath(node)+
-            " is not chosen because the rack has too many chosen nodes");
+        threadLocalBuilder.get().append(node.toString()).append(": ")
+          .append("Node ").append(NodeBase.getPath(node))
+          .append(" is not chosen because the rack has too many chosen nodes ");
       }
       return false;
     }

Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1104649&r1=1104648&r2=1104649&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java Wed
May 18 01:24:47 2011
@@ -1642,7 +1642,10 @@ public class FSNamesystem implements FSC
     if (targets.length < blockManager.minReplication) {
       throw new IOException("File " + src + " could only be replicated to " +
                             targets.length + " nodes, instead of " +
-                            blockManager.minReplication);
+                            blockManager.minReplication + ". There are "
+                            +clusterMap.getNumOfLeaves()+" datanode(s) running"
+                            +" but "+excludedNodes.size() +
+                            " node(s) are excluded in this operation.");
     }
 
     // Allocate a new block and record it in the INode. 



Mime
View raw message