jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1453320 - /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
Date Wed, 06 Mar 2013 13:03:06 GMT
Author: mreutegg
Date: Wed Mar  6 13:03:06 2013
New Revision: 1453320

URL: http://svn.apache.org/r1453320
Log:
OAK-619 Lock-free MongoMK implementation
- remember branch commits and ignore them in getHeadRevision()

Modified:
    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/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java?rev=1453320&r1=1453319&r2=1453320&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 Mar  6 13:03:06 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.mongomk.pr
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -129,8 +130,12 @@ public class MongoMK implements MicroKer
     private Revision headRevision;
     
     private Thread backgroundThread;
-    
-    private final Map<String, String> branchCommits = new HashMap<String, String>();
+
+    /**
+     * Maps branch commit revision to revision it is based on
+     */
+    private final Map<String, String> branchCommits =
+            Collections.synchronizedMap(new HashMap<String, String>());
 
     /**
      * Create a new in-memory MongoMK used for testing.
@@ -313,7 +318,11 @@ public class MongoMK implements MicroKer
 
     @Override
     public String getHeadRevision() throws MicroKernelException {
-        return headRevision.toString();
+        String head = headRevision.toString();
+        while (branchCommits.containsKey(head)) {
+            head = branchCommits.get(head);
+        }
+        return head;
     }
 
     @Override
@@ -466,8 +475,11 @@ public class MongoMK implements MicroKer
         if (revisionId.startsWith("b")) {
             // just commit to head currently
             applyCommit(commit);
+            // remember branch commit
+            branchCommits.put(rev.toString(), revisionId.substring(1));
+
             return "b" + rev.toString();
-            
+
             // String jsonBranch = branchCommits.remove(revisionId);
             // jsonBranch += commit.getDiff().toString();
             // String branchRev = revisionId + "+";
@@ -594,15 +606,24 @@ public class MongoMK implements MicroKer
     @Override
     public String merge(String branchRevisionId, String message)
             throws MicroKernelException {
+        // TODO improve implementation if needed
+        if (!branchRevisionId.startsWith("b")) {
+            throw new MicroKernelException("Not a branch: " + branchRevisionId);
+        }
+
         // reading from the branch is reading from the trunk currently
         String revisionId = branchRevisionId.substring(1).replace('+', ' ').trim();
+        String baseRevId = revisionId;
+        while (baseRevId != null) {
+            baseRevId = branchCommits.remove(baseRevId);
+        }
         return revisionId;
-        
+
         // TODO improve implementation if needed
         // if (!branchRevisionId.startsWith("b")) {
         //     throw new MicroKernelException("Not a branch: " + branchRevisionId);
         // }
-        // 
+        //
         // String commit = branchCommits.remove(branchRevisionId);
         // return commit("", commit, null, null);
     }



Mime
View raw message