jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1501767 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/mongomk/ test/java/org/apache/jackrabbit/oak/plugins/mongomk/
Date Wed, 10 Jul 2013 13:42:51 GMT
Author: mreutegg
Date: Wed Jul 10 13:42:50 2013
New Revision: 1501767

URL: http://svn.apache.org/r1501767
Log:
OAK-619 Lock-free MongoMK implementation
- Improved rebase implementation with more tests enabled

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Branch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMKRebaseTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Branch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Branch.java?rev=1501767&r1=1501766&r2=1501767&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Branch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Branch.java
Wed Jul 10 13:42:50 2013
@@ -35,31 +35,61 @@ class Branch {
     /**
      * The commits to the branch
      */
-    private final TreeMap<Revision, UnsavedModifications> commits;
+    private final TreeMap<Revision, Commit> commits;
 
-    private volatile Revision base;
+    private final Revision base;
 
     Branch(@Nonnull SortedSet<Revision> commits,
            @Nonnull Revision base,
            @Nonnull Revision.RevisionComparator comparator) {
         this.base = checkNotNull(base);
-        this.commits = new TreeMap<Revision, UnsavedModifications>(
+        this.commits = new TreeMap<Revision, Commit>(
                 checkNotNull(comparator));
         for (Revision r : commits) {
-            this.commits.put(r, new UnsavedModifications());
+            this.commits.put(r, new Commit(base));
         }
     }
 
+    /**
+     * @return the initial base of this branch.
+     */
     Revision getBase() {
         return base;
     }
 
-    public void setBase(Revision base) {
-        this.base = base;
+    /**
+     * Returns the base revision for the given branch revision <code>r</code>.
+     *
+     * @param r revision of a commit in this branch.
+     * @return the base revision for <code>r</code>.
+     * @throws IllegalArgumentException if <code>r</code> is not a commit of
+     *                                  this branch.
+     */
+    synchronized Revision getBase(Revision r) {
+        Commit c = commits.get(r);
+        if (c == null) {
+            throw new IllegalArgumentException(
+                    "Revision " + r + " is not a commit in this branch");
+        }
+        return c.getBase();
     }
+
+    /**
+     * Rebases the last commit of this branch to the given revision.
+     *
+     * @param head the new head of the branch.
+     * @param base rebase to this revision.
+     */
+    synchronized void rebase(Revision head, Revision base) {
+        Revision last = commits.lastKey();
+        checkArgument(commits.comparator().compare(head, last) > 0);
+        commits.put(head, new Commit(base));
+    }
+
     synchronized void addCommit(@Nonnull Revision r) {
-        checkArgument(commits.comparator().compare(r, commits.lastKey()) > 0);
-        commits.put(r, new UnsavedModifications());
+        Revision last = commits.lastKey();
+        checkArgument(commits.comparator().compare(r, last) > 0);
+        commits.put(r, new Commit(commits.get(last).getBase()));
     }
 
     synchronized SortedSet<Revision> getCommits() {
@@ -90,12 +120,12 @@ class Branch {
      */
     @Nonnull
     public synchronized UnsavedModifications getModifications(@Nonnull Revision r) {
-        UnsavedModifications modifications = commits.get(r);
-        if (modifications == null) {
+        Commit c = commits.get(r);
+        if (c == null) {
             throw new IllegalArgumentException(
                     "Revision " + r + " is not a commit in this branch");
         }
-        return modifications;
+        return c.getModifications();
     }
 
     /**
@@ -108,8 +138,8 @@ class Branch {
      */
     public synchronized void applyTo(@Nonnull UnsavedModifications trunk) {
         checkNotNull(trunk);
-        for (UnsavedModifications modifications : commits.values()) {
-            modifications.applyTo(trunk);
+        for (Commit c : commits.values()) {
+            c.getModifications().applyTo(trunk);
         }
     }
 
@@ -129,12 +159,30 @@ class Branch {
             if (readRevision.compareRevisionTime(r) < 0) {
                 continue;
             }
-            UnsavedModifications modifications = commits.get(r);
-            Revision modRevision = modifications.get(path);
+            Commit c = commits.get(r);
+            Revision modRevision = c.getModifications().get(path);
             if (modRevision != null) {
                 return modRevision;
             }
         }
         return null;
     }
+
+    private static final class Commit {
+
+        private final UnsavedModifications modifications = new UnsavedModifications();
+        private final Revision base;
+
+        Commit(Revision base) {
+            this.base = base;
+        }
+
+        Revision getBase() {
+            return base;
+        }
+
+        UnsavedModifications getModifications() {
+            return modifications;
+        }
+    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java?rev=1501767&r1=1501766&r2=1501767&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
Wed Jul 10 13:42:50 2013
@@ -477,7 +477,7 @@ public class MongoMK implements MicroKer
             // reset requestRevision to branch base revision to make
             // sure we don't include revisions committed after branch
             // was created
-            requestRevision = b.getBase();
+            requestRevision = b.getBase(requestRevision);
         }
         return revisionComparator.compare(requestRevision, x) >= 0;
     }
@@ -706,9 +706,10 @@ public class MongoMK implements MicroKer
         }
         // filter out revisions newer than branch base
         if (branch != null) {
+            Revision base = branch.getBase(readRevision);
             for (Iterator<Revision> it = lastRevs.values().iterator(); it.hasNext();
) {
                 Revision r = it.next();
-                if (isRevisionNewer(r, branch.getBase())) {
+                if (isRevisionNewer(r, base)) {
                     it.remove();
                 }
             }
@@ -1461,11 +1462,10 @@ public class MongoMK implements MicroKer
         if (b.getBase().equals(base)) {
             return branchRevisionId;
         }
-        b.setBase(base);
         // add a pseudo commit to make sure current head of branch
         // has a higher revision than base of branch
         Revision head = newRevision();
-        b.addCommit(head);
+        b.rebase(head, base);
         return "b" + head.toString();
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMKRebaseTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMKRebaseTest.java?rev=1501767&r1=1501766&r2=1501767&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMKRebaseTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMKRebaseTest.java
Wed Jul 10 13:42:50 2013
@@ -100,7 +100,6 @@ public class MongoMKRebaseTest extends B
     }
 
     @Test
-    @Ignore
     public void rebaseAddProperty() {
         mk.commit("", "+\"/x\":{\"y\":{}}", null, null);
         String branch = mk.branch(null);
@@ -122,7 +121,6 @@ public class MongoMKRebaseTest extends B
     }
 
     @Test
-    @Ignore
     public void rebaseRemoveProperty() {
         mk.commit("", "+\"/x\":{\"y\":{\"p\":42}}", null, null);
         String branch = mk.branch(null);
@@ -144,7 +142,6 @@ public class MongoMKRebaseTest extends B
     }
 
     @Test
-    @Ignore
     public void rebaseChangeProperty() {
         mk.commit("", "+\"/x\":{\"y\":{\"p\":42}}", null, null);
         String branch = mk.branch(null);



Mime
View raw message