This is an automated email from the ASF dual-hosted git repository.

mmiller pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 65639f3  Fix performance of crypto (#652)
65639f3 is described below

commit 65639f33c7d34e5278ef042afcc5d441aa3f033d
Author: Mike Miller <mmil...@apache.org>
AuthorDate: Thu Sep 20 13:51:37 2018 -0400

    Fix performance of crypto (#652)
    
    * Remove use of DiscardCloseOutputStream from WAL encryption
    * Override inefficient write method in DiscardCloseOutputStream and 
NoFlushOutputStream
    * Changed NoFlushOutputStream to extend FilterOutputStream, which doesn't 
have synchronized methods like DataOutputStream does
---
 .../core/security/crypto/impl/AESCryptoService.java        |  8 +-------
 .../security/crypto/streams/DiscardCloseOutputStream.java  |  9 +++++++++
 .../core/security/crypto/streams/NoFlushOutputStream.java  | 14 ++++++++++++--
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git 
a/core/src/main/java/org/apache/accumulo/core/security/crypto/impl/AESCryptoService.java
 
b/core/src/main/java/org/apache/accumulo/core/security/crypto/impl/AESCryptoService.java
index d10dbff..09c5648 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/security/crypto/impl/AESCryptoService.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/security/crypto/impl/AESCryptoService.java
@@ -448,13 +448,7 @@ public class AESCryptoService implements CryptoService {
           throw new CryptoException("Unable to initialize cipher", e);
         }
 
-        CipherOutputStream cos = new CipherOutputStream(new 
DiscardCloseOutputStream(outputStream),
-            cipher);
-        // Prevent underlying stream from being closed with 
DiscardCloseOutputStream
-        // Without this, when the crypto stream is closed (in order to flush 
its last bytes)
-        // the underlying RFile stream will *also* be closed, and that's 
undesirable as the
-        // cipher
-        // stream is closed for every block written.
+        CipherOutputStream cos = new CipherOutputStream(outputStream, cipher);
         return new BlockedOutputStream(cos, cipher.getBlockSize(), 1024);
       }
 
diff --git 
a/core/src/main/java/org/apache/accumulo/core/security/crypto/streams/DiscardCloseOutputStream.java
 
b/core/src/main/java/org/apache/accumulo/core/security/crypto/streams/DiscardCloseOutputStream.java
index cf0db70..4870bbc 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/security/crypto/streams/DiscardCloseOutputStream.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/security/crypto/streams/DiscardCloseOutputStream.java
@@ -32,6 +32,15 @@ public class DiscardCloseOutputStream extends 
FilterOutputStream {
     super(out);
   }
 
+  /**
+   * It is very important to override this method!! The underlying method from 
FilterOutputStream
+   * calls write a single byte at a time and will kill performance.
+   */
+  @Override
+  public void write(byte[] b, int off, int len) throws IOException {
+    out.write(b, off, len);
+  }
+
   @Override
   public void close() throws IOException {
     // Discard
diff --git 
a/core/src/main/java/org/apache/accumulo/core/security/crypto/streams/NoFlushOutputStream.java
 
b/core/src/main/java/org/apache/accumulo/core/security/crypto/streams/NoFlushOutputStream.java
index 1fa2af7..7edb1bf 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/security/crypto/streams/NoFlushOutputStream.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/security/crypto/streams/NoFlushOutputStream.java
@@ -16,15 +16,25 @@
  */
 package org.apache.accumulo.core.security.crypto.streams;
 
-import java.io.DataOutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
 import java.io.OutputStream;
 
-public class NoFlushOutputStream extends DataOutputStream {
+public class NoFlushOutputStream extends FilterOutputStream {
 
   public NoFlushOutputStream(OutputStream out) {
     super(out);
   }
 
+  /**
+   * It is very important to override this method!! The underlying method from 
FilterOutputStream
+   * calls write a single byte at a time and will kill performance.
+   */
+  @Override
+  public void write(byte[] b, int off, int len) throws IOException {
+    out.write(b, off, len);
+  }
+
   @Override
   public void flush() {}
 

Reply via email to