jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1376982 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Date Fri, 24 Aug 2012 16:13:39 GMT
Author: mduerig
Date: Fri Aug 24 16:13:38 2012
New Revision: 1376982

URL: http://svn.apache.org/viewvc?rev=1376982&view=rev
Log:
OAK-272: every session login causes a mk.branch operation

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1376982&r1=1376981&r2=1376982&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Fri Aug 24 16:13:38 2012
@@ -41,7 +41,10 @@ class KernelNodeStoreBranch implements N
     /** Base state of this branch */
     private final NodeState base;
 
-    /** Revision of this branch in the Microkernel */
+    /** Revision from which to branch */
+    private final String headRevision;
+
+    /** Revision of this branch in the Microkernel, null if not yet branched */
     private String branchRevision;
 
     /** Current root state of this branch */
@@ -53,8 +56,8 @@ class KernelNodeStoreBranch implements N
     KernelNodeStoreBranch(KernelNodeStore store) {
         this.store = store;
         MicroKernel kernel = store.getKernel();
-        this.branchRevision = kernel.branch(null);
-        this.currentRoot = new KernelNodeState(kernel, "/", branchRevision);
+        this.headRevision = kernel.getHeadRevision();
+        this.currentRoot = new KernelNodeState(kernel, "/", headRevision);
         this.base = currentRoot;
         this.committed = currentRoot;
     }
@@ -120,7 +123,7 @@ class KernelNodeStoreBranch implements N
     }
 
     @Override
-    public KernelNodeState merge(CommitEditor editor) throws CommitFailedException {
+    public NodeState merge(CommitEditor editor) throws CommitFailedException {
         NodeState oldRoot = base;
         CommitEditor commitEditor = editor == null
                 ? store.getEditor()
@@ -129,13 +132,19 @@ class KernelNodeStoreBranch implements N
         setRoot(toCommit);
 
         try {
-            MicroKernel kernel = store.getKernel();
-            String mergedRevision = kernel.merge(branchRevision, null);
-            branchRevision = null;
-            currentRoot = null;
-            committed = null;
-            KernelNodeState committed = new KernelNodeState(kernel, "/", mergedRevision);
-            return committed;
+            if (branchRevision == null) {
+                // Nothing was written to this branch: return initial node state.
+                branchRevision = null;
+                currentRoot = null;
+                return committed;
+            }
+            else {
+                MicroKernel kernel = store.getKernel();
+                String mergedRevision = kernel.merge(branchRevision, null);
+                branchRevision = null;
+                currentRoot = null;
+                return new KernelNodeState(kernel, "/", mergedRevision);
+            }
         }
         catch (MicroKernelException e) {
             throw new CommitFailedException(e);
@@ -159,6 +168,11 @@ class KernelNodeStoreBranch implements N
 
     private void commit(String jsop) {
         MicroKernel kernel = store.getKernel();
+        if (branchRevision == null) {
+            // create the branch if this is the first commit
+            branchRevision = kernel.branch(headRevision);
+        }
+
         branchRevision = kernel.commit("", jsop, branchRevision, null);
         currentRoot = new KernelNodeState(kernel, "/", branchRevision);
         committed = currentRoot;



Mime
View raw message