jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1446262 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/segment/ test/java/org/apache/jackrabbit/oak/plugins/segment/
Date Thu, 14 Feb 2013 16:19:36 GMT
Author: jukka
Date: Thu Feb 14 16:19:35 2013
New Revision: 1446262

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

Fix some corner cases in cross-segment references

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/SegmentWriter.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/RecordTest.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=1446262&r1=1446261&r2=1446262&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 Feb 14 16:19:35 2013
@@ -20,20 +20,14 @@ import static com.google.common.base.Pre
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
-import org.apache.jackrabbit.oak.plugins.segment.MapRecord.Entry;
 import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
-
 class SegmentNodeState extends AbstractNodeState {
 
     public static RecordId getRecordIdIfAvailable(NodeState state) {

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=1446262&r1=1446261&r2=1446262&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 Feb 14 16:19:35 2013
@@ -102,13 +102,14 @@ public class SegmentWriter {
         Set<UUID> segmentIds = new HashSet<UUID>();
         for (RecordId id : ids) {
             UUID segmentId = id.getSegmentId();
-            if (!uuid.equals(segmentId) && !uuids.contains(segmentId)) {
+            if (!uuids.contains(segmentId)) {
                 segmentIds.add(segmentId);
             }
         }
 
         int fullSize = size + 4 * ids.size();
-        if (buffer.position() + fullSize > store.getMaxSegmentSize()) {
+        if (buffer.position() + fullSize > store.getMaxSegmentSize()
+                || uuids.size() + segmentIds.size() > 0x100) {
             flush();
         }
         if (fullSize > buffer.remaining()) {
@@ -131,6 +132,8 @@ public class SegmentWriter {
             index = uuids.size();
             uuids.add(segmentId);
         }
+        checkState(index < (1 << 8));
+        checkState(id.getOffset() < (1 << 24));
         buffer.putInt(index << 24 | id.getOffset());
     }
 
@@ -218,7 +221,7 @@ public class SegmentWriter {
                 ids.add(entry.value);
             }
 
-            RecordId bucketId = prepare(4 + entries.size() * 12, ids);
+            RecordId bucketId = prepare(4 + entries.size() * 4, ids);
             buffer.putInt(entries.size());
             for (MapEntry entry : entries) {
                 buffer.putInt(entry.hashCode);
@@ -249,7 +252,7 @@ public class SegmentWriter {
                 }
             }
 
-            RecordId bucketId = prepare(12 + bucketIds.size() * 4, bucketIds);
+            RecordId bucketId = prepare(12, bucketIds);
             buffer.putInt(entries.size());
             buffer.putLong(bucketMap);
             for (RecordId id : bucketIds) {

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=1446262&r1=1446261&r2=1446262&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 Feb 14 16:19:35 2013
@@ -26,12 +26,16 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
+import java.util.Calendar;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
 
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.junit.Test;
 
 import com.google.common.base.Charsets;
@@ -219,4 +223,40 @@ public class RecordTest {
         assertNull(many.getEntry(reader, "foo"));
     }
 
+    @Test
+    public void testEmptyNode() {
+        NodeState before = MemoryNodeState.EMPTY_NODE;
+        RecordId id = writer.writeNode(before);
+        writer.flush();
+        NodeState after = new SegmentNodeState(reader, id);
+        assertEquals(before, after);
+    }
+
+    @Test
+    public void testSimpleNode() {
+        NodeState before = MemoryNodeState.EMPTY_NODE.builder()
+                .setProperty("foo", "abc")
+                .setProperty("bar", 123)
+                .setProperty("baz", Math.PI)
+                .getNodeState();
+        RecordId id = writer.writeNode(before);
+        writer.flush();
+        NodeState after = new SegmentNodeState(reader, id);
+        assertEquals(before, after);
+    }
+
+    @Test
+    public void testDeepNode() {
+        NodeBuilder root = MemoryNodeState.EMPTY_NODE.builder();
+        NodeBuilder builder = root;
+        for (int i = 0; i < 1000; i++) {
+            builder = builder.child("test");
+        }
+         NodeState before = builder.getNodeState();
+        RecordId id = writer.writeNode(before);
+        writer.flush();
+        NodeState after = new SegmentNodeState(reader, id);
+        assertEquals(before, after);
+    }
+
 }



Mime
View raw message