From a85291003cf3e3fd79b6addcf59d4f43dc72d356 Mon Sep 17 00:00:00 2001 From: yliu Date: Fri, 13 Mar 2015 02:25:02 +0800 Subject: [PATCH] HADOOP-11710. Make CryptoOutputStream behave like DFSOutputStream wrt synchronization. (Sean Busbey via yliu) --- .../hadoop-common/CHANGES.txt | 3 +++ .../hadoop/crypto/CryptoOutputStream.java | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 6970bad0bc4..55028cba067 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -1097,6 +1097,9 @@ Release 2.7.0 - UNRELEASED HADOOP-11693. Azure Storage FileSystem rename operations are throttled too aggressively to complete HBase WAL archiving. (Duo Xu via cnauroth) + HADOOP-11710. Make CryptoOutputStream behave like DFSOutputStream wrt + synchronization. (Sean Busbey via yliu) + Release 2.6.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoOutputStream.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoOutputStream.java index f1ea0fccf7d..bc09b8c179f 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoOutputStream.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoOutputStream.java @@ -40,6 +40,9 @@ * padding = pos%(algorithm blocksize); *

* The underlying stream offset is maintained as state. + * + * Note that while some of this class' methods are synchronized, this is just to + * match the threadsafety behavior of DFSOutputStream. See HADOOP-11710. */ @InterfaceAudience.Private @InterfaceStability.Evolving @@ -126,7 +129,7 @@ public OutputStream getWrappedStream() { * @throws IOException */ @Override - public void write(byte[] b, int off, int len) throws IOException { + public synchronized void write(byte[] b, int off, int len) throws IOException { checkStream(); if (b == null) { throw new NullPointerException(); @@ -213,14 +216,16 @@ private byte[] getTmpBuf() { } @Override - public void close() throws IOException { + public synchronized void close() throws IOException { if (closed) { return; } - - super.close(); - freeBuffers(); - closed = true; + try { + super.close(); + freeBuffers(); + } finally { + closed = true; + } } /** @@ -228,7 +233,7 @@ public void close() throws IOException { * underlying stream, then do the flush. */ @Override - public void flush() throws IOException { + public synchronized void flush() throws IOException { checkStream(); encrypt(); super.flush();