jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1026023 - in /jackrabbit/branches/2.0: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/ jackr...
Date Thu, 21 Oct 2010 15:02:29 GMT
Author: jukka
Date: Thu Oct 21 15:02:28 2010
New Revision: 1026023

URL: http://svn.apache.org/viewvc?rev=1026023&view=rev
Log:
2.0: Merged revisions 1025981 and 1025985 (JCR-2699)

Added:
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/
      - copied from r1025985, jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/Cache.java
      - copied unchanged from r1025985, jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/Cache.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheAccessListener.java
      - copied unchanged from r1025985, jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheAccessListener.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheManager.java
      - copied unchanged from r1025985, jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cache/CacheManager.java
Removed:
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/Cache.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/CacheAccessListener.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/CacheManager.java
Modified:
    jackrabbit/branches/2.0/   (props changed)
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceManager.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/AbstractBundlePersistenceManager.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ManagedMLRUItemStateCacheFactory.java

Propchange: jackrabbit/branches/2.0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Oct 21 15:02:28 2010
@@ -1,6 +1,6 @@
 /jackrabbit/branches/1.5:794012,794100,794102
-/jackrabbit/branches/2.1:955309,955314,982266,982277,982505,998310,1025933,1025957,1025962,1025964
+/jackrabbit/branches/2.1:955309,955314,982266,982277,982505,998310,1025933,1025957,1025962,1025964,1025981,1025985
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935,897983,897992-897993,897996,898002,898042,898267,898325,898540,898677,898699,898701,898715,898872,899102,899181,899391,899393-899394,899583,899594,899643,900305,900310,900314,900453,900702,900736,900762-900763,900767,900782,901095,901122,901139,901144,901170,901176,901191,901193,901196,901216,901228,901285,902058,902062,926324,928888,936668,955222,955229,955307,955852,965539,996810,1001707,1002065-1002066,1002084,1002101-1002102,1002168,1002170,1002589,1002608,1002657
+/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935,897983,897992-897993,897996,898002,898042,898267,898325,898540,898677,898699,898701,898715,898872,899102,899181,899391,899393-899394,899583,899594,899643,900305,900310,900314,900453,900702,900736,900762-900763,900767,900782,901095,901122,901139,901144,901170,901176,901191,901193,901196,901216,901228,901285,902058,902062,926324,928888,936668,955222,955229,955307,955852,965539,996810,1001707,1002065-1002066,1002084,1002101-1002102,1002168,1002170,1002589,1002608,1002657,1002729,1003423,1003470

Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=1026023&r1=1026022&r2=1026023&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Thu Oct 21 15:02:28 2010
@@ -95,7 +95,7 @@ import org.apache.jackrabbit.core.retent
 import org.apache.jackrabbit.core.security.JackrabbitSecurityManager;
 import org.apache.jackrabbit.core.security.authentication.AuthContext;
 import org.apache.jackrabbit.core.security.simple.SimpleSecurityManager;
-import org.apache.jackrabbit.core.state.CacheManager;
+import org.apache.jackrabbit.core.cache.CacheManager;
 import org.apache.jackrabbit.core.state.ChangeLog;
 import org.apache.jackrabbit.core.state.ISMLocking;
 import org.apache.jackrabbit.core.state.ItemStateCacheFactory;

Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceManager.java?rev=1026023&r1=1026022&r2=1026023&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceManager.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceManager.java
Thu Oct 21 15:02:28 2010
@@ -58,6 +58,15 @@ import org.apache.jackrabbit.core.state.
  *       to close the persistence manager and release all acquired
  *       resources.
  * </ol>
+ *
+ * <h2>Concurrency</h2>
+ * <p>
+ * A persistence manager instance should be thread-safe and guarantee that
+ * the {@link #store(ChangeLog)} method calls are atomic. Any load() or
+ * exists() calls started after a store() call has returned must access
+ * the updated content. The client accessing a persistence manager must
+ * guarantee that no two concurrent {@link #store(ChangeLog)} calls will
+ * modify the same items.
  */
 public interface PersistenceManager {
 

Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java?rev=1026023&r1=1026022&r2=1026023&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
Thu Oct 21 15:02:28 2010
@@ -35,8 +35,8 @@ import org.apache.jackrabbit.core.persis
 import org.apache.jackrabbit.core.persistence.IterablePersistenceManager;
 import org.apache.jackrabbit.core.persistence.PMContext;
 import org.apache.jackrabbit.core.persistence.PersistenceManager;
-import org.apache.jackrabbit.core.util.StringIndex;
 import org.apache.jackrabbit.core.persistence.util.BundleBinding;
+import org.apache.jackrabbit.core.util.StringIndex;
 import org.apache.jackrabbit.core.persistence.util.BundleCache;
 import org.apache.jackrabbit.core.persistence.util.HashMapIndex;
 import org.apache.jackrabbit.core.persistence.util.LRUNodeIdCache;
@@ -405,7 +405,7 @@ public abstract class AbstractBundlePers
      *
      * Loads the state via the appropriate NodePropBundle.
      */
-    public synchronized NodeState load(NodeId id)
+    public NodeState load(NodeId id)
             throws NoSuchItemStateException, ItemStateException {
         NodePropBundle bundle = getBundle(id);
         if (bundle == null) {
@@ -419,7 +419,7 @@ public abstract class AbstractBundlePers
      *
      * Loads the state via the appropriate NodePropBundle.
      */
-    public synchronized PropertyState load(PropertyId id)
+    public PropertyState load(PropertyId id)
             throws NoSuchItemStateException, ItemStateException {
         NodePropBundle bundle = getBundle(id.getParentId());
         if (bundle == null) {
@@ -457,7 +457,7 @@ public abstract class AbstractBundlePers
      *
      * Loads the state via the appropriate NodePropBundle.
      */
-    public synchronized boolean exists(PropertyId id) throws ItemStateException {
+    public boolean exists(PropertyId id) throws ItemStateException {
         NodePropBundle bundle = getBundle(id.getParentId());
         return bundle != null && bundle.hasProperty(id.getName());
     }
@@ -467,7 +467,7 @@ public abstract class AbstractBundlePers
      *
      * Checks the existence via the appropriate NodePropBundle.
      */
-    public synchronized boolean exists(NodeId id) throws ItemStateException {
+    public boolean exists(NodeId id) throws ItemStateException {
         // anticipating a load followed by a exists
         return getBundle(id) != null;
     }
@@ -650,12 +650,14 @@ public abstract class AbstractBundlePers
         }
         NodePropBundle bundle = bundles.get(id);
         if (bundle == null) {
-            bundle = loadBundle(id);
-            if (bundle != null) {
-                bundle.markOld();
-                bundles.put(bundle);
-            } else {
-                missing.put(id);
+            synchronized (this) {
+                bundle = loadBundle(id);
+                if (bundle != null) {
+                    bundle.markOld();
+                    bundles.put(bundle);
+                } else {
+                    missing.put(id);
+                }
             }
         }
         return bundle;

Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/AbstractBundlePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/AbstractBundlePersistenceManager.java?rev=1026023&r1=1026022&r2=1026023&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/AbstractBundlePersistenceManager.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/AbstractBundlePersistenceManager.java
Thu Oct 21 15:02:28 2010
@@ -405,7 +405,7 @@ public abstract class AbstractBundlePers
      *
      * Loads the state via the appropriate NodePropBundle.
      */
-    public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException
{
+    public NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException
{
         NodePropBundle bundle = getBundle(id);
         if (bundle == null) {
             throw new NoSuchItemStateException(id.toString());
@@ -418,7 +418,7 @@ public abstract class AbstractBundlePers
      *
      * Loads the state via the appropriate NodePropBundle.
      */
-    public synchronized PropertyState load(PropertyId id) throws NoSuchItemStateException,
ItemStateException {
+    public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException
{
         NodePropBundle bundle = getBundle(id.getParentId());
         if (bundle == null) {
             throw new NoSuchItemStateException(id.toString());
@@ -455,7 +455,7 @@ public abstract class AbstractBundlePers
      *
      * Loads the state via the appropriate NodePropBundle.
      */
-    public synchronized boolean exists(PropertyId id) throws ItemStateException {
+    public boolean exists(PropertyId id) throws ItemStateException {
         NodePropBundle bundle = getBundle(id.getParentId());
         return bundle != null && bundle.hasProperty(id.getName());
     }
@@ -465,7 +465,7 @@ public abstract class AbstractBundlePers
      *
      * Checks the existence via the appropriate NodePropBundle.
      */
-    public synchronized boolean exists(NodeId id) throws ItemStateException {
+    public boolean exists(NodeId id) throws ItemStateException {
         // anticipating a load followed by a exists
         return getBundle(id) != null;
     }
@@ -648,12 +648,14 @@ public abstract class AbstractBundlePers
         }
         NodePropBundle bundle = bundles.get(id);
         if (bundle == null) {
-            bundle = loadBundle(id);
-            if (bundle != null) {
-                bundle.markOld();
-                bundles.put(bundle);
-            } else {
-                missing.put(id);
+            synchronized (this) {
+                bundle = loadBundle(id);
+                if (bundle != null) {
+                    bundle.markOld();
+                    bundles.put(bundle);
+                } else {
+                    missing.put(id);
+                }
             }
         }
         return bundle;

Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java?rev=1026023&r1=1026022&r2=1026023&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleCache.java
Thu Oct 21 15:02:28 2010
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.core.persistence.util;
 
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.jackrabbit.core.id.NodeId;
@@ -71,10 +73,14 @@ public class BundleCache {
             @Override
             protected boolean removeEldestEntry(
                     Map.Entry<NodeId, NodePropBundle> e) {
-                if (curSize > BundleCache.this.maxSize) {
+                long maxSize = BundleCache.this.maxSize;
+                if (curSize <= maxSize) {
+                    return false;
+                } else if (curSize - e.getValue().getSize() <= maxSize) {
                     curSize -= e.getValue().getSize();
                     return true;
                 } else {
+                    shrink();
                     return false;
                 }
             }
@@ -97,6 +103,20 @@ public class BundleCache {
      */
     public void setMaxSize(long maxSize) {
         this.maxSize = maxSize;
+
+        if (curSize > maxSize) {
+            shrink();
+        }
+    }
+
+    private void shrink() {
+        List<NodePropBundle> list =
+            new ArrayList<NodePropBundle>(bundles.values());
+        for (int i = list.size() - 1; curSize > maxSize && i >= 0; i--) {
+            NodePropBundle bundle = list.get(i);
+            curSize -= bundle.getSize();
+            bundles.remove(bundle.getId());
+        }
     }
 
     /**

Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java?rev=1026023&r1=1026022&r2=1026023&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
Thu Oct 21 15:02:28 2010
@@ -22,6 +22,8 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.collections.map.LinkedMap;
+import org.apache.jackrabbit.core.cache.Cache;
+import org.apache.jackrabbit.core.cache.CacheAccessListener;
 import org.apache.jackrabbit.core.id.ItemId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -84,10 +86,14 @@ public class MLRUItemStateCache implemen
                 maxMem / 1024, 0.75f, true /* access-ordered */) {
             @Override
             protected boolean removeEldestEntry(Map.Entry<ItemId, Entry> e) {
-                if (totalMem > MLRUItemStateCache.this.maxMem) {
+                long maxMem = MLRUItemStateCache.this.maxMem;
+                if (totalMem <= maxMem) {
+                    return false;
+                } else if (totalMem - e.getValue().size <= maxMem) {
                     totalMem -= e.getValue().size;
                     return true;
                 } else {
+                    shrink();
                     return false;
                 }
             }
@@ -248,21 +254,21 @@ public class MLRUItemStateCache implemen
 
             // remove items, if too many
             if (totalMem > maxMem) {
-                totalMem = 0;
-                List<Map.Entry<ItemId, Entry>> entries =
-                    new ArrayList<Map.Entry<ItemId, Entry>>(cache.entrySet());
-                for (Map.Entry<ItemId, Entry> entry : entries) {
-                    long entrySize = entry.getValue().size;
-                    if (totalMem + entrySize > maxMem) {
-                        cache.remove(entry.getKey());
-                    } else {
-                        totalMem += entrySize;
-                    }
-                }
+                shrink();
             }
         }
     }
 
+    private void shrink() {
+        List<Map.Entry<ItemId, Entry>> list =
+            new ArrayList<Map.Entry<ItemId, Entry>>(cache.entrySet());
+        for (int i = list.size() - 1; totalMem > maxMem && i >= 0; i--) {
+            Map.Entry<ItemId, Entry> last = list.get(i);
+            totalMem -= last.getValue().size;
+            cache.remove(last.getKey());
+        }
+    }
+
     /**
      * Set the cache access listener. Only one listener per cache is supported.
      *

Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ManagedMLRUItemStateCacheFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ManagedMLRUItemStateCacheFactory.java?rev=1026023&r1=1026022&r2=1026023&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ManagedMLRUItemStateCacheFactory.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ManagedMLRUItemStateCacheFactory.java
Thu Oct 21 15:02:28 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.state;
 
+import org.apache.jackrabbit.core.cache.CacheManager;
+
 /**
  * This class constructs new MLRUItemStateCache.
  * This class adds the new caches to the cache manager,



Mime
View raw message