jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1526512 - 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 14:33:13 GMT
Author: jukka
Date: Thu Sep 26 14:33:12 2013
New Revision: 1526512

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

Make the currently built segment accessible through readSegment() so we don't need to flush
so often.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.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/SegmentRootBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileJournal.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/Segment.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java?rev=1526512&r1=1526511&r2=1526512&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
Thu Sep 26 14:33:12 2013
@@ -132,7 +132,7 @@ public class Segment {
     private int pos(int offset, int length) {
         int pos = offset - (MAX_SEGMENT_SIZE - size());
         checkPositionIndexes(pos, pos + length, size());
-        return pos;
+        return data.position() + pos;
     }
 
     public UUID getSegmentId() {
@@ -144,7 +144,7 @@ public class Segment {
     }
 
     public int size() {
-        return data.limit();
+        return data.remaining();
     }
 
     byte readByte(int offset) {

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -130,10 +130,7 @@ public class SegmentNodeStore implements
 
     @Override
     public Blob createBlob(InputStream stream) throws IOException {
-        SegmentWriter writer = store.getWriter();
-        RecordId recordId = writer.writeStream(stream);
-        writer.flush();
-        return new SegmentBlob(reader, recordId);
+        return new SegmentBlob(reader, store.getWriter().writeStream(stream));
     }
 
     @Override @Nonnull

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=1526512&r1=1526511&r2=1526512&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
Thu Sep 26 14:33:12 2013
@@ -73,7 +73,6 @@ class SegmentNodeStoreBranch extends Abs
         NodeBuilder builder = head.builder();
         builder.setChildNode(ROOT, newRoot);
         head = writer.writeNode(builder.getNodeState());
-        writer.flush();
     }
 
     @Override
@@ -86,7 +85,6 @@ class SegmentNodeStoreBranch extends Abs
                     new ConflictAnnotatingRebaseDiff(builder.child(ROOT)));
             base = newBase;
             head = writer.writeNode(builder.getNodeState());
-            writer.flush();
         }
     }
 
@@ -106,7 +104,6 @@ class SegmentNodeStoreBranch extends Abs
             builder.setChildNode(ROOT, hook.processCommit(
                     base.getChildNode(ROOT), head.getChildNode(ROOT)));
             SegmentNodeState newHead = writer.writeNode(builder.getNodeState());
-            writer.flush();
 
             // use optimistic locking to update the journal
             if (base.hasProperty("token")
@@ -156,7 +153,6 @@ class SegmentNodeStoreBranch extends Abs
 
                 SegmentNodeState after =
                         writer.writeNode(builder.getNodeState());
-                writer.flush();
                 if (store.setHead(before, after)) {
                     SegmentNodeState originalBase = base;
                     SegmentNodeState originalHead = head;
@@ -171,7 +167,6 @@ class SegmentNodeStoreBranch extends Abs
                     // complete the commit
                     SegmentNodeState newHead =
                             writer.writeNode(builder.getNodeState());
-                    writer.flush();
                     if (store.setHead(after, newHead)) {
                         NodeState previousBase = base;
                         base = newHead;

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -44,11 +44,9 @@ class SegmentRootBuilder extends Segment
 
     @Override
     public SegmentNodeState getNodeState() {
-        SegmentNodeState state = writer.writeNode(super.getNodeState());
-        writer.flush();
-        set(state);
+        set(writer.writeNode(super.getNodeState()));
         updateCount = 0;
-        return state;
+        return writer.writeNode(super.getNodeState());
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java?rev=1526512&r1=1526511&r2=1526512&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
Thu Sep 26 14:33:12 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
+import static com.google.common.base.Objects.equal;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkElementIndex;
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -30,6 +31,7 @@ import static org.apache.jackrabbit.oak.
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -110,6 +112,17 @@ public class SegmentWriter {
         this.store = store;
     }
 
+    public synchronized Segment getCurrentSegment(UUID id) {
+        if (equal(id, uuid)) {
+            return new Segment(
+                    store, uuid,
+                    ByteBuffer.wrap(buffer, buffer.length - length, length),
+                    newArrayList(uuids.keySet()));
+        } else {
+            return null;
+        }
+    }
+
     public synchronized void flush() {
         if (length > 0) {
             store.writeSegment(

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileJournal.java?rev=1526512&r1=1526511&r2=1526512&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileJournal.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileJournal.java
Thu Sep 26 14:33:12 2013
@@ -38,7 +38,7 @@ class FileJournal extends MemoryJournal 
 
     @Override
     public synchronized boolean setHead(RecordId base, RecordId head) {
-        if (super.setHead(base, head)) {
+        if (super.setHead(base, head)) { // flushes the segment if needed
             try {
                 store.writeJournals();
                 return true;

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -140,12 +140,16 @@ public class FileStore implements Segmen
     @Override
     public Segment readSegment(final UUID id) {
         try {
-            return cache.getSegment(id, new Callable<Segment>() {
-                @Override
-                public Segment call() throws Exception {
-                    return loadSegment(id);
-                }
-            });
+            Segment segment = writer.getCurrentSegment(id);
+            if (segment == null) {
+                segment = cache.getSegment(id, new Callable<Segment>() {
+                    @Override
+                    public Segment call() throws Exception {
+                        return loadSegment(id);
+                    }
+                });
+            }
+            return segment;
         } catch (IllegalStateException e) {
             throw e;
         } catch (Exception e) {

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -64,6 +64,10 @@ public class MemoryJournal implements Jo
     @Override
     public synchronized boolean setHead(RecordId base, RecordId head) {
         if (checkNotNull(base).equals(this.head)) {
+            SegmentWriter writer = store.getWriter();
+            if (writer.getCurrentSegment(head.getSegmentId()) != null) {
+                writer.flush();
+            }
             this.head = checkNotNull(head);
             return true;
         } else {
@@ -77,6 +81,7 @@ public class MemoryJournal implements Jo
             NodeState before = new SegmentNodeState(store, base);
             NodeState after = new SegmentNodeState(store, head);
 
+            SegmentWriter writer = store.getWriter();
             while (!parent.setHead(base, head)) {
                 RecordId newBase = parent.getHead();
                 NodeBuilder builder =
@@ -84,9 +89,7 @@ public class MemoryJournal implements Jo
                 after.compareAgainstBaseState(before, new MergeDiff(builder));
                 NodeState state = builder.getNodeState();
 
-                SegmentWriter writer = store.getWriter();
                 RecordId newHead = writer.writeNode(state).getRecordId();
-                writer.flush();
 
                 base = newBase;
                 head = newHead;

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -74,7 +74,10 @@ public class MemoryStore implements Segm
 
     @Override
     public Segment readSegment(UUID id) {
-        Segment segment = segments.get(id);
+        Segment segment = writer.getCurrentSegment(id);
+        if (segment == null) {
+            segment = segments.get(id);
+        }
         if (segment != null) {
             return segment;
         } else {

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -187,7 +187,6 @@ class MongoJournal implements Journal {
                 after.compareAgainstBaseState(before, new MergeDiff(builder));
                 RecordId newHead =
                         writer.writeNode(builder.getNodeState()).getRecordId();
-                writer.flush();
 
                 base = newBase;
                 head = newHead;

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -102,12 +102,16 @@ public class MongoStore implements Segme
     @Override
     public Segment readSegment(final UUID segmentId) {
         try {
-            return cache.getSegment(segmentId, new Callable<Segment>() {
-                @Override
-                public Segment call() throws Exception {
-                    return findSegment(segmentId);
-                }
-            });
+            Segment segment = writer.getCurrentSegment(segmentId);
+            if (segment == null) {
+                segment = cache.getSegment(segmentId, new Callable<Segment>() {
+                    @Override
+                    public Segment call() throws Exception {
+                        return findSegment(segmentId);
+                    }
+                });
+            }
+            return segment;
         } catch (Exception e) {
             throw new RuntimeException(e);
         }

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -30,18 +30,15 @@ import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Test case for ensuring that segment size remains within bounds.
+ * Test case for segment node state comparisons.
  */
 public class CompareAgainstBaseStateTest {
 
-    private final SegmentStore store = new MemoryStore();
-
-    private final SegmentWriter writer = store.getWriter();
-
     private final NodeStateDiff diff =
             createControl().createMock("diff", NodeStateDiff.class);
 
-    private NodeBuilder builder = EMPTY_NODE.builder();
+    private NodeBuilder builder =
+            new MemoryStore().getWriter().writeNode(EMPTY_NODE).builder();
 
     @Before
     public void setUp() {
@@ -52,7 +49,7 @@ public class CompareAgainstBaseStateTest
 
     @Test
     public void testSameState() {
-        NodeState node = persist(builder);
+        NodeState node = builder.getNodeState();
 
         replay(diff);
 
@@ -62,8 +59,8 @@ public class CompareAgainstBaseStateTest
 
     @Test
     public void testEqualState() {
-        NodeState before = persist(builder);
-        NodeState after = persist(before.builder());
+        NodeState before = builder.getNodeState();
+        NodeState after = before.builder().getNodeState();
 
         replay(diff);
 
@@ -73,10 +70,10 @@ public class CompareAgainstBaseStateTest
 
     @Test
     public void testPropertyAdded() {
-        NodeState before = persist(builder);
+        NodeState before = builder.getNodeState();
         builder = before.builder();
         builder.setProperty("test", "test");
-        NodeState after = persist(builder);
+        NodeState after = builder.getNodeState();
 
         expect(diff.propertyAdded(after.getProperty("test"))).andReturn(true);
         replay(diff);
@@ -87,10 +84,10 @@ public class CompareAgainstBaseStateTest
 
     @Test
     public void testPropertyChanged() {
-        NodeState before = persist(builder);
+        NodeState before = builder.getNodeState();
         builder = before.builder();
         builder.setProperty("foo", "test");
-        NodeState after = persist(builder);
+        NodeState after = builder.getNodeState();
 
         expect(diff.propertyChanged(
                 before.getProperty("foo"), after.getProperty("foo"))).andReturn(true);
@@ -102,10 +99,10 @@ public class CompareAgainstBaseStateTest
 
     @Test
     public void testPropertyDeleted() {
-        NodeState before = persist(builder);
+        NodeState before = builder.getNodeState();
         builder = before.builder();
         builder.removeProperty("foo");
-        NodeState after = persist(builder);
+        NodeState after = builder.getNodeState();
 
         expect(diff.propertyDeleted(before.getProperty("foo"))).andReturn(true);
         replay(diff);
@@ -116,10 +113,10 @@ public class CompareAgainstBaseStateTest
 
     @Test
     public void testChildNodeAdded() {
-        NodeState before = persist(builder);
+        NodeState before = builder.getNodeState();
         builder = before.builder();
         builder.child("test");
-        NodeState after = persist(builder);
+        NodeState after = builder.getNodeState();
 
         expect(diff.childNodeAdded("test", after.getChildNode("test"))).andReturn(true);
         replay(diff);
@@ -130,9 +127,9 @@ public class CompareAgainstBaseStateTest
 
     @Test
     public void testChildNodeChanged() {
-        NodeState before = persist(builder);
+        NodeState before = builder.getNodeState();
         builder.child("baz").setProperty("test", "test");
-        NodeState after = persist(builder);
+        NodeState after = builder.getNodeState();
 
         expect(diff.childNodeChanged(
                 "baz", before.getChildNode("baz"), after.getChildNode("baz"))).andReturn(true);
@@ -144,9 +141,9 @@ public class CompareAgainstBaseStateTest
 
     @Test
     public void testChildNodeDeleted() {
-        NodeState before = persist(builder);
+        NodeState before = builder.getNodeState();
         builder.getChildNode("baz").remove();
-        NodeState after = persist(builder);
+        NodeState after = builder.getNodeState();
 
         expect(diff.childNodeDeleted("baz", before.getChildNode("baz"))).andReturn(true);
         replay(diff);
@@ -155,10 +152,4 @@ public class CompareAgainstBaseStateTest
         verify(diff);
     }
 
-    private NodeState persist(NodeBuilder builder) {
-        NodeState state = writer.writeNode(builder.getNodeState());
-        writer.flush();
-        return state;
-    }
-
 }

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -59,7 +59,6 @@ public class RecordTest {
     @Test
     public void testBlockRecord() {
         RecordId blockId = writer.writeBlock(bytes, 0, bytes.length);
-        writer.flush();
         BlockRecord block = new BlockRecord(blockId, bytes.length);
 
         // Check reading with all valid positions and lengths
@@ -86,7 +85,6 @@ public class RecordTest {
         ListRecord level1p = writeList(LEVEL_SIZE + 1, blockId);
         ListRecord level2 = writeList(LEVEL_SIZE * LEVEL_SIZE, blockId);
         ListRecord level2p = writeList(LEVEL_SIZE * LEVEL_SIZE + 1, blockId);
-        writer.flush();
 
         assertEquals(1, one.size());
         assertEquals(blockId, one.getEntry(reader, 0));
@@ -130,8 +128,6 @@ public class RecordTest {
         random.nextBytes(source);
 
         RecordId valueId = writer.writeStream(new ByteArrayInputStream(source));
-        writer.flush();
-
         InputStream stream = reader.readStream(valueId);
         try {
             byte[] b = new byte[349]; // prime number
@@ -161,7 +157,6 @@ public class RecordTest {
         }
         RecordId large = writer.writeString(builder.toString());
 
-        writer.flush();
         Segment segment = store.readSegment(large.getSegmentId());
 
         assertEquals("", segment.readString(empty));
@@ -186,7 +181,6 @@ public class RecordTest {
         }
         MapRecord many = writer.writeMap(null, map);
 
-        writer.flush();
         Iterator<MapEntry> iterator;
 
         assertEquals(0, zero.size());
@@ -227,7 +221,6 @@ public class RecordTest {
         changes.put("key0", null);
         changes.put("key1000", blockId);
         MapRecord modified = writer.writeMap(many, changes);
-        writer.flush();
         assertEquals(1000, modified.size());
         iterator = modified.getEntries().iterator();
         for (int i = 1; i <= 1000; i++) {
@@ -251,7 +244,6 @@ public class RecordTest {
         }
 
         MapRecord bad = writer.writeMap(null, map);
-        writer.flush();
 
         assertEquals(map.size(), bad.size());
         Iterator<MapEntry> iterator = bad.getEntries().iterator();
@@ -266,7 +258,6 @@ public class RecordTest {
     public void testEmptyNode() {
         NodeState before = EMPTY_NODE;
         NodeState after = writer.writeNode(before);
-        writer.flush();
         assertEquals(before, after);
     }
 
@@ -278,7 +269,6 @@ public class RecordTest {
                 .setProperty("baz", Math.PI)
                 .getNodeState();
         NodeState after = writer.writeNode(before);
-        writer.flush();
         assertEquals(before, after);
     }
 
@@ -291,7 +281,6 @@ public class RecordTest {
         }
         NodeState before = builder.getNodeState();
         NodeState after = writer.writeNode(before);
-        writer.flush();
         assertEquals(before, after);
     }
 
@@ -302,7 +291,6 @@ public class RecordTest {
             builder.child("test" + i);
         }
         NodeState before = writer.writeNode(builder.getNodeState());
-        writer.flush();
         assertEquals(builder.getNodeState(), before);
 
         builder = before.builder();
@@ -310,7 +298,6 @@ public class RecordTest {
             builder.getChildNode("test" + i).remove();
         }
         NodeState after = writer.writeNode(builder.getNodeState());
-        writer.flush();
         assertEquals(builder.getNodeState(), after);
     }
 

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=1526512&r1=1526511&r2=1526512&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 14:33:12 2013
@@ -153,14 +153,14 @@ public class SegmentSizeTest {
         }
 
         SegmentNodeState state = writer.writeNode(builder.getNodeState());
-        writer.flush();
         Segment segment = store.readSegment(state.getRecordId().getSegmentId());
         assertEquals(26784, segment.size());
 
+        writer.flush(); // force flushing of the previous segment
+
         builder = state.builder();
         builder.child("child1000");
         state = writer.writeNode(builder.getNodeState());
-        writer.flush();
         segment = store.readSegment(state.getRecordId().getSegmentId());
         assertEquals(252, segment.size());
     }
@@ -169,7 +169,6 @@ public class SegmentSizeTest {
         SegmentStore store = new MemoryStore();
         SegmentWriter writer = store.getWriter();
         RecordId id = writer.writeNode(builder.getNodeState()).getRecordId();
-        writer.flush();
         Segment segment = store.readSegment(id.getSegmentId());
         return segment.size();
     }
@@ -179,14 +178,12 @@ public class SegmentSizeTest {
         SegmentWriter writer = store.getWriter();
         NodeState state = builder.getNodeState();
         RecordId id = writer.writeNode(state).getRecordId();
-        writer.flush();
         int base = store.readSegment(id.getSegmentId()).size();
 
         store = new MemoryStore(); // avoid cross-segment caching
         writer = store.getWriter();
         writer.writeNode(state);
         id = writer.writeNode(state).getRecordId();
-        writer.flush();
         Segment segment = store.readSegment(id.getSegmentId());
         return segment.size() - base;
     }



Mime
View raw message