jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1430796 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: kernel/KernelNodeStoreBranch.java spi/state/NodeStoreBranch.java
Date Wed, 09 Jan 2013 11:36:41 GMT
Author: mduerig
Date: Wed Jan  9 11:36:40 2013
New Revision: 1430796

URL: http://svn.apache.org/viewvc?rev=1430796&view=rev
Log:
OAK-544: Refactor / cleanup NodeStoreBranch and KernelNodeStoreBranch

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.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=1430796&r1=1430795&r2=1430796&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
Wed Jan  9 11:36:40 2013
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
 import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
@@ -38,27 +39,23 @@ class KernelNodeStoreBranch implements N
     /** The underlying store to which this branch belongs */
     private final KernelNodeStore store;
 
-    /** Base state of this branch */
+    /** Root state of the base revision of this branch */
     private final NodeState base;
 
-    /** Revision from which to branch */
-    private final String headRevision;
+    /** Revision of the base state of this branch*/
+    private final String baseRevision;
 
-    /** Revision of this branch in the Microkernel, null if not yet branched */
-    private String branchRevision;
+    /** Root state of the head revision of this branch*/
+    private NodeState head;
 
-    /** Current root state of this branch */
-    private NodeState currentRoot;
-
-    /** Last state which was committed to this branch */
-    private NodeState committed;
+    /** Head revision of this branch, null if not yet branched*/
+    private String headRevision;
 
     KernelNodeStoreBranch(KernelNodeStore store, KernelNodeState root) {
         this.store = store;
-        this.headRevision = root.getRevision();
-        this.currentRoot = root;
-        this.base = currentRoot;
-        this.committed = currentRoot;
+        this.base = root;
+        this.baseRevision = root.getRevision();
+        this.head = root;
     }
 
     @Override
@@ -68,21 +65,23 @@ class KernelNodeStoreBranch implements N
 
     @Override
     public NodeState getRoot() {
-        return currentRoot;
+        checkNotMerged();
+        return head;
     }
 
     @Override
     public void setRoot(NodeState newRoot) {
-        if (!currentRoot.equals(newRoot)) {
-            currentRoot = newRoot;
+        checkNotMerged();
+        if (!head.equals(newRoot)) {
             JsopDiff diff = new JsopDiff(store.getKernel());
-            currentRoot.compareAgainstBaseState(committed, diff);
+            newRoot.compareAgainstBaseState(head, diff);
             commit(diff.toString());
         }
     }
 
     @Override
     public boolean move(String source, String target) {
+        checkNotMerged();
         if (getNode(source) == null) {
             // source does not exist
             return false;
@@ -103,6 +102,7 @@ class KernelNodeStoreBranch implements N
 
     @Override
     public boolean copy(String source, String target) {
+        checkNotMerged();
         if (getNode(source) == null) {
             // source does not exist
             return false;
@@ -123,23 +123,23 @@ class KernelNodeStoreBranch implements N
 
     @Override
     public NodeState merge() throws CommitFailedException {
+        checkNotMerged();
         CommitHook commitHook = store.getHook();
-        NodeState toCommit = commitHook.processCommit(base, currentRoot);
-        NodeState oldRoot = currentRoot;
+        NodeState toCommit = commitHook.processCommit(base, head);
+        NodeState oldRoot = head;
         setRoot(toCommit);
 
         try {
-            if (branchRevision == null) {
-                // Nothing was written to this branch: return initial node state.
-                branchRevision = null;
-                currentRoot = null;
-                return committed;
+            if (headRevision == null) {
+                // Nothing was written to this branch: return base state
+                head = null;  // Mark as merged
+                return base;
             }
             else {
                 MicroKernel kernel = store.getKernel();
-                String mergedRevision = kernel.merge(branchRevision, null);
-                branchRevision = null;
-                currentRoot = null;
+                String mergedRevision = kernel.merge(headRevision, null);
+                headRevision = null;
+                head = null;  // Mark as merged
                 return store.getRootState(mergedRevision);
             }
         }
@@ -151,6 +151,10 @@ class KernelNodeStoreBranch implements N
 
     //------------------------------------------------------------< private >---
 
+    private void checkNotMerged() {
+        checkState(head != null, "Branch has already been merged");
+    }
+
     private NodeState getNode(String path) {
         checkArgument(path.startsWith("/"));
         NodeState node = getRoot();
@@ -166,13 +170,12 @@ class KernelNodeStoreBranch implements N
 
     private void commit(String jsop) {
         MicroKernel kernel = store.getKernel();
-        if (branchRevision == null) {
+        if (headRevision == null) {
             // create the branch if this is the first commit
-            branchRevision = kernel.branch(headRevision);
+            headRevision = kernel.branch(baseRevision);
         }
 
-        branchRevision = kernel.commit("", jsop, branchRevision, null);
-        currentRoot = store.getRootState(branchRevision);
-        committed = currentRoot;
+        headRevision = kernel.commit("", jsop, headRevision, null);
+        head = store.getRootState(headRevision);
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.java?rev=1430796&r1=1430795&r2=1430796&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.java
Wed Jan  9 11:36:40 2013
@@ -21,14 +21,16 @@ import javax.annotation.Nonnull;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 
 /**
- * TODO document
+ * An instance of this class represents a private branch of the tree in a
+ * {@link NodeStore} to which transient changes can be applied and later merged
+ * back or discarded.
  */
 public interface NodeStoreBranch {
 
     /**
      * Returns the base state of this branch.
      *
-     * @return base node state
+     * @return root node state
      */
     @Nonnull
     NodeState getBase();
@@ -37,32 +39,36 @@ public interface NodeStoreBranch {
      * Returns the latest state of the branch.
      *
      * @return root node state
+     * @throws IllegalStateException if the branch is already merged
      */
     @Nonnull
     NodeState getRoot();
 
     /**
-     * Updates the state of the content tree.
+     * Updates the state of the content tree of this private branch.
      *
      * @param newRoot new root node state
+     * @throws IllegalStateException if the branch is already merged
      */
     void setRoot(NodeState newRoot);
 
     /**
-     * Moves a node.
+     * Moves a node in this private branch.
      *
      * @param source source path
      * @param target target path
      * @return  {@code true} iff the move succeeded
+     * @throws IllegalStateException if the branch is already merged
      */
     boolean move(String source, String target);
 
     /**
-     * Copies a node.
+     * Copies a node in this private branch.
      *
      * @param source source path
      * @param target target path
      * @return  {@code true} iff the copy succeeded
+     * @throws IllegalStateException if the branch is already merged
      */
     boolean copy(String source, String target);
 
@@ -71,6 +77,7 @@ public interface NodeStoreBranch {
      *
      * @return the node state resulting from the merge.
      * @throws CommitFailedException if the merge failed
+     * @throws IllegalStateException if the branch is already merged
      */
     @Nonnull
     NodeState merge() throws CommitFailedException;



Mime
View raw message