jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1450808 - in /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype: Commit.java MongoMK.java
Date Wed, 27 Feb 2013 15:30:13 GMT
Author: thomasm
Date: Wed Feb 27 15:30:12 2013
New Revision: 1450808

URL: http://svn.apache.org/r1450808
Log:
OAK-619 Lock-free MongoMK implementation (support multiple MongoMK connecting to the same
MongoDB)

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

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=1450808&r1=1450807&r2=1450808&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
Wed Feb 27 15:30:12 2013
@@ -33,8 +33,18 @@ import org.apache.jackrabbit.oak.commons
  */
 public class Commit {
     
-    // TODO too small
-    private static final int MAX_MAP_SIZE = 16 * 1024;
+    /**
+     * The maximum size of a document. If it is larger, it is split.
+     */
+    // TODO check which value is the best one
+    private static final int MAX_DOCUMENT_SIZE = 16 * 1024;
+    
+    /**
+     * Whether to purge old revisions if a node gets too large. If false, old
+     * revisions are stored in a separate document. If true, old revisions are
+     * removed (purged).
+     */
+    private static final boolean PURGE_OLD_REVISIONS = true;
     
     private final MongoMK mk;
     private final Revision revision;
@@ -133,34 +143,45 @@ public class Commit {
             newNodes.add(root);
             root = null;
         }
-        if (newNodes.size() > 0) {
-            store.create(Collection.NODES, newNodes);
-        }
-        for (UpdateOp op : changedNodes) {
-            createOrUpdateNode(store, op);
-        }
-        if (root != null) {
-            long increment = mk.getWriteCountIncrement(commitRoot);
-            root.increment(UpdateOp.WRITE_COUNT, 1 + increment);
-            root.addMapEntry(UpdateOp.REVISIONS + "." + revision.toString(), "true");
-            createOrUpdateNode(store, root);
-            operations.put(commitRoot, root);
+        try {
+            if (newNodes.size() > 0) {
+                store.create(Collection.NODES, newNodes);
+            }
+            for (UpdateOp op : changedNodes) {
+                createOrUpdateNode(store, op);
+            }
+            if (root != null) {
+                long increment = mk.getWriteCountIncrement(commitRoot);
+                root.increment(UpdateOp.WRITE_COUNT, 1 + increment);
+                root.addMapEntry(UpdateOp.REVISIONS + "." + revision.toString(), "true");
+                createOrUpdateNode(store, root);
+                operations.put(commitRoot, root);
+            }
+        } catch (MicroKernelException e) {
+            throw new MicroKernelException("Exception committing " + diff.toString(), e);
         }
     }
     
     private void createOrUpdateNode(DocumentStore store, UpdateOp op) {
         Map<String, Object> map = store.createOrUpdate(Collection.NODES, op);
         int size = Utils.getMapSize(map);
-        if (size > MAX_MAP_SIZE) {
+        if (size > MAX_DOCUMENT_SIZE) {
             UpdateOp[] split = splitDocument(map);
             
             // TODO check if the new main document is actually smaller;
             // otherwise, splitting doesn't make sense
             
             // the old version
-            store.createOrUpdate(Collection.NODES, split[0]);
+            UpdateOp old = split[0];
+            if (old != null) {
+                store.createOrUpdate(Collection.NODES, old);
+            }
+            
             // the (shrunken) main document
-            store.createOrUpdate(Collection.NODES, split[1]);
+            UpdateOp main = split[1];
+            if (main != null) {
+                store.createOrUpdate(Collection.NODES, main);
+            }
         }
         // TODO detect conflicts here
         Long count = (Long) map.get(UpdateOp.WRITE_COUNT);
@@ -218,6 +239,9 @@ public class Commit {
                 }
             }
         }
+        if (PURGE_OLD_REVISIONS) {
+            old = null;
+        }
         return new UpdateOp[]{old, main};
     }
 

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=1450808&r1=1450807&r2=1450808&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
Wed Feb 27 15:30:12 2013
@@ -208,7 +208,7 @@ public class MongoMK implements MicroKer
             return requestRevision.compareRevisionTime(x) >= 0;
         }
         // TODO currently we only compare the timestamps
-        return x.compareRevisionTime(requestRevision) >= 0;
+        return requestRevision.compareRevisionTime(x) >= 0;
     }
     
     boolean isRevisionNewer(Revision x, Revision previous) {
@@ -526,7 +526,7 @@ public class MongoMK implements MicroKer
     }
     
     private static String stripBranchRevMarker(String revisionId){
-        if(revisionId.startsWith("b")){
+        if (revisionId.startsWith("b")) {
             return revisionId.substring(1);
         }
         return revisionId;



Mime
View raw message