jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r425398 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state: ItemStateCache.java ItemStateReferenceCache.java LRUItemStateCache.java MLRUItemStateCache.java
Date Tue, 25 Jul 2006 14:14:52 GMT
Author: tripod
Date: Tue Jul 25 07:14:52 2006
New Revision: 425398

URL: http://svn.apache.org/viewvc?rev=425398&view=rev
Log:
Allow updating of cached item resource consumption.

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LRUItemStateCache.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java?rev=425398&r1=425397&r2=425398&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
Tue Jul 25 07:14:52 2006
@@ -100,4 +100,12 @@
      * @return a collection view of the values contained in this cache.
      */
     Collection values();
+
+    /**
+     * Informs the cache that the item was modified and the cache might need to
+     * recalc the items caching weight.
+     *
+     * @param id the id of the item that was modified.
+     */
+    void update(ItemId id);
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java?rev=425398&r1=425397&r2=425398&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
Tue Jul 25 07:14:52 2006
@@ -140,6 +140,14 @@
     /**
      * {@inheritDoc}
      */
+    public void update(ItemId id) {
+        // delegate
+        cache.update(id);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public boolean isEmpty() {
         // check primary cache
         return refs.isEmpty();

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LRUItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LRUItemStateCache.java?rev=425398&r1=425397&r2=425398&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LRUItemStateCache.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LRUItemStateCache.java
Tue Jul 25 07:14:52 2006
@@ -103,6 +103,13 @@
     /**
      * {@inheritDoc}
      */
+    public void update(ItemId id) {
+        // do nothing
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public boolean isEmpty() {
         return cache.isEmpty();
     }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java?rev=425398&r1=425397&r2=425398&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
Tue Jul 25 07:14:52 2006
@@ -39,7 +39,7 @@
     private static Logger log = LoggerFactory.getLogger(LRUItemStateCache.class);
 
     /** default maximum memory to use */
-    public static final int DEFAULT_MAX_MEM = 8 * 1024 * 1024;
+    public static final int DEFAULT_MAX_MEM = 4 * 1024 * 1024;
 
     /** the amount of memory the entries use */
     private long totalMem;
@@ -47,6 +47,9 @@
     /** the maximum of memory the cache may use */
     private final long maxMem;
 
+    /** the number of writes */
+    private long numWrites = 0;
+
     /**
      * A cache for <code>ItemState</code> instances
      */
@@ -99,6 +102,20 @@
     /**
      * {@inheritDoc}
      */
+    public void update(ItemId id) {
+        synchronized (cache) {
+            Entry entry = (Entry) cache.get(id);
+            if (entry != null) {
+                totalMem -= entry.size;
+                entry.recalc();
+                totalMem += entry.size;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void cache(ItemState state) {
         synchronized (cache) {
             ItemId id = state.getId();
@@ -114,7 +131,7 @@
                 id = (ItemId) cache.firstKey();
                 evict(id);
             }
-            if (log.isDebugEnabled()) {
+            if (numWrites++%10000 == 0 && log.isDebugEnabled()) {
                 log.info(this + " size=" + cache.size() + ", " + totalMem + "/" + maxMem);
             }
         }
@@ -191,11 +208,15 @@
 
         private final ItemState state;
 
-        private final long size;
+        private long size;
 
         public Entry(ItemState state) {
             this.state = state;
             this.size = 64 + state.calculateMemoryFootprint();
+        }
+
+        public void recalc() {
+            size = 64 + state.calculateMemoryFootprint();
         }
     }
 }



Mime
View raw message