jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1461981 - /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
Date Thu, 28 Mar 2013 08:39:58 GMT
Author: mreutegg
Date: Thu Mar 28 08:39:58 2013
New Revision: 1461981

URL: http://svn.apache.org/r1461981
Log:
OAK-619 Lock-free MongoMK implementation
- use ConcurrentHashMap for branchCommits
- remember branch revision already before commit is written

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=1461981&r1=1461980&r2=1461981&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
Thu Mar 28 08:39:58 2013
@@ -19,13 +19,13 @@ 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.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.annotation.Nonnull;
@@ -140,8 +140,8 @@ public class MongoMK implements MicroKer
     /**
      * Maps branch commit revision to revision it is based on
      */
-    private final Map<Revision, Revision> branchCommits =
-            Collections.synchronizedMap(new HashMap<Revision, Revision>());
+    private final Map<Revision, Revision> branchCommits
+            = new ConcurrentHashMap<Revision, Revision>();
 
     /**
      * Create a new in-memory MongoMK used for testing.
@@ -745,10 +745,18 @@ public class MongoMK implements MicroKer
             }
         }
         if (baseRevId.startsWith("b")) {
-            // prepare commit
-            commit.prepare(baseRev);
             // remember branch commit
             branchCommits.put(rev, baseRev);
+            boolean success = false;
+            try {
+                // prepare commit
+                commit.prepare(baseRev);
+                success = true;
+            } finally {
+                if (!success) {
+                    branchCommits.remove(rev);
+                }
+            }
 
             return "b" + rev.toString();
 



Mime
View raw message