jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1525318 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/kernel/ main/java/org/apache/jackrabbit/oak/plugins/memory/ main/java/org/apache/jackrabbit/oak/plugins/segment/ main/java/org/apache/jackrabbit/oak/spi/s...
Date Sun, 22 Sep 2013 02:26:27 GMT
Author: jukka
Date: Sun Sep 22 02:26:26 2013
New Revision: 1525318

URL: http://svn.apache.org/r1525318
Log:
OAK-659: Move purge logic for transient changes below the NodeBuilder interface

Remove the branch() method from NodeStore as branches are now only used internally

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/MergeTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Sun Sep 22 02:26:26 2013
@@ -209,7 +209,7 @@ public class KernelNodeStore extends Abs
     }
 
     @Override
-    public NodeStoreBranch branch() {
+    protected NodeStoreBranch branch() {
         return new KernelNodeStoreBranch(this, mergeLock, getRoot());
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
Sun Sep 22 02:26:26 2013
@@ -23,7 +23,6 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.PostCommitHook;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
 /**
@@ -41,7 +40,7 @@ class KernelRootBuilder extends MemoryNo
     /**
      * The underlying store
      */
-    private final NodeStore store;
+    private final KernelNodeStore store;
 
     /**
      * The base state of this builder, possibly non-existent if this builder

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
Sun Sep 22 02:26:26 2013
@@ -66,13 +66,13 @@ public class MemoryNodeStore extends Abs
     }
 
     @Override
-    public NodeState getRoot() {
-        return root.get();
+    protected NodeStoreBranch branch() {
+        return new MemoryNodeStoreBranch(this, root.get());
     }
 
     @Override
-    public NodeStoreBranch branch() {
-        return new MemoryNodeStoreBranch(this, root.get());
+    public NodeState getRoot() {
+        return root.get();
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
Sun Sep 22 02:26:26 2013
@@ -18,6 +18,8 @@ package org.apache.jackrabbit.oak.plugin
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -50,6 +52,8 @@ public class SegmentNodeStore implements
 
     private SegmentNodeState head;
 
+    private long maximumBackoff = MILLISECONDS.convert(10, SECONDS);
+
     public SegmentNodeStore(SegmentStore store, String journal) {
         this.store = store;
         this.journal = store.getJournal(journal);
@@ -62,6 +66,10 @@ public class SegmentNodeStore implements
         this(store, "root");
     }
 
+    void setMaximumBackoff(long max) {
+        this.maximumBackoff = max;
+    }
+
     synchronized SegmentNodeState getHead() {
         NodeState before = head.getChildNode(ROOT);
         head = new SegmentNodeState(store, journal.getHead());
@@ -89,7 +97,7 @@ public class SegmentNodeStore implements
         SegmentNodeState head = getHead();
         rebase(builder, head.getChildNode(ROOT)); // TODO: can we avoid this?
         SegmentNodeStoreBranch branch = new SegmentNodeStoreBranch(
-                this, new SegmentWriter(store), head);
+                this, new SegmentWriter(store), head, maximumBackoff);
         branch.setRoot(builder.getNodeState());
         NodeState merged = branch.merge(commitHook, committed);
         ((SegmentNodeBuilder) builder).reset(merged);
@@ -120,12 +128,6 @@ public class SegmentNodeStore implements
         return state;
     }
 
-    @Override @Nonnull
-    public SegmentNodeStoreBranch branch() {
-        return new SegmentNodeStoreBranch(
-                this, new SegmentWriter(store), getHead());
-    }
-
     @Override
     public Blob createBlob(InputStream stream) throws IOException {
         SegmentWriter writer = new SegmentWriter(store);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java
Sun Sep 22 02:26:26 2013
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.plugin
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore.ROOT;
 
 import java.util.Random;
@@ -47,19 +46,16 @@ class SegmentNodeStoreBranch extends Abs
 
     private SegmentNodeState head;
 
-    private long maximumBackoff = MILLISECONDS.convert(10, SECONDS);
+    private long maximumBackoff;
 
     SegmentNodeStoreBranch(
             SegmentNodeStore store, SegmentWriter writer,
-            SegmentNodeState base) {
+            SegmentNodeState base, long maximumBackoff) {
         this.store = store;
         this.writer = writer;
         this.base = base;
         this.head = base;
-    }
-
-    void setMaximumBackoff(long max) {
-        this.maximumBackoff = max;
+        this.maximumBackoff = maximumBackoff;
     }
 
     @Override @Nonnull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
Sun Sep 22 02:26:26 2013
@@ -185,11 +185,6 @@ public class SegmentNodeStoreService imp
         return getDelegate().reset(builder);
     }
 
-    @Override @Nonnull
-    public NodeStoreBranch branch() {
-        return getDelegate().branch();
-    }
-
     @Override
     public Blob createBlob(InputStream stream) throws IOException {
         return getDelegate().createBlob(stream);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java
Sun Sep 22 02:26:26 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.spi.state;
 
-
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import javax.annotation.Nonnull;
@@ -43,6 +42,14 @@ public abstract class AbstractNodeStore 
     protected abstract void reset(NodeBuilder builder, NodeState state);
 
     /**
+     * Creates a new branch of the tree to which transient changes can be applied.
+     *
+     * @return branch
+     */
+    @Nonnull
+    protected abstract NodeStoreBranch branch();
+
+    /**
      * This default implementation is equal to first rebasing the builder
      * and then applying it to a new branch and immediately merging it back.
      * <p>

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
Sun Sep 22 02:26:26 2013
@@ -84,14 +84,6 @@ public interface NodeStore {
     NodeState reset(@Nonnull NodeBuilder builder);
 
     /**
-     * Creates a new branch of the tree to which transient changes can be applied.
-     *
-     * @return branch
-     */
-    @Nonnull
-    NodeStoreBranch branch();
-
-    /**
      * Create a {@link Blob} from the given input stream. The input stream
      * is closed after this method returns.
      * @param inputStream  The input stream for the {@code Blob}

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
Sun Sep 22 02:26:26 2013
@@ -109,10 +109,8 @@ public class NodeStoreTest {
     }
 
     @Test
-    public void branch() throws CommitFailedException {
-        NodeStoreBranch branch = store.branch();
-
-        NodeBuilder rootBuilder = branch.getHead().builder();
+    public void simpleMerge() throws CommitFailedException {
+        NodeBuilder rootBuilder = store.getRoot().builder();
         NodeBuilder testBuilder = rootBuilder.child("test");
         NodeBuilder newNodeBuilder = testBuilder.child("newNode");
 
@@ -126,25 +124,12 @@ public class NodeStoreTest {
         assertFalse(testState.getChildNode("x").exists());
         assertEquals(42, (long) testState.getChildNode("newNode").getProperty("n").getValue(LONG));
 
-        // Assert changes are not yet present in the branch
-        testState = branch.getHead().getChildNode("test");
-        assertFalse(testState.getChildNode("newNode").exists());
-        assertTrue(testState.getChildNode("x").exists());
-
-        branch.setRoot(rootBuilder.getNodeState());
-
-        // Assert changes are present in the branch
-        testState = branch.getHead().getChildNode("test");
-        assertTrue(testState.getChildNode("newNode").exists());
-        assertFalse(testState.getChildNode("x").exists());
-        assertEquals(42, (long) testState.getChildNode("newNode").getProperty("n").getValue(LONG));
-
         // Assert changes are not yet present in the trunk
         testState = store.getRoot().getChildNode("test");
         assertFalse(testState.getChildNode("newNode").exists());
         assertTrue(testState.getChildNode("x").exists());
 
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(rootBuilder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
 
         // Assert changes are present in the trunk
         testState = store.getRoot().getChildNode("test");

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/MergeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/MergeTest.java?rev=1525318&r1=1525317&r2=1525318&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/MergeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/MergeTest.java
Sun Sep 22 02:26:26 2013
@@ -33,7 +33,6 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 import org.junit.Test;
 
 public class MergeTest {
@@ -95,11 +94,9 @@ public class MergeTest {
             public void run() {
                 for (int i = 0; running.get(); i++) {
                     try {
-                        SegmentNodeStoreBranch a = store.branch();
-                        NodeBuilder builder = a.getHead().builder();
-                        builder.setProperty("foo", "abc" + i);
-                        a.setRoot(builder.getNodeState());
-                        a.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+                        NodeBuilder a = store.getRoot().builder();
+                        a.setProperty("foo", "abc" + i);
+                        store.merge(a, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
                         semaphore.release();
                     } catch (CommitFailedException e) {
                         fail();
@@ -115,10 +112,10 @@ public class MergeTest {
         assertTrue(store.getRoot().hasProperty("foo"));
         assertFalse(store.getRoot().hasProperty("bar"));
 
-        SegmentNodeStoreBranch b = store.branch();
-        b.setMaximumBackoff(100);
-        b.setRoot(b.getHead().builder().setProperty("bar", "xyz").getNodeState());
-        b.merge(new CommitHook() {
+        NodeBuilder b = store.getRoot().builder();
+        b.setProperty("bar", "xyz");
+        store.setMaximumBackoff(100);
+        store.merge(b, new CommitHook() {
             @Override @Nonnull
             public NodeState processCommit(NodeState before, NodeState after) {
                 try {



Mime
View raw message