jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1300904 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk: model/CommitBuilder.java store/CopyingGC.java store/DefaultRevisionStore.java store/RevisionStore.java
Date Thu, 15 Mar 2012 10:48:35 GMT
Author: dpfister
Date: Thu Mar 15 10:48:34 2012
New Revision: 1300904

URL: http://svn.apache.org/viewvc?rev=1300904&view=rev
Log: (empty)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java?rev=1300904&r1=1300903&r2=1300904&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
Thu Mar 15 10:48:34 2012
@@ -216,9 +216,7 @@ public class CommitBuilder {
             newCommit.setCommitTS(System.currentTimeMillis());
             newCommit.setMsg(msg);
             newCommit.setRootNodeId(rootNodeId);
-            newRevId = store.putCommit(newCommit);
-
-            store.setHeadCommitId(newRevId);
+            newRevId = store.putHeadCommit(newCommit);
         } finally {
             store.unlockHead();
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java?rev=1300904&r1=1300903&r2=1300904&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
Thu Mar 15 10:48:34 2012
@@ -75,16 +75,21 @@ public class CopyingGC implements Revisi
         // Copy the head commit
         MutableCommit commitTo = copy(rsFrom.getHeadCommit());
         commitTo.setParentId(rsTo.getHeadCommitId());
-        Id revId = rsTo.putCommit(commitTo);
-        rsTo.setHeadCommitId(revId);
-
+        
+        rsTo.lockHead();
+        
+        try {
+            rsTo.putHeadCommit(commitTo);
+        } finally {
+            rsTo.unlockHead();
+        }
         running = true;
     }
     
     /**
      * Stop GC cycle.
      */
-    public void stop() throws Exception {
+    public void stop() {
         running = false;
         
         // TODO: swap rsFrom/rsTo and reset them
@@ -192,10 +197,6 @@ public class CopyingGC implements Revisi
         return running ? rsTo.putNode(node) : rsFrom.putNode(node);
     }
 
-    public Id putCommit(MutableCommit commit) throws Exception {
-        return running ? rsTo.putCommit(commit) : rsFrom.putCommit(commit);
-    }
-
     public Id putCNEMap(ChildNodeEntriesMap map) throws Exception {
         return running ? rsTo.putCNEMap(map) : rsFrom.putCNEMap(map);
     }
@@ -209,12 +210,8 @@ public class CopyingGC implements Revisi
         }
     }
 
-    public void setHeadCommitId(Id commitId) throws Exception {
-        if (running) {
-            rsTo.setHeadCommitId(commitId);
-        } else {
-            rsFrom.setHeadCommitId(commitId);
-        }
+    public Id putHeadCommit(MutableCommit commit) throws Exception {
+        return running ? rsTo.putHeadCommit(commit) : rsFrom.putHeadCommit(commit);
     }
 
     // TODO: potentially dangerous, if lock & unlock interfere with GC start

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java?rev=1300904&r1=1300903&r2=1300904&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
Thu Mar 15 10:48:34 2012
@@ -179,8 +179,15 @@ public class DefaultRevisionStore implem
         return id;
     }
 
-    public Id putCommit(MutableCommit commit) throws Exception {
+    public void lockHead() {
+        headLock.writeLock().lock();
+    }
+
+    public Id putHeadCommit(MutableCommit commit) throws Exception {
         verifyInitialized();
+        if (!headLock.writeLock().isHeldByCurrentThread()) {
+            throw new IllegalStateException("putCommit called without holding write lock.");
+        }
 
         PersistHook callback = null;
         if (commit instanceof PersistHook) {
@@ -193,35 +200,26 @@ public class DefaultRevisionStore implem
             id = new Id(longToBytes(++headCounter));
         }
         pm.writeCommit(id, commit);
+        setHeadCommitId(id);
 
         if (callback != null)  {
             callback.postPersist(this);
         }
         cache.put(id, new StoredCommit(id, commit));
+
         return id;
     }
 
-    public void setHeadCommitId(Id id) throws Exception {
-        verifyInitialized();
-
-        headLock.writeLock().lock();
-        try {
-            pm.writeHead(id);
-            head = id;
-            
-            long headCounter = Long.parseLong(id.toString(), 16);
-            if (headCounter > this.headCounter) {
-                this.headCounter = headCounter;
-            }
-        } finally {
-            headLock.writeLock().unlock();
+    private void setHeadCommitId(Id id) throws Exception {
+        pm.writeHead(id);
+        head = id;
+        
+        long headCounter = Long.parseLong(id.toString(), 16);
+        if (headCounter > this.headCounter) {
+            this.headCounter = headCounter;
         }
     }
 
-    public void lockHead() {
-        headLock.writeLock().lock();
-    }
-
     public void unlockHead() {
         headLock.writeLock().unlock();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java?rev=1300904&r1=1300903&r2=1300904&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
Thu Mar 15 10:48:34 2012
@@ -29,10 +29,30 @@ import java.io.InputStream;
 public interface RevisionStore extends RevisionProvider {
 
     Id /*id*/ putNode(MutableNode node) throws Exception;
-    Id /*id*/ putCommit(MutableCommit commit) throws Exception;
     Id /*id*/ putCNEMap(ChildNodeEntriesMap map) throws Exception;
-    void setHeadCommitId(Id commitId) throws Exception;
+    
+    /**
+     * Lock the head. Must be called prior to putting a new head commit.
+     * 
+     * @see #putHeadCommit(MutableCommit)
+     */
     void lockHead();
+    
+    /**
+     * Put a new head commit. Must be called while holding a
+     * lock on the head.
+     * 
+     * @param commit commit
+     * @return head commit id
+     * @throws Exception if an error occurs
+     * @see #lockHead()
+     */
+    Id /*id*/ putHeadCommit(MutableCommit commit) throws Exception;
+    
+    /**
+     * Unlock the head.
+     */
     void unlockHead();
+    
     String /*id*/ putBlob(InputStream in) throws Exception;
 }



Mime
View raw message