HADOOP-11710. Make CryptoOutputStream behave like DFSOutputStream wrt synchronization. (Sean Busbey via yliu)

This commit is contained in:
yliu 2015-03-13 02:25:02 +08:00
parent 8212877415
commit a85291003c
2 changed files with 15 additions and 7 deletions

View File

@ -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

View File

@ -40,6 +40,9 @@ import com.google.common.base.Preconditions;
* padding = pos%(algorithm blocksize);
* <p/>
* 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 class CryptoOutputStream extends FilterOutputStream implements
* @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,22 +216,24 @@ public class CryptoOutputStream extends FilterOutputStream implements
}
@Override
public void close() throws IOException {
public synchronized void close() throws IOException {
if (closed) {
return;
}
try {
super.close();
freeBuffers();
} finally {
closed = true;
}
}
/**
* To flush, we need to encrypt the data in the buffer and write to the
* underlying stream, then do the flush.
*/
@Override
public void flush() throws IOException {
public synchronized void flush() throws IOException {
checkStream();
encrypt();
super.flush();