Browse Source

HADOOP-4583. Several code optimizations in HDFS. (Suresh Srinivas via szetszwo)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@712344 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 16 years ago
parent
commit
01612b0c7c

+ 6 - 3
CHANGES.txt

@@ -70,6 +70,9 @@ Trunk (unreleased changes)
     HADOOP-4453. Improve ssl configuration and handling in HsftpFileSystem,
     particularly when used with DistCp. (Kan Zhang via cdouglas)
 
+    HADOOP-4583. Several code optimizations in HDFS.  (Suresh Srinivas via
+    szetszwo)
+
   OPTIMIZATIONS
 
   BUG FIXES
@@ -964,9 +967,6 @@ Release 0.19.0 - Unreleased
     HADOOP-4288. Fixes a NPE problem in CapacityScheduler. 
     (Amar Kamat via ddas)
 
-    HADOOP-3883. Limit namenode to assign at most one generation stamp for
-    a particular block within a short period. (szetszwo)
-
     HADOOP-4014. Create hard links with 'fsutil hardlink' on Windows. (shv)
 
     HADOOP-4393. Merged org.apache.hadoop.fs.permission.AccessControlException
@@ -1085,6 +1085,9 @@ Release 0.18.3 - Unreleased
     HADOOP-4610. Always calculate mis-replicated blocks when safe-mode is 
     turned off. (shv)
 
+    HADOOP-3883. Limit namenode to assign at most one generation stamp for
+    a particular block within a short period. (szetszwo)
+
 Release 0.18.2 - 2008-11-03
 
   BUG FIXES

+ 22 - 17
src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java

@@ -449,12 +449,13 @@ public class FSEditLog {
     for (int idx = 0; idx < errorStreams.size(); idx++) {
       EditLogOutputStream eStream = errorStreams.get(idx);
       int j = 0;
-      for (j = 0; j < editStreams.size(); j++) {
+      int numEditStreams = editStreams.size();
+      for (j = 0; j < numEditStreams; j++) {
         if (editStreams.get(j) == eStream) {
           break;
         }
       }
-      if (j == editStreams.size()) {
+      if (j == numEditStreams) {
           FSNamesystem.LOG.error("Unable to find sync log on which " +
                                  " IO error occured. " +
                                  "Fatal Error.");
@@ -841,7 +842,8 @@ public class FSEditLog {
   synchronized void logEdit(byte op, Writable ... writables) {
     assert this.getNumEditStreams() > 0 : "no editlog streams";
     long start = FSNamesystem.now();
-    for (int idx = 0; idx < editStreams.size(); idx++) {
+    int numEditStreams = editStreams.size();
+    for (int idx = 0; idx < numEditStreams; idx++) {
       EditLogOutputStream eStream = editStreams.get(idx);
       try {
         eStream.write(op, writables);
@@ -874,11 +876,12 @@ public class FSEditLog {
     long syncStart = 0;
 
     // Fetch the transactionId of this thread. 
-    TransactionId id = myTransactionId.get();
-    long mytxid = id.txid;
+    long mytxid = myTransactionId.get().txid;
 
+    final int numEditStreams;
     synchronized (this) {
-      assert this.getNumEditStreams() > 0 : "no editlog streams";
+      numEditStreams = editStreams.size();
+      assert numEditStreams > 0 : "no editlog streams";
       printStatistics(false);
 
       // if somebody is already syncing, then wait
@@ -901,15 +904,14 @@ public class FSEditLog {
       isSyncRunning = true;   
 
       // swap buffers
-      for (int idx = 0; idx < editStreams.size(); idx++) {
-        EditLogOutputStream eStream = editStreams.get(idx);
-        eStream.setReadyToFlush();
+      for (int idx = 0; idx < numEditStreams; idx++) {
+        editStreams.get(idx).setReadyToFlush();
       }
     }
 
     // do the sync
     long start = FSNamesystem.now();
-    for (int idx = 0; idx < editStreams.size(); idx++) {
+    for (int idx = 0; idx < numEditStreams; idx++) {
       EditLogOutputStream eStream = editStreams.get(idx);
       try {
         eStream.flush();
@@ -950,14 +952,17 @@ public class FSEditLog {
       return;
     }
     lastPrintTime = now;
-    StringBuffer buf = new StringBuffer();
-
-    buf.append("Number of transactions: " + numTransactions +
-               " Total time for transactions(ms): " + 
-               totalTimeTransactions);
-    buf.append(" Number of syncs: " + editStreams.get(0).getNumSync());
+    StringBuilder buf = new StringBuilder();
+    buf.append("Number of transactions: ");
+    buf.append(numTransactions);
+    buf.append(" Total time for transactions(ms): ");
+    buf.append(totalTimeTransactions);
+    buf.append(" Number of syncs: ");
+    buf.append(editStreams.get(0).getNumSync());
     buf.append(" SyncTimes(ms): ");
-    for (int idx = 0; idx < editStreams.size(); idx++) {
+
+    int numEditStreams = editStreams.size();
+    for (int idx = 0; idx < numEditStreams; idx++) {
       EditLogOutputStream eStream = editStreams.get(idx);
       buf.append(eStream.getTotalSyncTime());
       buf.append(" ");

+ 6 - 6
src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -1433,11 +1433,11 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
    *        <code>inodes[inodes.length-1]</code> is the INode for the file.
    */
   private Block allocateBlock(String src, INode[] inodes) throws IOException {
-    Block b = null;
-    do {
-      b = new Block(FSNamesystem.randBlockId.nextLong(), 0, 
-                    getGenerationStamp());
-    } while (isValidBlock(b));
+    Block b = new Block(FSNamesystem.randBlockId.nextLong(), 0, 0); 
+    while(isValidBlock(b)) {
+      b.setBlockId(FSNamesystem.randBlockId.nextLong());
+    }
+    b.setGenerationStamp(getGenerationStamp());
     b = dir.addBlock(src, inodes, b);
     NameNode.stateChangeLog.info("BLOCK* NameSystem.allocateBlock: "
                                  +src+ ". "+b);
@@ -3879,7 +3879,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
      * @see SafeModeInfo
      */
     private SafeModeInfo() {
-      this.threshold = 1.5f;  // this threshold can never be riched
+      this.threshold = 1.5f;  // this threshold can never be reached
       this.extension = 0;
       this.safeReplication = Short.MAX_VALUE + 1; // more than maxReplication
       this.blockTotal = -1;

+ 1 - 3
src/hdfs/org/apache/hadoop/hdfs/server/namenode/INodeFile.java

@@ -98,9 +98,7 @@ class INodeFile extends INode {
     } else {
       int size = this.blocks.length;
       BlockInfo[] newlist = new BlockInfo[size + 1];
-      for (int i = 0; i < size; i++) {
-        newlist[i] = this.blocks[i];
-      }
+      System.arraycopy(this.blocks, 0, newlist, 0, size);
       newlist[size] = newblock;
       this.blocks = newlist;
     }