commit c16ae3eb314cff24406f3ebe10508008368e4b63 Author: Todd Lipcon Date: Fri Jul 24 12:35:43 2009 -0700 Hadoop-5318 diff --git src/java/org/apache/hadoop/fs/FSDataOutputStream.java src/java/org/apache/hadoop/fs/FSDataOutputStream.java index ac13d74..d4c623f 100644 --- src/java/org/apache/hadoop/fs/FSDataOutputStream.java +++ src/java/org/apache/hadoop/fs/FSDataOutputStream.java @@ -29,19 +29,25 @@ public class FSDataOutputStream extends DataOutputStream implements Syncable { private FileSystem.Statistics statistics; long position; + private int unreportedBytes; + + private static final int REPORT_INTERVAL = 1024; + + public PositionCache(OutputStream out, FileSystem.Statistics stats, long pos) throws IOException { super(out); statistics = stats; position = pos; + unreportedBytes = 0; } public void write(int b) throws IOException { out.write(b); position++; if (statistics != null) { - statistics.incrementBytesWritten(1); + incrementBytesWritten(1); } } @@ -49,7 +55,7 @@ public class FSDataOutputStream extends DataOutputStream implements Syncable { out.write(b, off, len); position += len; // update position if (statistics != null) { - statistics.incrementBytesWritten(len); + incrementBytesWritten(len); } } @@ -59,6 +65,20 @@ public class FSDataOutputStream extends DataOutputStream implements Syncable { public void close() throws IOException { out.close(); + if (statistics != null) { + reportBytesWritten(); + } + } + + private void incrementBytesWritten(int bytesWritten) { + unreportedBytes += bytesWritten; + if (unreportedBytes > REPORT_INTERVAL) + reportBytesWritten(); + } + + private void reportBytesWritten() { + statistics.incrementBytesWritten(unreportedBytes); + unreportedBytes = 0; } }