Repository: zookeeper
Updated Branches:
refs/heads/branch-3.5 82be7f63c -> c81538019
ZOOKEEPER-2870: Improve the efficiency of AtomicFileOutputStream
Author: Fangmin Lyu <allenlyu@fb.com>
Reviewers: Michael Han <hanm@apache.org>
Closes #331 from lvfangmin/ZOOKEEPER-2870
(cherry picked from commit 0c5b320060bdda854b530dc8a22993ba8cbbd655)
Signed-off-by: Michael Han <hanm@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/c8153801
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/c8153801
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/c8153801
Branch: refs/heads/branch-3.5
Commit: c815380191ac300410d5f017cb4946b442e1dd65
Parents: 82be7f6
Author: Fangmin Lyu <allenlyu@fb.com>
Authored: Thu Aug 10 13:14:22 2017 -0700
Committer: Michael Han <hanm@apache.org>
Committed: Thu Aug 10 13:14:35 2017 -0700
----------------------------------------------------------------------
.../zookeeper/common/AtomicFileOutputStream.java | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c8153801/src/java/main/org/apache/zookeeper/common/AtomicFileOutputStream.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/common/AtomicFileOutputStream.java b/src/java/main/org/apache/zookeeper/common/AtomicFileOutputStream.java
index 26035bf..740ae8f 100644
--- a/src/java/main/org/apache/zookeeper/common/AtomicFileOutputStream.java
+++ b/src/java/main/org/apache/zookeeper/common/AtomicFileOutputStream.java
@@ -35,10 +35,10 @@ import org.slf4j.LoggerFactory;
* A FileOutputStream that has the property that it will only show up at its
* destination once it has been entirely written and flushed to disk. While
* being written, it will use a .tmp suffix.
- *
+ *
* When the output stream is closed, it is flushed, fsynced, and will be moved
* into place, overwriting any file that already exists at that location.
- *
+ *
* <b>NOTE</b>: on Windows platforms, it will not atomically replace the target
* file - instead the target file is deleted before this one is moved into
* place.
@@ -63,6 +63,17 @@ public class AtomicFileOutputStream extends FilterOutputStream {
.getAbsoluteFile();
}
+ /**
+ * The default write method in FilterOutputStream does not call the write
+ * method of its underlying input stream with the same arguments. Instead
+ * it writes the data byte by byte, override it here to make it more
+ * efficient.
+ */
+ @Override
+ public void write(byte b[], int off, int len) throws IOException {
+ out.write(b, off, len);
+ }
+
@Override
public void close() throws IOException {
boolean triedToClose = false, success = false;
|