Author: mreutegg
Date: Wed Jul 26 13:01:34 2017
New Revision: 1803042

URL: http://svn.apache.org/viewvc?rev=1803042&view=rev
Log:
OAK-6462: Incorrect memory calculation for bundled node states

Merged revisions 1802262,1802286 from trunk

Modified:
    jackrabbit/oak/branches/1.6/   (props changed)
    
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
    
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java

Propchange: jackrabbit/oak/branches/1.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 26 13:01:34 2017
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782476,1782770,1782945,1782966,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783731,1783733,1783738,1783742,1783773,1783855,1783891,1784023,1784034,1784130,1784162,1784251,1784401,1784551,1784574,1784689,1785095,1785108,1785283,1785838,1785917,1785919,1785946,1786122,1787074,1787145,1787217,1787425,1788056,1788378,1788387-1788389,1788850,1789056,1789534,1790382,1792463,1792742,1792746,1793013,1793088,1793618,1793627,1793644,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988,1798035,1798834,1799219,1799389,1799393,1799924,1800269,1800606,1800613,1800974,1801118-1801119,1801675,1802260,1802548,1802973,1803026
+/jackrabbit/oak/trunk:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782476,1782770,1782945,1782966,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783731,1783733,1783738,1783742,1783773,1783855,1783891,1784023,1784034,1784130,1784162,1784251,1784401,1784551,1784574,1784689,1785095,1785108,1785283,1785838,1785917,1785919,1785946,1786122,1787074,1787145,1787217,1787425,1788056,1788378,1788387-1788389,1788850,1789056,1789534,1790382,1792463,1792742,1792746,1793013,1793088,1793618,1793627,1793644,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988,1798035,1798834,1799219,1799389,1799393,1799924,1800269,1800606,1800613,1800974,1801118-1801119,1801675,1802260,1802262,1802286,1802548,1802973,1803026
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java?rev=1803042&r1=1803041&r2=1803042&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
 (original)
+++ 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
 Wed Jul 26 13:01:34 2017
@@ -440,7 +440,7 @@ public class DocumentNodeState extends A
                     // shallow memory:
                     // - 8 bytes per reference in values list
                     // - 48 bytes per string
-                    // double useage per property because of parsed 
PropertyState
+                    // double usage per property because of parsed 
PropertyState
                     size += (56 + propState.size(i) * 2) * 2;
                 }
             } else {
@@ -448,7 +448,7 @@ public class DocumentNodeState extends A
                 // referencing the binary in the blob store
                 // double the size because the parsed PropertyState
                 // will have a similarly sized blobId as well
-                size += 
(long)estimateMemoryUsage(getPropertyAsString(entry.getKey())) * 2;
+                size += (long)estimateMemoryUsage(asString(entry.getValue())) 
* 2;
             }
         }
         if (size > Integer.MAX_VALUE) {

Modified: 
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java?rev=1803042&r1=1803041&r2=1803042&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
 Wed Jul 26 13:01:34 2017
@@ -29,6 +29,8 @@ import javax.annotation.Nonnull;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
+
+import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
@@ -40,6 +42,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
 import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
 import org.apache.jackrabbit.oak.plugins.document.PathRev;
+import org.apache.jackrabbit.oak.plugins.document.RandomStream;
 import org.apache.jackrabbit.oak.plugins.document.TestNodeObserver;
 import org.apache.jackrabbit.oak.plugins.document.TestUtils;
 import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
@@ -59,7 +62,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -185,6 +187,31 @@ public class DocumentBundlingTest {
         assertThat(bundledMem, is(greaterThan(nonBundledMem)));
     }
 
+    @Test
+    public void memoryWithBinary() throws Exception {
+        Blob blob = store.createBlob(new RandomStream(1024, 17));
+        NodeBuilder builder = store.getRoot().builder();
+        NodeBuilder bundledFileNode = newNode("nt:file");
+        bundledFileNode.child("jcr:content").setProperty("jcr:data", blob);
+        builder.child("test").setChildNode("book.jpg", 
bundledFileNode.getNodeState());
+
+        //Create a non bundled NodeState structure nt:File vs nt:file
+        NodeBuilder nonBundledFileNode = newNode("nt:File");
+        nonBundledFileNode.child("jcr:content").setProperty("jcr:data", blob);
+        builder.child("test").setChildNode("book2.jpg", 
nonBundledFileNode.getNodeState());
+        merge(builder);
+
+        NodeState root = store.getRoot();
+        DocumentNodeState bundledFile = asDocumentState(getNode(root, 
"/test/book.jpg"));
+        DocumentNodeState nonBundledFile = asDocumentState(getNode(root, 
"/test/book2.jpg"));
+        DocumentNodeState nonBundledContent = asDocumentState(getNode(root, 
"/test/book2.jpg/jcr:content"));
+
+        int nonBundledMem = nonBundledFile.getMemory() + 
nonBundledContent.getMemory();
+        int bundledMem = bundledFile.getMemory();
+
+        assertThat(bundledMem, is(greaterThan(nonBundledMem)));
+    }
+
     @Test
     public void bundlorUtilsIsBundledMethods() throws Exception{
         NodeBuilder builder = store.getRoot().builder();


Reply via email to