Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A959E20049E for ; Thu, 10 Aug 2017 22:14:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A7CD716BE12; Thu, 10 Aug 2017 20:14:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EADCB16BD9C for ; Thu, 10 Aug 2017 22:14:49 +0200 (CEST) Received: (qmail 45877 invoked by uid 500); 10 Aug 2017 20:14:49 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 45862 invoked by uid 99); 10 Aug 2017 20:14:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Aug 2017 20:14:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 00282DFC28; Thu, 10 Aug 2017 20:14:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hanm@apache.org To: commits@zookeeper.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: zookeeper git commit: ZOOKEEPER-2870: Improve the efficiency of AtomicFileOutputStream Date: Thu, 10 Aug 2017 20:14:48 +0000 (UTC) archived-at: Thu, 10 Aug 2017 20:14:50 -0000 Repository: zookeeper Updated Branches: refs/heads/branch-3.4 4beaa69b5 -> 9959b0e43 ZOOKEEPER-2870: Improve the efficiency of AtomicFileOutputStream Author: Fangmin Lyu Reviewers: Michael Han Closes #331 from lvfangmin/ZOOKEEPER-2870 (cherry picked from commit 0c5b320060bdda854b530dc8a22993ba8cbbd655) Signed-off-by: Michael Han Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/9959b0e4 Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/9959b0e4 Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/9959b0e4 Branch: refs/heads/branch-3.4 Commit: 9959b0e4387c02e82fadb0aee8d59f6212a2757e Parents: 4beaa69 Author: Fangmin Lyu Authored: Thu Aug 10 13:14:22 2017 -0700 Committer: Michael Han Committed: Thu Aug 10 13:14:45 2017 -0700 ---------------------------------------------------------------------- .../zookeeper/common/AtomicFileOutputStream.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zookeeper/blob/9959b0e4/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 ecfcad7..2584d3f 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. - * + * * NOTE: 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;