jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1547652 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins: backup/ segment/
Date Wed, 04 Dec 2013 00:22:49 GMT
Author: jukka
Date: Wed Dec  4 00:22:49 2013
New Revision: 1547652

URL: http://svn.apache.org/r1547652
Log:
OAK-593: Segment-based MK

Merge SegmentRootBuilder into SegmentNodeBuilder and simplify the code

Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentRootBuilder.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/backup/FileStoreBackup.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/backup/FileStoreBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/backup/FileStoreBackup.java?rev=1547652&r1=1547651&r2=1547652&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/backup/FileStoreBackup.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/backup/FileStoreBackup.java
Wed Dec  4 00:22:49 2013
@@ -23,8 +23,8 @@ import java.io.IOException;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.jackrabbit.oak.plugins.segment.Journal;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeBuilder;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeState;
-import org.apache.jackrabbit.oak.plugins.segment.SegmentRootBuilder;
 import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
 import org.apache.jackrabbit.oak.spi.state.ApplyDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -64,7 +64,7 @@ public class FileStoreBackup {
             Journal root = backup.getJournal("root");
             SegmentNodeState state = new SegmentNodeState(backup.getWriter()
                     .getDummySegment(), root.getHead());
-            SegmentRootBuilder builder = state.builder();
+            SegmentNodeBuilder builder = state.builder();
             current.compareAgainstBaseState(state,
                     new ApplyDiff(builder.child("root")));
             root.setHead(state.getRecordId(), builder.getNodeState()

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java?rev=1547652&r1=1547651&r2=1547652&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java
Wed Dec  4 00:22:49 2013
@@ -17,20 +17,54 @@
 package org.apache.jackrabbit.oak.plugins.segment;
 
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
-class SegmentNodeBuilder extends MemoryNodeBuilder {
+public class SegmentNodeBuilder extends MemoryNodeBuilder {
 
-    protected SegmentNodeBuilder(SegmentNodeState base) {
+    /**
+     * Number of content updates that need to happen before the updates
+     * are automatically purged to the underlying segments.
+     */
+    private static final int UPDATE_LIMIT =
+            Integer.getInteger("update.limit", 10000);
+
+    private long updateCount = 0;
+
+    private final SegmentStore store;
+
+    SegmentNodeBuilder(SegmentNodeState base) {
         super(base);
+        this.store = base.getStore();
     }
 
-    private SegmentNodeBuilder(SegmentNodeBuilder parent, String name) {
-        super(parent, name);
+    //-------------------------------------------------< MemoryNodeBuilder >--
+
+    @Override
+    protected void updated() {
+        updateCount++;
+        if (updateCount > UPDATE_LIMIT) {
+            getNodeState();
+        }
+    }
+
+    //-------------------------------------------------------< NodeBuilder >--
+
+    @Override
+    public SegmentNodeState getBaseState() {
+        // guaranteed to be a SegmentNodeState
+        return (SegmentNodeState) super.getBaseState();
     }
 
     @Override
-    protected SegmentNodeBuilder createChildBuilder(String name) {
-        return new SegmentNodeBuilder(this, name);
+    public SegmentNodeState getNodeState() {
+        NodeState state = super.getNodeState();
+        if (!store.isInstance(state, SegmentNodeState.class)) {
+            state = store.getWriter().writeNode(state);
+            set(state);
+            updateCount = 0;
+        }
+        // guaranteed to be a SegmentNodeState from the same store as the base
+        return (SegmentNodeState) state;
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java?rev=1547652&r1=1547651&r2=1547652&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
Wed Dec  4 00:22:49 2013
@@ -264,8 +264,8 @@ public class SegmentNodeState extends Re
     }
 
     @Override @Nonnull
-    public SegmentRootBuilder builder() {
-        return new SegmentRootBuilder(this, getStore().getWriter());
+    public SegmentNodeBuilder builder() {
+        return new SegmentNodeBuilder(this);
     }
 
     @Override

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=1547652&r1=1547651&r2=1547652&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
Wed Dec  4 00:22:49 2013
@@ -143,7 +143,7 @@ public class SegmentNodeStore implements
 
     @Override @Nonnull
     public NodeState rebase(@Nonnull NodeBuilder builder) {
-        checkArgument(builder instanceof SegmentRootBuilder);
+        checkArgument(builder instanceof SegmentNodeBuilder);
         NodeState newBase = getRoot();
         NodeState oldBase = builder.getBaseState();
         if (!fastEquals(oldBase, newBase)) {
@@ -164,7 +164,7 @@ public class SegmentNodeStore implements
 
     @Override @Nonnull
     public NodeState reset(@Nonnull NodeBuilder builder) {
-        checkArgument(builder instanceof SegmentRootBuilder);
+        checkArgument(builder instanceof SegmentNodeBuilder);
         NodeState state = getRoot();
         ((SegmentNodeBuilder) builder).reset(state);
         return state;
@@ -189,7 +189,7 @@ public class SegmentNodeStore implements
                     SegmentNodeState ns = head;
                     RecordId ri = head.getRecordId();
 
-                    SegmentRootBuilder builder = ns.builder();
+                    SegmentNodeBuilder builder = ns.builder();
                     NodeBuilder cp = builder.child(name);
                     cp.setProperty("timestamp", System.currentTimeMillis()
                             + lifetime);
@@ -234,7 +234,7 @@ public class SegmentNodeStore implements
         Commit(@Nonnull SegmentNodeState base, @Nonnull NodeState head,
                 @Nonnull CommitHook hook, @Nullable CommitInfo info) {
             this.base = checkNotNull(base);
-            SegmentRootBuilder builder = base.builder();
+            SegmentNodeBuilder builder = base.builder();
             builder.setChildNode(ROOT, checkNotNull(head));
             this.head = builder.getNodeState();
 



Mime
View raw message