jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1526354 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/segment/ main/java/org/apache/jackrabbit/oak/plugins/segment/file/ main/java/org/apache/jackrabbit/oak/plugins/segment/memory/ main/java/org/apach...
Date Thu, 26 Sep 2013 02:18:18 GMT
Author: jukka
Date: Thu Sep 26 02:18:17 2013
New Revision: 1526354

URL: http://svn.apache.org/r1526354
Log:
OAK-1032: SegmentMK: One SegmentWriter per SegmentNodeStore

Adjust code to use just one SegmentWriter

Modified:
    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
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentRootBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryJournal.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoJournal.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentSizeTest.java

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=1526354&r1=1526353&r2=1526354&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
Thu Sep 26 02:18:17 2013
@@ -130,7 +130,7 @@ public class SegmentNodeState extends Ab
 
     @Override @Nonnull
     public NodeBuilder builder() {
-        return new SegmentRootBuilder(this, store);
+        return new SegmentRootBuilder(this, store.getWriter());
     }
 
     @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=1526354&r1=1526353&r2=1526354&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
Thu Sep 26 02:18:17 2013
@@ -97,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, maximumBackoff);
+                this, store.getWriter(), head, maximumBackoff);
         branch.setRoot(builder.getNodeState());
         NodeState merged = branch.merge(commitHook, committed);
         ((SegmentNodeBuilder) builder).reset(merged);
@@ -130,7 +130,7 @@ public class SegmentNodeStore implements
 
     @Override
     public Blob createBlob(InputStream stream) throws IOException {
-        SegmentWriter writer = new SegmentWriter(store);
+        SegmentWriter writer = store.getWriter();
         RecordId recordId = writer.writeStream(stream);
         writer.flush();
         return new SegmentBlob(reader, recordId);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentRootBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentRootBuilder.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentRootBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentRootBuilder.java
Thu Sep 26 02:18:17 2013
@@ -29,9 +29,9 @@ class SegmentRootBuilder extends Segment
 
     private long updateCount = 0;
 
-    SegmentRootBuilder(SegmentNodeState base, SegmentStore store) {
+    SegmentRootBuilder(SegmentNodeState base, SegmentWriter writer) {
         super(base);
-        this.writer = new SegmentWriter(store);
+        this.writer = writer;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
Thu Sep 26 02:18:17 2013
@@ -21,6 +21,8 @@ import java.util.UUID;
 
 public interface SegmentStore {
 
+    SegmentWriter getWriter();
+
     Journal getJournal(String name);
 
     Segment readSegment(UUID segmentId);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
Thu Sep 26 02:18:17 2013
@@ -27,7 +27,6 @@ import static org.apache.jackrabbit.oak.
 import java.io.File;
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -40,7 +39,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.segment.SegmentCache;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeState;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentStore;
-import org.apache.jackrabbit.oak.plugins.segment.Template;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentWriter;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 
 public class FileStore implements SegmentStore {
@@ -65,6 +64,8 @@ public class FileStore implements Segmen
 
     private final SegmentCache cache = SegmentCache.create();
 
+    private final SegmentWriter writer = new SegmentWriter(this);
+
     public FileStore(File directory, int maxFileSize, boolean memoryMapping)
             throws IOException {
         checkNotNull(directory).mkdirs();
@@ -107,6 +108,12 @@ public class FileStore implements Segmen
         }
     }
 
+    @Override
+    public SegmentWriter getWriter() {
+        return writer;
+    }
+
+    @Override
     public synchronized void close() {
         try {
             for (TarFile file : files) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryJournal.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryJournal.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryJournal.java
Thu Sep 26 02:18:17 2013
@@ -41,7 +41,7 @@ public class MemoryJournal implements Jo
         this.store = checkNotNull(store);
         this.parent = null;
 
-        SegmentWriter writer = new SegmentWriter(store);
+        SegmentWriter writer = store.getWriter();
         RecordId id = writer.writeNode(head).getRecordId();
         writer.flush();
 
@@ -77,13 +77,14 @@ public class MemoryJournal implements Jo
             NodeState before = new SegmentNodeState(store, base);
             NodeState after = new SegmentNodeState(store, head);
 
-            SegmentWriter writer = new SegmentWriter(store);
             while (!parent.setHead(base, head)) {
                 RecordId newBase = parent.getHead();
                 NodeBuilder builder =
                         new SegmentNodeState(store, newBase).builder();
                 after.compareAgainstBaseState(before, new MergeDiff(builder));
                 NodeState state = builder.getNodeState();
+
+                SegmentWriter writer = store.getWriter();
                 RecordId newHead = writer.writeNode(state).getRecordId();
                 writer.flush();
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java
Thu Sep 26 02:18:17 2013
@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentMa
 import org.apache.jackrabbit.oak.plugins.segment.Journal;
 import org.apache.jackrabbit.oak.plugins.segment.Segment;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentStore;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentWriter;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -40,6 +41,8 @@ public class MemoryStore implements Segm
     private final ConcurrentMap<UUID, Segment> segments =
             Maps.newConcurrentMap();
 
+    private final SegmentWriter writer = new SegmentWriter(this);
+
     public MemoryStore(NodeState root) {
         NodeBuilder builder = EMPTY_NODE.builder();
         builder.setChildNode("root", root);
@@ -51,6 +54,11 @@ public class MemoryStore implements Segm
     }
 
     @Override
+    public SegmentWriter getWriter() {
+        return writer;
+    }
+
+    @Override
     public void close() {
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoJournal.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoJournal.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoJournal.java
Thu Sep 26 02:18:17 2013
@@ -70,7 +70,7 @@ class MongoJournal implements Journal {
         DBObject id = new BasicDBObject("_id", "root");
         state = journals.findOne(id, null, primaryPreferred());
         if (state == null) {
-            SegmentWriter writer = new SegmentWriter(store);
+            SegmentWriter writer = store.getWriter();
             RecordId headId = writer.writeNode(head).getRecordId();
             writer.flush();
             state = new BasicDBObject(of(
@@ -179,7 +179,7 @@ class MongoJournal implements Journal {
             NodeState after = new SegmentNodeState(store, head);
 
             Journal parent = store.getJournal(state.get("parent").toString());
-            SegmentWriter writer = new SegmentWriter(store);
+            SegmentWriter writer = store.getWriter();
             while (!parent.setHead(base, head)) {
                 RecordId newBase = parent.getHead();
                 NodeBuilder builder =

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java
Thu Sep 26 02:18:17 2013
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.segment.Segment;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentCache;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentStore;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentWriter;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 
 import com.google.common.collect.Lists;
@@ -56,6 +57,8 @@ public class MongoStore implements Segme
 
     private final SegmentCache cache;
 
+    private final SegmentWriter writer = new SegmentWriter(this);
+
     public MongoStore(DB db, SegmentCache cache) {
         this.db = checkNotNull(db);
         this.segments = db.getCollection("segments");
@@ -77,6 +80,11 @@ public class MongoStore implements Segme
     }
 
     @Override
+    public SegmentWriter getWriter() {
+        return writer;
+    }
+
+    @Override
     public void close() {
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/CompareAgainstBaseStateTest.java
Thu Sep 26 02:18:17 2013
@@ -36,7 +36,7 @@ public class CompareAgainstBaseStateTest
 
     private final SegmentStore store = new MemoryStore();
 
-    private final SegmentWriter writer = new SegmentWriter(store);
+    private final SegmentWriter writer = store.getWriter();
 
     private final NodeStateDiff diff =
             createControl().createMock("diff", NodeStateDiff.class);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.java
Thu Sep 26 02:18:17 2013
@@ -52,7 +52,7 @@ public class RecordTest {
 
     private SegmentReader reader = new SegmentReader(store);
 
-    private SegmentWriter writer = new SegmentWriter(store);
+    private SegmentWriter writer = store.getWriter();
 
     private final Random random = new Random(0xcafefaceL);
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentSizeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentSizeTest.java?rev=1526354&r1=1526353&r2=1526354&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentSizeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentSizeTest.java
Thu Sep 26 02:18:17 2013
@@ -39,7 +39,7 @@ public class SegmentSizeTest {
     @Test
     public void testNodeSize() {
         NodeBuilder builder = EMPTY_NODE.builder();
-        assertEquals(8, getSize(builder));
+        assertEquals(4, getSize(builder));
         assertEquals(4, getAmortizedSize(builder));
 
         builder = EMPTY_NODE.builder();
@@ -55,13 +55,13 @@ public class SegmentSizeTest {
 
         builder = EMPTY_NODE.builder();
         builder.child("foo");
-        assertEquals(28, getSize(builder));
+        assertEquals(24, getSize(builder));
         assertEquals(12, getAmortizedSize(builder));
 
         builder = EMPTY_NODE.builder();
         builder.child("foo");
         builder.child("bar");
-        assertEquals(56, getSize(builder));
+        assertEquals(52, getSize(builder));
         assertEquals(40, getAmortizedSize(builder));
     }
 
@@ -145,7 +145,7 @@ public class SegmentSizeTest {
     @Test
     public void testFlatNodeUpdate() {
         SegmentStore store = new MemoryStore();
-        SegmentWriter writer = new SegmentWriter(store);
+        SegmentWriter writer = store.getWriter();
 
         NodeBuilder builder = EMPTY_NODE.builder();
         for (int i = 0; i < 1000; i++) {
@@ -155,19 +155,19 @@ public class SegmentSizeTest {
         SegmentNodeState state = writer.writeNode(builder.getNodeState());
         writer.flush();
         Segment segment = store.readSegment(state.getRecordId().getSegmentId());
-        assertEquals(26788, segment.size());
+        assertEquals(26784, segment.size());
 
         builder = state.builder();
         builder.child("child1000");
         state = writer.writeNode(builder.getNodeState());
         writer.flush();
         segment = store.readSegment(state.getRecordId().getSegmentId());
-        assertEquals(256, segment.size());
+        assertEquals(252, segment.size());
     }
 
     private int getSize(NodeBuilder builder) {
         SegmentStore store = new MemoryStore();
-        SegmentWriter writer = new SegmentWriter(store);
+        SegmentWriter writer = store.getWriter();
         RecordId id = writer.writeNode(builder.getNodeState()).getRecordId();
         writer.flush();
         Segment segment = store.readSegment(id.getSegmentId());
@@ -176,12 +176,14 @@ public class SegmentSizeTest {
 
     private int getAmortizedSize(NodeBuilder builder) {
         SegmentStore store = new MemoryStore();
-        SegmentWriter writer = new SegmentWriter(store);
+        SegmentWriter writer = store.getWriter();
         NodeState state = builder.getNodeState();
         RecordId id = writer.writeNode(state).getRecordId();
         writer.flush();
         int base = store.readSegment(id.getSegmentId()).size();
-        writer = new SegmentWriter(store); // avoid cross-segment caching
+
+        store = new MemoryStore(); // avoid cross-segment caching
+        writer = store.getWriter();
         writer.writeNode(state);
         id = writer.writeNode(state).getRecordId();
         writer.flush();



Mime
View raw message