You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2019/11/02 14:24:39 UTC

svn commit: r1869294 - in /jackrabbit/oak/branches/1.4/oak-core: ./ src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java

Author: reschke
Date: Sat Nov  2 14:24:39 2019
New Revision: 1869294

URL: http://svn.apache.org/viewvc?rev=1869294&view=rev
Log:
OAK-8016: RDBDocumentStore: minor improvements to GZIP compression of BLOB contents (merged r1852601 into 1.4)

Modified:
    jackrabbit/oak/branches/1.4/oak-core/   (props changed)
    jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java

Propchange: jackrabbit/oak/branches/1.4/oak-core/
------------------------------------------------------------------------------
  Merged /jackrabbit/oak/trunk/oak-store-document:r1852601

Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1869294&r1=1869293&r2=1869294&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Sat Nov  2 14:24:39 2019
@@ -26,6 +26,7 @@ import static org.apache.jackrabbit.oak.
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -1777,17 +1778,16 @@ public class RDBDocumentStore implements
         if (NOGZIP) {
             return bytes;
         } else {
-            try {
-                ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length());
-                GZIPOutputStream gos = new GZIPOutputStream(bos) {
-                    {
-                        // TODO: make this configurable
-                        this.def.setLevel(Deflater.BEST_SPEED);
-                    }
-                };
+            ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length / 2);
+            try (GZIPOutputStream gos = asGZIPOutputStream(bos, Deflater.BEST_SPEED)) {
                 gos.write(bytes);
                 gos.close();
-                return bos.toByteArray();
+                byte[] compressedBytes = bos.toByteArray();
+                if (LOG.isTraceEnabled()) {
+                    long ratio = (100L * compressedBytes.length) / bytes.length;
+                    LOG.trace("Gzipped {} bytes to {} ({}%)", bytes.length, compressedBytes.length, ratio);
+                }
+                return compressedBytes;
             } catch (IOException ex) {
                 LOG.error("Error while gzipping contents", ex);
                 throw new DocumentStoreException(ex);
@@ -1795,6 +1795,13 @@ public class RDBDocumentStore implements
         }
     }
 
+    private static GZIPOutputStream asGZIPOutputStream(OutputStream os, final int level) throws IOException {
+        return new GZIPOutputStream(os) {
+            {
+                this.def.setLevel(level);
+            }
+        };
+    }
 
     @Override
     public void setReadWriteMode(String readWriteMode) {