Forráskód Böngészése

HADOOP-2768. Fix performance regression caused by HADOOP-1707. Contributed by dhruba borthakur.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@618349 13f79535-47bb-0310-9956-ffa450edef68
Nigel Daley 17 éve
szülő
commit
402724ccc9
2 módosított fájl, 27 hozzáadás és 6 törlés
  1. 4 1
      CHANGES.txt
  2. 23 5
      src/java/org/apache/hadoop/dfs/DataNode.java

+ 4 - 1
CHANGES.txt

@@ -16,7 +16,7 @@ Trunk (unreleased changes)
     HADOOP-2738 Text is not subclassable because set(Text) and compareTo(Object)
     access the other instance's private members directly.
 
-Release 0.16.0 - 2008-02-04
+Release 0.16.0 - 2008-02-07
 
   INCOMPATIBLE CHANGES
 
@@ -661,6 +661,9 @@ Release 0.16.0 - 2008-02-04
     HADOOP-2755. Fix fsck performance degradation because of permissions 
     issue.  (Tsz Wo (Nicholas), SZE via dhruba)
 
+    HADOOP-2768. Fix performance regression caused by HADOOP-1707.
+    (dhruba borthakur via nigel)
+
 Release 0.15.3 - 2008-01-18
 
   BUG FIXES

+ 23 - 5
src/java/org/apache/hadoop/dfs/DataNode.java

@@ -1092,7 +1092,9 @@ public class DataNode implements FSConstants, Runnable {
             mirrorSock.connect(mirrorTarget, timeoutValue);
             mirrorSock.setSoTimeout(timeoutValue);
             mirrorSock.setSendBufferSize(DEFAULT_DATA_SOCKET_SIZE);
-            mirrorOut = new DataOutputStream(mirrorSock.getOutputStream());
+            mirrorOut = new DataOutputStream(
+                          new BufferedOutputStream(mirrorSock.getOutputStream(),
+                                                   BUFFER_SIZE));
             mirrorIn = new DataInputStream(mirrorSock.getInputStream());
 
             // Write header: Copied from DFSClient.java!
@@ -1918,6 +1920,18 @@ public class DataNode implements FSConstants, Runnable {
     }
   }
 
+  // this class is a bufferoutputstream that exposes the number of
+  // bytes in the buffer.
+  static private class DFSBufferedOutputStream extends BufferedOutputStream {
+    DFSBufferedOutputStream(OutputStream out, int capacity) {
+      super(out, capacity);
+    }
+
+    int count() {
+      return count;
+    }
+  }
+
   /* A class that receives a block and wites to its own disk, meanwhile
    * may copies it to another site. If a throttler is provided,
    * streaming throttling is also supported. 
@@ -1929,6 +1943,7 @@ public class DataNode implements FSConstants, Runnable {
     private DataChecksum checksum; // from where chunks of a block can be read
     private DataOutputStream out = null; // to block file at local disk
     private DataOutputStream checksumOut = null; // to crc file at local disk
+    private DFSBufferedOutputStream bufStream = null;
     private int bytesPerChecksum;
     private int checksumSize;
     private byte buf[];
@@ -1968,8 +1983,11 @@ public class DataNode implements FSConstants, Runnable {
         streams = data.writeToBlock(block, isRecovery);
 		this.finalized = data.isValidBlock(block);
         if (streams != null) {
-          this.out = new DataOutputStream(streams.dataOut);
-          this.checksumOut = new DataOutputStream(streams.checksumOut);
+          this.bufStream = new DFSBufferedOutputStream(
+                                          streams.dataOut, BUFFER_SIZE);
+          this.out = new DataOutputStream(bufStream);
+          this.checksumOut = new DataOutputStream(new BufferedOutputStream(
+                                          streams.checksumOut, BUFFER_SIZE));
         }
       } catch(IOException ioe) {
         IOUtils.closeStream(this);
@@ -2290,7 +2308,8 @@ public class DataNode implements FSConstants, Runnable {
         }
         return;
       }
-      if (data.getChannelPosition(block, streams) == offsetInBlock) {
+      if (data.getChannelPosition(block, streams) + bufStream.count() == 
+                                                    offsetInBlock) {
         return;                   // nothing to do 
       }
       if (offsetInBlock % bytesPerChecksum != 0) {
@@ -2657,5 +2676,4 @@ public class DataNode implements FSConstants, Runnable {
       System.exit(-1);
     }
   }
-
 }