jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1452326 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
Date Mon, 04 Mar 2013 14:31:27 GMT
Author: thomasm
Date: Mon Mar  4 14:31:26 2013
New Revision: 1452326

URL: http://svn.apache.org/r1452326
Log:
OAK-619 Lock-free MongoMK implementation (bugfixes)

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java?rev=1452326&r1=1452325&r2=1452326&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
Mon Mar  4 14:31:26 2013
@@ -156,6 +156,7 @@ public class Commit {
                     for (UpdateOp op : newNodes) {
                         op.unset(UpdateOp.ID);
                         op.addMapEntry(UpdateOp.DELETED + "." + revision.toString(), "false");
+                        op.increment(UpdateOp.WRITE_COUNT, 1);
                         createOrUpdateNode(store, op);
                     }
                 }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java?rev=1452326&r1=1452325&r2=1452326&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
Mon Mar  4 14:31:26 2013
@@ -38,6 +38,8 @@ import org.apache.jackrabbit.mk.json.Jso
 import org.apache.jackrabbit.mongomk.impl.blob.MongoBlobStore;
 import org.apache.jackrabbit.mongomk.prototype.Node.Children;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.mongodb.DB;
 
@@ -46,6 +48,8 @@ import com.mongodb.DB;
  */
 public class MongoMK implements MicroKernel {
     
+    private static final Logger LOG = LoggerFactory.getLogger(MongoMK.class);
+    
     /**
      * The delay for asynchronous operations (delayed commit propagation and
      * cache update).
@@ -637,19 +641,41 @@ public class MongoMK implements MicroKer
 
         private static final long serialVersionUID = 1L;
         private int size;
+        private TreeSet<K> keySet = new TreeSet<K>();
 
         Cache(int size) {
             super(size, (float) 0.75, true);
             this.size = size;
         }
+        
+        public synchronized V put(K key, V value) {
+            keySet.add(key);
+            return super.put(key, value);
+        }
+        
+        public synchronized V remove(Object key) {
+            keySet.remove(key);
+            return super.remove(key);
+        }
 
-        protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
-            return size() > size;
+        protected synchronized boolean removeEldestEntry(Map.Entry<K, V> eldest) {
+            boolean remove = size() > size;
+            if (remove) {
+                Object k = eldest.getKey();
+                if (k != null) {
+                    keySet.remove(k);
+                }
+            }
+            return remove;
         }
         
         public String toString() {
             return super.toString().replace(',', '\n');
         }
+        
+        // public synchronized SortedSet<K> subSet(K fromElement, K toElement) {
+        //   return keySet.subSet(fromElement, toElement);
+        // }
 
     }
 
@@ -706,7 +732,11 @@ public class MongoMK implements MicroKer
             set.addAll(added);
             c2.children.addAll(set);
             if (nodeChildrenCache.get(id) != null) {
-                throw new AssertionError("New child list already cached");
+                // TODO should not happend, 
+                // probably a problem with add/delete/add
+                MicroKernelException e = new MicroKernelException(
+                        "New child list already cached for id " + id);
+                LOG.error("Error updating the cache", e);
             }
             nodeChildrenCache.put(id, c2);
         }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java?rev=1452326&r1=1452325&r2=1452326&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
Mon Mar  4 14:31:26 2013
@@ -98,7 +98,18 @@ public class SimpleTest {
         assertEquals("{\"name\":\"Hallo\",\":childNodeCount\":0}", test);
         mk.dispose();
     }
-    
+
+    @Test
+    public void reAddDeleted2() {
+        MongoMK mk = createMK();
+        String rev = mk.commit("/", "+\"test\":{\"child\": {}}", null, null);
+        rev = mk.commit("/", "-\"test\"", rev, null);
+        rev = mk.commit("/", "+\"test\":{}", null, null);
+        String test = mk.getNodes("/test", rev, 0, 0, Integer.MAX_VALUE, null);
+        assertEquals("{\":childNodeCount\":0}", test);
+        mk.dispose();
+    }
+
     @Test
     public void escapePropertyName() {
         MongoMK mk = createMK();



Mime
View raw message