You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2013/10/16 10:49:15 UTC

svn commit: r1532689 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk: Branch.java UnmergedBranches.java

Author: mreutegg
Date: Wed Oct 16 08:49:14 2013
New Revision: 1532689

URL: http://svn.apache.org/r1532689
Log:
OAK-1101: Improve concurrency of branch lookups

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/UnmergedBranches.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=1532689&r1=1532688&r2=1532689&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 Oct 16 08:49:14 2013
@@ -16,9 +16,11 @@
  */
 package org.apache.jackrabbit.oak.plugins.mongomk;
 
+import java.util.NavigableMap;
 import java.util.SortedSet;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentSkipListMap;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
@@ -34,7 +36,7 @@ class Branch {
     /**
      * The commits to the branch
      */
-    private final TreeMap<Revision, BranchCommit> commits;
+    private final ConcurrentSkipListMap<Revision, BranchCommit> commits;
 
     /**
      * The initial base revision of this branch.
@@ -53,7 +55,7 @@ class Branch {
            @Nonnull Revision base) {
         checkArgument(!checkNotNull(base).isBranch(), "base is not a trunk revision: %s", base);
         this.base = base;
-        this.commits = new TreeMap<Revision, BranchCommit>(commits.comparator());
+        this.commits = new ConcurrentSkipListMap<Revision, BranchCommit>(commits.comparator());
         for (Revision r : commits) {
             this.commits.put(r.asBranchRevision(), new BranchCommit(base));
         }
@@ -76,7 +78,7 @@ class Branch {
      *                                  this branch.
      */
     @Nonnull
-    synchronized Revision getBase(@Nonnull Revision r) {
+    Revision getBase(@Nonnull Revision r) {
         BranchCommit c = commits.get(checkNotNull(r).asBranchRevision());
         if (c == null) {
             throw new IllegalArgumentException(
@@ -93,7 +95,7 @@ class Branch {
      * @throws IllegalArgumentException if head is a trunk revision or base is a
      *                                  branch revision.
      */
-    synchronized void rebase(@Nonnull Revision head, @Nonnull Revision base) {
+    void rebase(@Nonnull Revision head, @Nonnull Revision base) {
         checkArgument(checkNotNull(head).isBranch(), "Not a branch revision: %s", head);
         checkArgument(!checkNotNull(base).isBranch(), "Not a trunk revision: %s", base);
         Revision last = commits.lastKey();
@@ -107,7 +109,7 @@ class Branch {
      * @param r the revision of the branch commit to add.
      * @throws IllegalArgumentException if r is not a branch revision.
      */
-    synchronized void addCommit(@Nonnull Revision r) {
+    void addCommit(@Nonnull Revision r) {
         checkArgument(checkNotNull(r).isBranch(), "Not a branch revision: %s", r);
         Revision last = commits.lastKey();
         checkArgument(commits.comparator().compare(r, last) > 0);
@@ -117,17 +119,15 @@ class Branch {
     /**
      * @return the commits to this branch.
      */
-    synchronized SortedSet<Revision> getCommits() {
-        SortedSet<Revision> revisions = new TreeSet<Revision>(commits.comparator());
-        revisions.addAll(commits.keySet());
-        return revisions;
+    SortedSet<Revision> getCommits() {
+        return commits.keySet();
     }
 
     /**
      * @return <code>true</code> if this branch contains any commits;
      *         <code>false</code> otherwise.
      */
-    synchronized boolean hasCommits() {
+    boolean hasCommits() {
         return !commits.isEmpty();
     }
 
@@ -138,7 +138,7 @@ class Branch {
      * @return <code>true</code> if this branch contains a commit with the given
      *         revision; <code>false</code> otherwise.
      */
-    synchronized boolean containsCommit(@Nonnull Revision r) {
+    boolean containsCommit(@Nonnull Revision r) {
         return commits.containsKey(checkNotNull(r).asBranchRevision());
     }
 
@@ -149,7 +149,7 @@ class Branch {
      * @param r the revision of the commit to remove.
      * @throws IllegalArgumentException if r is not a branch revision.
      */
-    public synchronized void removeCommit(@Nonnull Revision r) {
+    public void removeCommit(@Nonnull Revision r) {
         checkArgument(checkNotNull(r).isBranch(), "Not a branch revision: %s", r);
         commits.remove(r);
     }
@@ -163,7 +163,7 @@ class Branch {
      *                                  is no commit with the given revision.
      */
     @Nonnull
-    public synchronized UnsavedModifications getModifications(@Nonnull Revision r) {
+    public UnsavedModifications getModifications(@Nonnull Revision r) {
         checkArgument(checkNotNull(r).isBranch(), "Not a branch revision: %s", r);
         BranchCommit c = commits.get(r);
         if (c == null) {
@@ -180,7 +180,7 @@ class Branch {
      * @param trunk the unsaved trunk modifications.
      * @param mergeCommit the revision of the merge commit.
      */
-    public synchronized void applyTo(@Nonnull UnsavedModifications trunk,
+    public void applyTo(@Nonnull UnsavedModifications trunk,
                                      @Nonnull Revision mergeCommit) {
         checkNotNull(trunk);
         for (BranchCommit c : commits.values()) {
@@ -198,7 +198,7 @@ class Branch {
      *         there is none in this branch.
      */
     @CheckForNull
-    public synchronized Revision getUnsavedLastRevision(String path,
+    public Revision getUnsavedLastRevision(String path,
                                                         Revision readRevision) {
         readRevision = readRevision.asBranchRevision();
         for (Revision r : commits.descendingKeySet()) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/UnmergedBranches.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/UnmergedBranches.java?rev=1532689&r1=1532688&r2=1532689&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/UnmergedBranches.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/UnmergedBranches.java Wed Oct 16 08:49:14 2013
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.SortedMap;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.annotation.CheckForNull;
@@ -41,7 +42,7 @@ class UnmergedBranches {
     /**
      * Map of branches with the head of the branch as key.
      */
-    private final List<Branch> branches = new ArrayList<Branch>();
+    private final List<Branch> branches = new CopyOnWriteArrayList<Branch>();
 
     /**
      * Set to <code>true</code> once initialized.
@@ -103,9 +104,7 @@ class UnmergedBranches {
         SortedSet<Revision> commits = new TreeSet<Revision>(comparator);
         commits.add(initial);
         Branch b = new Branch(commits, base);
-        synchronized (branches) {
-            branches.add(b);
-        }
+        branches.add(b);
         return b;
     }
 
@@ -118,11 +117,9 @@ class UnmergedBranches {
      */
     @CheckForNull
     Branch getBranch(@Nonnull Revision r) {
-        synchronized (branches) {
-            for (Branch b : branches) {
-                if (b.containsCommit(r)) {
-                    return b;
-                }
+        for (Branch b : branches) {
+            if (b.containsCommit(r)) {
+                return b;
             }
         }
         return null;
@@ -133,13 +130,6 @@ class UnmergedBranches {
      * @param b the branch to remove.
      */
     void remove(Branch b) {
-        synchronized (branches) {
-            for (int i = 0; i < branches.size(); i++) {
-                if (branches.get(i) == b) {
-                    branches.remove(i);
-                    return;
-                }
-            }
-        }
+        branches.remove(b);
     }
 }