jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1365621 - /jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
Date Wed, 25 Jul 2012 15:17:44 GMT
Author: dpfister
Date: Wed Jul 25 15:17:44 2012
New Revision: 1365621

URL: http://svn.apache.org/viewvc?rev=1365621&view=rev
Log:
OAK-187 - ConcurrentModificationException during gc run

Modified:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java?rev=1365621&r1=1365620&r2=1365621&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
Wed Jul 25 15:17:44 2012
@@ -101,7 +101,7 @@ public class DefaultRevisionStore extend
     /**
      * Active branches (Key: branch root id, Value: branch head).
      */
-    private final Map<Id,Id> branches = Collections.synchronizedMap(new TreeMap<Id,
Id>());
+    private final TreeMap<Id,Id> branches = new TreeMap<Id, Id>();
 
     public DefaultRevisionStore(Persistence pm) {
         this(pm, (pm instanceof GCPersistence) ? (GCPersistence) pm : null);
@@ -305,7 +305,9 @@ public class DefaultRevisionStore extend
         
         putTokens.remove(token);
         if (branchRootId != null) {
-            branches.remove(branchRootId);
+            synchronized (branches) {
+                branches.remove(branchRootId);
+            }
         }
         return id;
     }
@@ -318,7 +320,9 @@ public class DefaultRevisionStore extend
 
         Id branchRootId = commit.getBranchRootId();
         if (branchRootId != null) {
-            branches.put(branchRootId, commitId);
+            synchronized (branches) {
+                branches.put(branchRootId, commitId);
+            }
         }
         
         return commitId;
@@ -557,9 +561,16 @@ public class DefaultRevisionStore extend
      * @throws Exception
      *             if an error occurs
      */
+    @SuppressWarnings("unchecked")
     private Id markBranches() throws Exception {
+        Map<Id,Id> tmpBranches;
+        
+        synchronized (branches) {
+            tmpBranches = (Map<Id,Id>) branches.clone();
+        }
+        
         /* Mark all branch commits */
-        for (Entry<Id, Id> entry : branches.entrySet()) {
+        for (Entry<Id, Id> entry : tmpBranches.entrySet()) {
             Id branchRootId = entry.getKey();
             Id branchHeadId = entry.getValue();
             while (!branchHeadId.equals(branchRootId)) {
@@ -569,8 +580,8 @@ public class DefaultRevisionStore extend
             }
         }
         /* Mark all master commits till the first branch root id */
-        if (!branches.isEmpty()) {
-            Id firstBranchRootId = branches.keySet().iterator().next();
+        if (!tmpBranches.isEmpty()) {
+            Id firstBranchRootId = tmpBranches.keySet().iterator().next();
             StoredCommit commit = getHeadCommit();
 
             for (;;) {



Mime
View raw message