jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1025957 - in /jackrabbit/branches/2.1: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/
Date Thu, 21 Oct 2010 11:30:53 GMT
Author: jukka
Date: Thu Oct 21 11:30:52 2010
New Revision: 1025957

URL: http://svn.apache.org/viewvc?rev=1025957&view=rev
Log:
2.1: Merged revisions 1002084, 1002101 and 1002102 (JCR-2699)

Modified:
    jackrabbit/branches/2.1/   (props changed)
    jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java
    jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/LRUNodeIdCache.java
    jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
    jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
    jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java

Propchange: jackrabbit/branches/2.1/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Oct 21 11:30:52 2010
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:931121,931479,931483-931484,931504,931609,931613,931838,931919,932318-932319,933144,933197,933203,933213,933216,933554,933646,933694,934405,934412,934849,935557,936668,938099,945528,950440,950680,955222,955229,955307,955852,961487,961626,964362,965539,986682,986686,986715,991144,996810,1001707,1002065-1002066
+/jackrabbit/trunk:931121,931479,931483-931484,931504,931609,931613,931838,931919,932318-932319,933144,933197,933203,933213,933216,933554,933646,933694,934405,934412,934849,935557,936668,938099,945528,950440,950680,955222,955229,955307,955852,961487,961626,964362,965539,986682,986686,986715,991144,996810,1001707,1002065-1002066,1002084,1002101-1002102

Modified: jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java?rev=1025957&r1=1025956&r2=1025957&view=diff
==============================================================================
--- jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java
(original)
+++ jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java
Thu Oct 21 11:30:52 2010
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.core.persistence.util;
 
-import org.apache.commons.collections.map.LinkedMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
 import org.apache.jackrabbit.core.id.NodeId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -54,15 +56,29 @@ public class BundleCache {
     /**
      * a map of the cache entries
      */
-    private LinkedMap bundles = new LinkedMap();
+    private final LinkedHashMap<NodeId, NodePropBundle> bundles;
 
     /**
      * Creates a new BundleCache
      *
      * @param maxSize the maximum size of this cache in bytes.
      */
+    @SuppressWarnings("serial")
     public BundleCache(long maxSize) {
         this.maxSize = maxSize;
+        this.bundles = new LinkedHashMap<NodeId, NodePropBundle>(
+                (int) maxSize / 1024, 0.75f, true /* access-ordered */) {
+            @Override
+            protected boolean removeEldestEntry(
+                    Map.Entry<NodeId, NodePropBundle> e) {
+                if (curSize > BundleCache.this.maxSize) {
+                    curSize -= e.getValue().getSize();
+                    return true;
+                } else {
+                    return false;
+                }
+            }
+        };
     }
 
     /**
@@ -90,11 +106,9 @@ public class BundleCache {
      * @param id the id of the bundle
      * @return the cached bundle or <code>null</code>
      */
-    public NodePropBundle get(NodeId id) {
-        Entry entry = (Entry) bundles.remove(id);
-        if (entry != null) {
-            // at end
-            bundles.put(id, entry);
+    public synchronized NodePropBundle get(NodeId id) {
+        NodePropBundle bundle = bundles.get(id);
+        if (bundle != null) {
             hits++;
         } else {
             misses++;
@@ -106,32 +120,21 @@ public class BundleCache {
             log.info("num=" + bundles.size() + " mem=" + c + "k max=" + m + "k avg=" + a
                     + " hits=" + hits + " miss=" + misses);
         }
-        return entry == null ? null : entry.bundle;
+        return bundle;
     }
 
     /**
-     * Puts a bunlde to the cache. If the new size of the cache exceeds the
-     * {@link #getMaxSize() max size} of the cache it will remove bundles from
-     * this cache until the limit is satisfied.
+     * Puts a bundle to the cache.
      *
      * @param bundle the bunlde to put to the cache
      */
-    public void put(NodePropBundle bundle) {
-        Entry entry = (Entry) bundles.remove(bundle.getId());
-        if (entry == null) {
-            entry = new Entry(bundle, bundle.getSize());
-        } else {
-            curSize -= entry.size;
-            entry.bundle = bundle;
-            entry.size = bundle.getSize();
-        }
-        bundles.put(bundle.getId(), entry);
-        curSize += entry.size;
-        // now limit size of cache
-        while (curSize > maxSize) {
-            entry = (Entry) bundles.remove(0);
-            curSize -= entry.size;
+    public synchronized void put(NodePropBundle bundle) {
+        NodePropBundle previous = bundles.get(bundle.getId());
+        if (previous != null) {
+            curSize -= previous.getSize();
         }
+        bundles.put(bundle.getId(), bundle);
+        curSize += bundle.getSize();
     }
 
     /**
@@ -141,7 +144,7 @@ public class BundleCache {
      * @return <code>true</code> if the bundle is cached;
      *         <code>false</code> otherwise.
      */
-    public boolean contains(NodeId id) {
+    public synchronized boolean contains(NodeId id) {
         return bundles.containsKey(id);
     }
 
@@ -152,51 +155,22 @@ public class BundleCache {
      * @return the previously cached bunlde or <code>null</code> of the bundle
      *         was not cached.
      */
-    public NodePropBundle remove(NodeId id) {
-        Entry entry = (Entry) bundles.remove(id);
-        if (entry != null) {
-            curSize -= entry.size;
-            return entry.bundle;
-        } else {
-            return null;
+    public synchronized NodePropBundle remove(NodeId id) {
+        NodePropBundle bundle = bundles.remove(id);
+        if (bundle != null) {
+            curSize -= bundle.getSize();
         }
+        return bundle;
     }
 
     /**
      * Clears this cache and removes all bundles.
      */
-    public void clear() {
+    public synchronized void clear() {
         bundles.clear();
         curSize = 0;
         hits = 0;
         misses = 0;
     }
 
-    /**
-     * Internal class that holds the bundles.
-     */
-    private static final class Entry {
-
-        /**
-         * the cached bundle
-         */
-        private NodePropBundle bundle;
-
-        /**
-         * the memory usage of the bundle in bytes
-         */
-        private long size;
-
-        /**
-         * Creates a new entry.
-         *
-         * @param bundle the bundle to cache
-         * @param size the size of the bundle
-         */
-        public Entry(NodePropBundle bundle, long size) {
-            this.bundle = bundle;
-            this.size = size;
-        }
-    }
-
 }

Modified: jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/LRUNodeIdCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/LRUNodeIdCache.java?rev=1025957&r1=1025956&r2=1025957&view=diff
==============================================================================
--- jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/LRUNodeIdCache.java
(original)
+++ jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/LRUNodeIdCache.java
Thu Oct 21 11:30:52 2010
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.core.persistence.util;
 
-import org.apache.commons.collections.map.LinkedMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
 import org.apache.jackrabbit.core.id.NodeId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -34,7 +36,7 @@ public class LRUNodeIdCache {
     /**
      * The maximum number of ids to cache
      */
-    private long maxSize = 10240;
+    private static final int maxSize = 10240;
 
     /**
      * the number of cache hits
@@ -49,7 +51,14 @@ public class LRUNodeIdCache {
     /**
      * the map of cached ids
      */
-    private final LinkedMap missing = new LinkedMap();
+    @SuppressWarnings("serial")
+    private final LinkedHashMap<NodeId, NodeId> missing =
+        new LinkedHashMap<NodeId, NodeId>(maxSize * 2, 0.75f, true) {
+            @Override
+            protected boolean removeEldestEntry(Map.Entry<NodeId, NodeId> e) {
+                return size() > maxSize;
+            }
+        };
 
     /**
      * Checks if the given id is contained in this cached.
@@ -58,31 +67,25 @@ public class LRUNodeIdCache {
      * @return <code>true</code> if the id is cached;
      *         <code>false</code> otherwise.
      */
-    public boolean contains(NodeId id) {
-        Object o = missing.remove(id);
-        if (o == null) {
-            misses++;
-        } else {
-            missing.put(id, id);
+    public synchronized boolean contains(NodeId id) {
+        boolean rv = missing.get(id) != null;
+        if (rv) {
             hits++;
+        } else {
+            misses++;
         }
         if (log.isInfoEnabled() && (hits + misses) % 10000 == 0) {
             log.info("num=" + missing.size() + "/" + maxSize + " hits=" + hits + " miss="
+ misses);
         }
-        return o != null;
+        return rv;
     }
 
     /**
      * Puts the given id to this cache.
      * @param id the id to put.
      */
-    public void put(NodeId id) {
-        if (!missing.containsKey(id)) {
-            if (missing.size() == maxSize) {
-                missing.remove(0);
-            }
-            missing.put(id, id);
-        }
+    public synchronized void put(NodeId id) {
+        missing.put(id, id);
     }
 
     /**
@@ -91,14 +94,14 @@ public class LRUNodeIdCache {
      * @return <code>true</code> if the id was cached;
      *         <code>false</code> otherwise.
      */
-    public boolean remove(NodeId id) {
+    public synchronized boolean remove(NodeId id) {
         return missing.remove(id) != null;
     }
 
     /**
      * Clears this cache.
      */
-    public void clear() {
+    public synchronized void clear() {
         missing.clear();
     }
 

Modified: jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java?rev=1025957&r1=1025956&r2=1025957&view=diff
==============================================================================
--- jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
(original)
+++ jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
Thu Oct 21 11:30:52 2010
@@ -421,4 +421,5 @@ public abstract class ItemState {
      * @return the approximate memory consumption of this state.
      */
     public abstract long calculateMemoryFootprint();
+
 }

Modified: jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java?rev=1025957&r1=1025956&r2=1025957&view=diff
==============================================================================
--- jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
(original)
+++ jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
Thu Oct 21 11:30:52 2010
@@ -820,27 +820,26 @@ public class NodeState extends ItemState
     /**
      * {@inheritDoc}
      */
+    @Override
     public long calculateMemoryFootprint() {
         /*
         private Name nodeTypeName;
         private Set mixinTypeNames = Collections.EMPTY_SET;
         private NodeId id;
         private NodeId parentId;
-        private NodeDefId defId;
         private ChildNodeEntries childNodeEntries = new ChildNodeEntries();
-        private boolean sharedChildNodeEntries = false;
         private HashSet propertyNames = new HashSet();
-        private boolean sharedPropertyNames = false;
+        private boolean sharedSet = Set<NodeId>;
+        private boolean sharedSetRW = false;
+        private NodeStateListener listener = ...;
 
-        we assume an average Name localname of 30 chars.
-        NodeId = 8 + UUID(24) + hashcode(4) = 36
-        Name = 8 + hash(4) + string(38+2*len) + namespace(4) + localName(38+2*len) ~ 250
-        NodeDefId = 8 + id(4) = 12
-        ChildNodeEntries = 8 + n * (name(256) + index(4) + id(36) + hashentry(16)) ~ n*300
-        PropNames = 8 + n * ( name(250))
+        We assume only 16 bytes per name or node id,
+        as they are shared between states
+        ChildNodeEntries = 8 + n * (name(16) + index(4) + id(16) + hashentry(16)) ~ n*52
+        MixinTypeNames/PropNames = 8 + n * (name(16) + hashentry(16))
         */
-        return 350 + mixinTypeNames.size() * 250 + childNodeEntries.size() * 300
-                + propertyNames.size() * 250;
+        return 100 + mixinTypeNames.size() * 32 + childNodeEntries.size() * 52
+                + propertyNames.size() * 32;
     }
 
     /**

Modified: jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java?rev=1025957&r1=1025956&r2=1025957&view=diff
==============================================================================
--- jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
(original)
+++ jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
Thu Oct 21 11:30:52 2010
@@ -196,20 +196,21 @@ public class PropertyState extends ItemS
     /**
      * {@inheritDoc}
      */
+    @Override
     public long calculateMemoryFootprint() {
         /*
         private PropertyId id;
         private InternalValue[] values;
         private int type;
         private boolean multiValued;
-        private PropDefId defId;
 
-        we assume an average Name localname of 30 chars.
-        PropertyId = 8 + nodeId(36) * name(250) + hash(4) ~ 300;
-        NodeDefId = 8 + id(4) = 12
+        We assume only 16 bytes per name or node id,
+        as they are shared between states
+        PropertyId = 8 + nodeId(16) + name(16) + hash(4) ~ 44;
         InternalValue = 8 + n * (values) ~ 8 + n*100;
         value=approx 100 bytes.
         */
-        return 350 + values.length * 100;
+        return 64 + values.length * 100;
     }
+
 }



Mime
View raw message