hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1294754 - in /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs: ./ src/main/java/org/apache/hadoop/hdfs/protocol/ src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/
Date Tue, 28 Feb 2012 18:04:14 GMT
Author: todd
Date: Tue Feb 28 18:04:13 2012
New Revision: 1294754

URL: http://svn.apache.org/viewvc?rev=1294754&view=rev
Log:
HDFS-3024. Improve performance of stringification in addStoredBlock. Contributed by Todd Lipcon.

Modified:
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1294754&r1=1294753&r2=1294754&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Tue Feb 28 18:04:13 2012
@@ -201,6 +201,8 @@ Release 0.23.3 - UNRELEASED 
 
   OPTIMIZATIONS
 
+    HDFS-3024. Improve performance of stringification in addStoredBlock (todd)
+
   BUG FIXES
 
     HDFS-2481. Unknown protocol: org.apache.hadoop.hdfs.protocol.ClientProtocol.

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java?rev=1294754&r1=1294753&r2=1294754&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java
Tue Feb 28 18:04:13 2012
@@ -150,6 +150,14 @@ public class Block implements Writable, 
     return getBlockName() + "_" + getGenerationStamp();
   }
 
+  public void appendStringTo(StringBuilder sb) {
+    sb.append(BLOCK_FILE_PREFIX)
+      .append(blockId)
+      .append("_")
+      .append(getGenerationStamp());
+  }
+
+
   /////////////////////////////////////
   // Writable
   /////////////////////////////////////

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java?rev=1294754&r1=1294753&r2=1294754&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java
Tue Feb 28 18:04:13 2012
@@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.bl
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.hadoop.hdfs.protocol.Block;
@@ -114,14 +115,19 @@ public class BlockInfoUnderConstruction 
 
     @Override
     public String toString() {
-      final StringBuilder b = new StringBuilder(getClass().getSimpleName());
-      b.append("[")
-       .append(expectedLocation)
-       .append("|")
-       .append(state)
-       .append("]");
+      final StringBuilder b = new StringBuilder(50);
+      appendStringTo(b);
       return b.toString();
     }
+    
+    @Override
+    public void appendStringTo(StringBuilder sb) {
+      sb.append("ReplicaUnderConstruction[")
+        .append(expectedLocation)
+        .append("|")
+        .append(state)
+        .append("]");
+    }
   }
 
   /**
@@ -269,11 +275,29 @@ public class BlockInfoUnderConstruction 
 
   @Override
   public String toString() {
-    final StringBuilder b = new StringBuilder(super.toString());
-    b.append("{blockUCState=").append(blockUCState)
-     .append(", primaryNodeIndex=").append(primaryNodeIndex)
-     .append(", replicas=").append(replicas)
-     .append("}");
+    final StringBuilder b = new StringBuilder(100);
+    appendStringTo(b);
     return b.toString();
   }
+
+  @Override
+  public void appendStringTo(StringBuilder sb) {
+    super.appendStringTo(sb);
+    appendUCParts(sb);
+  }
+
+  private void appendUCParts(StringBuilder sb) {
+    sb.append("{blockUCState=").append(blockUCState)
+      .append(", primaryNodeIndex=").append(primaryNodeIndex)
+      .append(", replicas=[");
+    Iterator<ReplicaUnderConstruction> iter = replicas.iterator();
+    if (iter.hasNext()) {
+      iter.next().appendStringTo(sb);
+      while (iter.hasNext()) {
+        sb.append(", ");
+        iter.next().appendStringTo(sb);
+      }
+    }
+    sb.append("]}");
+  }
 }

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java?rev=1294754&r1=1294753&r2=1294754&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
Tue Feb 28 18:04:13 2012
@@ -1722,9 +1722,7 @@ public class BlockManager {
     if (added) {
       curReplicaDelta = 1;
       if (logEveryBlock) {
-        NameNode.stateChangeLog.info("BLOCK* addStoredBlock: "
-            + "blockMap updated: " + node.getName() + " is added to " + 
-            storedBlock + " size " + storedBlock.getNumBytes());
+        logAddStoredBlock(storedBlock, node);
       }
     } else {
       curReplicaDelta = 0;
@@ -1784,6 +1782,20 @@ public class BlockManager {
     return storedBlock;
   }
 
+  private void logAddStoredBlock(BlockInfo storedBlock, DatanodeDescriptor node) {
+    if (!NameNode.stateChangeLog.isInfoEnabled()) {
+      return;
+    }
+    
+    StringBuilder sb = new StringBuilder(500);
+    sb.append("BLOCK* addStoredBlock: blockMap updated: ")
+      .append(node.getName())
+      .append(" is added to ");
+    storedBlock.appendStringTo(sb);
+    sb.append(" size " )
+      .append(storedBlock.getNumBytes());
+    NameNode.stateChangeLog.info(sb);
+  }
   /**
    * Invalidate corrupt replicas.
    * <p>



Mime
View raw message