jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1452877 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/segment/ test/java/org/apache/jackrabbit/oak/plugins/segment/
Date Tue, 05 Mar 2013 16:13:53 GMT
Author: jukka
Date: Tue Mar  5 16:13:53 2013
New Revision: 1452877

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

Make SegmentNodeState and Template use Segments instead of SegmentReader for increased locality
of access

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.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
    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/SegmentPropertyState.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/Template.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/MapEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java?rev=1452877&r1=1452876&r2=1452877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapEntry.java
Tue Mar  5 16:13:53 2013
@@ -59,7 +59,7 @@ class MapEntry extends AbstractChildNode
     @Override @Nonnull
     public NodeState getNodeState() {
         checkState(value != null);
-        return new SegmentNodeState(new SegmentReader(store), value);
+        return new SegmentNodeState(store, value);
     }
 
     //---------------------------------------------------------< Map.Entry >--

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java?rev=1452877&r1=1452876&r2=1452877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java
Tue Mar  5 16:13:53 2013
@@ -46,8 +46,7 @@ public class MemoryStore implements Segm
             this.store = checkNotNull(store);
             this.parent = null;
 
-            SegmentWriter writer =
-                    new SegmentWriter(store, new SegmentReader(store));
+            SegmentWriter writer = new SegmentWriter(store);
             RecordId id = writer.writeNode(root).getRecordId();
             writer.flush();
 
@@ -80,15 +79,14 @@ public class MemoryStore implements Segm
         @Override
         public synchronized void merge() {
             if (parent != null) {
-                SegmentReader reader = new SegmentReader(store);
-                NodeState before = new SegmentNodeState(reader, base);
-                NodeState after = new SegmentNodeState(reader, head);
+                NodeState before = new SegmentNodeState(store, base);
+                NodeState after = new SegmentNodeState(store, head);
 
-                SegmentWriter writer = new SegmentWriter(store, reader);
+                SegmentWriter writer = new SegmentWriter(store);
                 while (!parent.setHead(base, head)) {
                     RecordId newBase = parent.getHead();
                     NodeBuilder builder =
-                            new SegmentNodeState(reader, newBase).builder();
+                            new SegmentNodeState(store, newBase).builder();
                     after.compareAgainstBaseState(
                             before, new RebaseDiff(builder));
                     NodeState state = builder.getNodeState();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java?rev=1452877&r1=1452876&r2=1452877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
Tue Mar  5 16:13:53 2013
@@ -45,7 +45,7 @@ public class MongoStore implements Segme
         this.cache = cache;
 
         if (journals.findOne(new BasicDBObject("_id", "root")) == null) {
-            SegmentWriter writer = new SegmentWriter(this, new SegmentReader(this));
+            SegmentWriter writer = new SegmentWriter(this);
             RecordId id = writer.writeNode(MemoryNodeState.EMPTY_NODE).getRecordId();
             writer.flush();
             journals.insert(new BasicDBObject(ImmutableMap.of(

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=1452877&r1=1452876&r2=1452877&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
Tue Mar  5 16:13:53 2013
@@ -31,14 +31,14 @@ import org.apache.jackrabbit.oak.spi.sta
 
 class SegmentNodeState extends AbstractNodeState {
 
-    private final SegmentReader reader;
+    private final SegmentStore store;
 
     private final RecordId recordId;
 
     private Template template = null;
 
-    SegmentNodeState(SegmentReader reader, RecordId id) {
-        this.reader = checkNotNull(reader);
+    SegmentNodeState(SegmentStore store, RecordId id) {
+        this.store = checkNotNull(store);
         this.recordId = checkNotNull(id);
     }
 
@@ -48,7 +48,7 @@ class SegmentNodeState extends AbstractN
 
     private synchronized Template getTemplate() {
         if (template == null) {
-            Segment segment = reader.getStore().readSegment(recordId.getSegmentId());
+            Segment segment = store.readSegment(recordId.getSegmentId());
             RecordId templateId = segment.readRecordId(recordId.getOffset());
             template = segment.readTemplate(templateId);
         }
@@ -56,7 +56,7 @@ class SegmentNodeState extends AbstractN
     }
 
     MapRecord getChildNodeMap() {
-        return getTemplate().getChildNodeMap(reader, recordId);
+        return getTemplate().getChildNodeMap(store, recordId);
     }
 
     @Override
@@ -67,37 +67,37 @@ class SegmentNodeState extends AbstractN
     @Override @CheckForNull
     public PropertyState getProperty(String name) {
         checkNotNull(name);
-        return getTemplate().getProperty(name, reader, recordId);
+        return getTemplate().getProperty(name, store, recordId);
     }
 
     @Override @Nonnull
     public Iterable<PropertyState> getProperties() {
-        return getTemplate().getProperties(reader, recordId);
+        return getTemplate().getProperties(store, recordId);
     }
 
     @Override
     public long getChildNodeCount() {
-        return getTemplate().getChildNodeCount(reader, recordId);
+        return getTemplate().getChildNodeCount(store, recordId);
     }
 
     @Override
     public boolean hasChildNode(String name) {
-        return getTemplate().hasChildNode(checkNotNull(name), reader, recordId);
+        return getTemplate().hasChildNode(checkNotNull(name), store, recordId);
     }
 
     @Override @CheckForNull
     public NodeState getChildNode(String name) {
-        return getTemplate().getChildNode(checkNotNull(name), reader, recordId);
+        return getTemplate().getChildNode(checkNotNull(name), store, recordId);
     }
 
     @Override
     public Iterable<String> getChildNodeNames() {
-        return getTemplate().getChildNodeNames(reader, recordId);
+        return getTemplate().getChildNodeNames(store, recordId);
     }
 
     @Override @Nonnull
     public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
-        return getTemplate().getChildNodeEntries(reader, recordId);
+        return getTemplate().getChildNodeEntries(store, recordId);
     }
 
     @Override @Nonnull
@@ -111,7 +111,7 @@ class SegmentNodeState extends AbstractN
             SegmentNodeState that = (SegmentNodeState) base;
             if (!recordId.equals(that.recordId)) {
                 getTemplate().compareAgainstBaseState(
-                        reader, recordId, that.getTemplate(), that.recordId,
+                        store, recordId, that.getTemplate(), that.recordId,
                         diff);
             }
         } else {

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=1452877&r1=1452876&r2=1452877&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
Tue Mar  5 16:13:53 2013
@@ -46,17 +46,17 @@ public class SegmentNodeStore implements
 
     @Override @Nonnull
     public NodeState getRoot() {
-        return new SegmentNodeState(reader, journal.getHead());
+        return new SegmentNodeState(store, journal.getHead());
     }
 
     @Override @Nonnull
     public NodeStoreBranch branch() {
-        return new SegmentNodeStoreBranch(store, journal, reader);
+        return new SegmentNodeStoreBranch(store, journal);
     }
 
     @Override
     public Blob createBlob(InputStream stream) throws IOException {
-        SegmentWriter writer = new SegmentWriter(store, reader);
+        SegmentWriter writer = new SegmentWriter(store);
         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/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=1452877&r1=1452876&r2=1452877&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
Tue Mar  5 16:13:53 2013
@@ -33,9 +33,9 @@ class SegmentNodeStoreBranch implements 
 
     private static final Random RANDOM = new Random();
 
-    private final Journal journal;
+    private final SegmentStore store;
 
-    private final SegmentReader reader;
+    private final Journal journal;
 
     private final SegmentWriter writer;
 
@@ -43,23 +43,22 @@ class SegmentNodeStoreBranch implements 
 
     private RecordId rootId;
 
-    SegmentNodeStoreBranch(
-            SegmentStore store, Journal journal, SegmentReader reader) {
+    SegmentNodeStoreBranch(SegmentStore store, Journal journal) {
+        this.store = store;
         this.journal = journal;
-        this.reader = reader;
-        this.writer = new SegmentWriter(store, reader);
+        this.writer = new SegmentWriter(store);
         this.baseId = journal.getHead();
         this.rootId = baseId;
     }
 
     @Override @Nonnull
     public NodeState getBase() {
-        return new SegmentNodeState(reader, baseId);
+        return new SegmentNodeState(store, baseId);
     }
 
     @Override @Nonnull
     public synchronized NodeState getHead() {
-        return new SegmentNodeState(reader, rootId);
+        return new SegmentNodeState(store, rootId);
     }
 
     @Override
@@ -73,7 +72,7 @@ class SegmentNodeStoreBranch implements 
         RecordId newBaseId = journal.getHead();
         if (!baseId.equals(newBaseId)) {
             NodeBuilder builder =
-                    new MemoryNodeBuilder(new SegmentNodeState(reader, newBaseId));
+                    new MemoryNodeBuilder(new SegmentNodeState(store, newBaseId));
             getHead().compareAgainstBaseState(getBase(), new RebaseDiff(builder));
             this.baseId = newBaseId;
             this.rootId = writer.writeNode(builder.getNodeState()).getRecordId();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java?rev=1452877&r1=1452876&r2=1452877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
Tue Mar  5 16:13:53 2013
@@ -34,15 +34,14 @@ class SegmentPropertyState extends Abstr
 
     private final PropertyTemplate template;
 
-    private final SegmentReader reader;
+    private final SegmentStore store;
 
     private final RecordId recordId;
 
     public SegmentPropertyState(
-            PropertyTemplate template,
-            SegmentReader reader, RecordId recordId) {
+            PropertyTemplate template, SegmentStore store, RecordId recordId) {
         this.template = checkNotNull(template);
-        this.reader = checkNotNull(reader);
+        this.store = checkNotNull(store);
         this.recordId = checkNotNull(recordId);
     }
 
@@ -64,7 +63,8 @@ class SegmentPropertyState extends Abstr
     @Override
     public int count() {
         if (isArray()) {
-            return reader.readInt(recordId, 0);
+            Segment segment = store.readSegment(recordId.getSegmentId());
+            return segment.readInt(recordId.getOffset());
         } else {
             return 1;
         }
@@ -114,7 +114,7 @@ class SegmentPropertyState extends Abstr
         checkNotNull(type);
         checkArgument(!type.isArray(), "Type must not be an array type");
 
-        Segment segment = reader.getStore().readSegment(recordId.getSegmentId());
+        Segment segment = store.readSegment(recordId.getSegmentId());
 
         Type<?> base = getType();
         ListRecord values;
@@ -128,6 +128,7 @@ class SegmentPropertyState extends Abstr
         }
         checkElementIndex(index, values.size());
 
+        SegmentReader reader = new SegmentReader(store);
         RecordId valueId = values.getEntry(reader, index);
         if (type == Type.BINARY) {
             return (T) new SegmentBlob(reader, valueId);
@@ -170,13 +171,15 @@ class SegmentPropertyState extends Abstr
     public long size(int index) {
         ListRecord values;
         if (isArray()) {
-            int size = reader.readInt(recordId, 0);
-            RecordId listId = reader.readRecordId(recordId, 4);
+            Segment segment = store.readSegment(recordId.getSegmentId());
+            int size = segment.readInt(recordId.getOffset());
+            RecordId listId = segment.readRecordId(recordId.getOffset() + 4);
             values = new ListRecord(listId, size);
         } else {
             values = new ListRecord(recordId, 1);
         }
         checkElementIndex(index, values.size());
+        SegmentReader reader = new SegmentReader(store);
         return reader.readLength(values.getEntry(reader, 0));
     }
 

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=1452877&r1=1452876&r2=1452877&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
Tue Mar  5 16:13:53 2013
@@ -59,8 +59,6 @@ public class SegmentWriter {
 
     private final SegmentStore store;
 
-    private final SegmentReader reader;
-
     private final Map<String, RecordId> strings = Maps.newHashMap();
 
     private final Map<Template, RecordId> templates = Maps.newHashMap();
@@ -95,9 +93,8 @@ public class SegmentWriter {
      */
     private int position;
 
-    public SegmentWriter(SegmentStore store, SegmentReader reader) {
+    public SegmentWriter(SegmentStore store) {
         this.store = store;
-        this.reader = reader;
     }
 
     public synchronized void flush() {
@@ -678,7 +675,7 @@ public class SegmentWriter {
         for (RecordId id : ids) {
             writeRecordId(id);
         }
-        return new SegmentNodeState(reader, recordId);
+        return new SegmentNodeState(store, recordId);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java?rev=1452877&r1=1452876&r2=1452877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
Tue Mar  5 16:13:53 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import static com.google.common.base.Preconditions.checkElementIndex;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
+import static org.apache.jackrabbit.oak.plugins.segment.Segment.RECORD_ID_BYTES;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -176,7 +177,7 @@ class Template {
     }
 
     public PropertyState getProperty(
-            String name, SegmentReader reader, RecordId recordId) {
+            String name, SegmentStore store, RecordId recordId) {
         if ("jcr:primaryType".equals(name) && primaryType != null) {
             return primaryType;
         } else if ("jcr:mixinTypes".equals(name) && mixinTypes != null) {
@@ -191,7 +192,7 @@ class Template {
             while (index < properties.length
                     && properties[index].getName().hashCode() == hash) {
                 if (name.equals(properties[index].getName())) {
-                    return getProperty(reader, recordId, index);
+                    return getProperty(store, recordId, index);
                 }
                 index++;
             }
@@ -200,22 +201,23 @@ class Template {
     }
 
     private PropertyState getProperty(
-            SegmentReader reader, RecordId recordId, int index) {
-        checkNotNull(reader);
+            SegmentStore store, RecordId recordId, int index) {
+        checkNotNull(store);
         checkNotNull(recordId);
         checkElementIndex(index, properties.length);
 
-        int offset = 1;
+        int offset = recordId.getOffset() + RECORD_ID_BYTES;
         if (!hasNoChildNodes()) {
-            offset++;
+            offset += RECORD_ID_BYTES;
         }
+        offset += index * RECORD_ID_BYTES;
+        Segment segment = store.readSegment(recordId.getSegmentId());
         return new SegmentPropertyState(
-                properties[index], reader, reader.readRecordId(
-                        recordId, (offset + index) * Segment.RECORD_ID_BYTES));
+                properties[index], store, segment.readRecordId(offset));
     }
 
     public Iterable<PropertyState> getProperties(
-            SegmentReader reader, RecordId recordId) {
+            SegmentStore store, RecordId recordId) {
         List<PropertyState> list =
                 Lists.newArrayListWithCapacity(properties.length + 2);
         if (primaryType != null) {
@@ -224,44 +226,45 @@ class Template {
         if (mixinTypes != null) {
             list.add(mixinTypes);
         }
-        int offset = 1;
+        int offset = recordId.getOffset() + RECORD_ID_BYTES;
         if (!hasNoChildNodes()) {
-            offset++;
+            offset += RECORD_ID_BYTES;
         }
+        Segment segment = store.readSegment(recordId.getSegmentId());
         for (int i = 0; i < properties.length; i++) {
-            RecordId propertyId = reader.readRecordId(
-                    recordId, (offset + i) * Segment.RECORD_ID_BYTES);
+            RecordId propertyId = segment.readRecordId(offset);
             list.add(new SegmentPropertyState(
-                    properties[i], reader, propertyId));
+                    properties[i], store, propertyId));
+            offset += RECORD_ID_BYTES;
         }
         return list;
     }
 
-    public long getChildNodeCount(SegmentReader reader, RecordId recordId) {
+    public long getChildNodeCount(SegmentStore store, RecordId recordId) {
         if (hasNoChildNodes()) {
             return 0;
         } else if (hasManyChildNodes()) {
-            RecordId childNodesId =
-                    reader.readRecordId(recordId, Segment.RECORD_ID_BYTES);
-            return MapRecord.readMap(reader.getStore(), childNodesId).size();
+            MapRecord map = getChildNodeMap(store, recordId);
+            return map.size();
         } else {
             return 1;
         }
     }
 
-    MapRecord getChildNodeMap(SegmentReader reader, RecordId recordId) {
+    MapRecord getChildNodeMap(SegmentStore store, RecordId recordId) {
         checkState(hasManyChildNodes());
-        return MapRecord.readMap(
-                reader.getStore(),
-                reader.readRecordId(recordId, Segment.RECORD_ID_BYTES));
+        int offset = recordId.getOffset() + RECORD_ID_BYTES;
+        Segment segment = store.readSegment(recordId.getSegmentId());
+        RecordId childNodesId = segment.readRecordId(offset);
+        return MapRecord.readMap(store, childNodesId);
     }
 
     public boolean hasChildNode(
-            String name, SegmentReader reader, RecordId recordId) {
+            String name, SegmentStore store, RecordId recordId) {
         if (hasNoChildNodes()) {
             return false;
         } else if (hasManyChildNodes()) {
-            MapRecord map = getChildNodeMap(reader, recordId);
+            MapRecord map = getChildNodeMap(store, recordId);
             return map.getEntry(name) != null;
         } else {
             return name.equals(childName);
@@ -269,56 +272,59 @@ class Template {
     }
 
     public NodeState getChildNode(
-            String name, SegmentReader reader, RecordId recordId) {
+            String name, SegmentStore store, RecordId recordId) {
         if (hasNoChildNodes()) {
             return null;
         } else if (hasManyChildNodes()) {
-            RecordId childNodeId =
-                    getChildNodeMap(reader, recordId).getEntry(name);
+            MapRecord map = getChildNodeMap(store, recordId);
+            RecordId childNodeId = map.getEntry(name);
             if (childNodeId != null) {
-                return new SegmentNodeState(reader, childNodeId);
+                return new SegmentNodeState(store, childNodeId);
             } else {
                 return null;
             }
         } else if (name.equals(childName)) {
-            RecordId childNodeId =
-                    reader.readRecordId(recordId, Segment.RECORD_ID_BYTES);
-            return new SegmentNodeState(reader, childNodeId);
+            int offset = recordId.getOffset() + RECORD_ID_BYTES;
+            Segment segment = store.readSegment(recordId.getSegmentId());
+            RecordId childNodeId = segment.readRecordId(offset);
+            return new SegmentNodeState(store, childNodeId);
         } else {
             return null;
         }
     }
 
-    public Iterable<String> getChildNodeNames(
-            SegmentReader reader, RecordId recordId) {
+    Iterable<String> getChildNodeNames(SegmentStore store, RecordId recordId) {
         if (hasNoChildNodes()) {
             return Collections.emptyList();
         } else if (hasManyChildNodes()) {
-            return getChildNodeMap(reader, recordId).getKeys();
+            MapRecord map = getChildNodeMap(store, recordId);
+            return map.getKeys();
         } else {
             return Collections.singletonList(childName);
         }
     }
 
-    public Iterable<? extends ChildNodeEntry> getChildNodeEntries(
-            final SegmentReader reader, RecordId recordId) {
+    Iterable<? extends ChildNodeEntry> getChildNodeEntries(
+            SegmentStore store, RecordId recordId) {
         if (hasNoChildNodes()) {
             return Collections.emptyList();
         } else if (hasManyChildNodes()) {
-            return getChildNodeMap(reader, recordId).getEntries();
+            MapRecord map = getChildNodeMap(store, recordId);
+            return map.getEntries();
         } else {
-            RecordId childNodeId =
-                    reader.readRecordId(recordId, Segment.RECORD_ID_BYTES);
+            int offset = recordId.getOffset() + RECORD_ID_BYTES;
+            Segment segment = store.readSegment(recordId.getSegmentId());
+            RecordId childNodeId = segment.readRecordId(offset);
             return Collections.singletonList(new MemoryChildNodeEntry(
-                    childName, new SegmentNodeState(reader, childNodeId)));
+                    childName, new SegmentNodeState(store, childNodeId)));
         }
     }
 
     public void compareAgainstBaseState(
-            SegmentReader reader, RecordId afterId,
+            SegmentStore store, RecordId afterId,
             Template beforeTemplate, RecordId beforeId,
             NodeStateDiff diff) {
-        checkNotNull(reader);
+        checkNotNull(store);
         checkNotNull(afterId);
         checkNotNull(beforeTemplate);
         checkNotNull(beforeId);
@@ -342,37 +348,37 @@ class Template {
             PropertyState beforeProperty = null;
             PropertyState afterProperty = null;
             if (d < 0) {
-                afterProperty = getProperty(reader, afterId, afterIndex++);
+                afterProperty = getProperty(store, afterId, afterIndex++);
             } else if (d > 0) {
                 beforeProperty = beforeTemplate.getProperty(
-                        reader, beforeId, beforeIndex++);
+                        store, beforeId, beforeIndex++);
             } else {
-                afterProperty = getProperty(reader, afterId, afterIndex++);
+                afterProperty = getProperty(store, afterId, afterIndex++);
                 beforeProperty = beforeTemplate.getProperty(
-                        reader, beforeId, beforeIndex++);
+                        store, beforeId, beforeIndex++);
             }
             compareProperties(beforeProperty, afterProperty, diff);
         }
         while (afterIndex < properties.length) {
-            diff.propertyAdded(getProperty(reader, afterId, afterIndex++));
+            diff.propertyAdded(getProperty(store, afterId, afterIndex++));
         }
         while (beforeIndex < beforeTemplate.properties.length) {
             diff.propertyDeleted(beforeTemplate.getProperty(
-                    reader, beforeId, beforeIndex++));
+                    store, beforeId, beforeIndex++));
         }
 
         if (hasNoChildNodes()) {
             if (!beforeTemplate.hasNoChildNodes()) {
                 for (ChildNodeEntry entry :
-                        beforeTemplate.getChildNodeEntries(reader, beforeId)) {
+                        beforeTemplate.getChildNodeEntries(store, beforeId)) {
                     diff.childNodeDeleted(
                             entry.getName(), entry.getNodeState());
                 }
             }
         } else if (hasOneChildNode()) {
-            NodeState afterNode = getChildNode(childName, reader, afterId);
+            NodeState afterNode = getChildNode(childName, store, afterId);
             NodeState beforeNode = beforeTemplate.getChildNode(
-                    childName, reader, beforeId);
+                    childName, store, beforeId);
             if (beforeNode == null) {
                 diff.childNodeAdded(childName, afterNode);
             } else if (!beforeNode.equals(afterNode)) {
@@ -381,7 +387,7 @@ class Template {
             if ((beforeTemplate.hasOneChildNode() && beforeNode == null)
                     || beforeTemplate.hasManyChildNodes()) {
                 for (ChildNodeEntry entry :
-                    beforeTemplate.getChildNodeEntries(reader, beforeId)) {
+                    beforeTemplate.getChildNodeEntries(store, beforeId)) {
                     if (!childName.equals(entry.getName())) {
                         diff.childNodeDeleted(
                                 entry.getName(), entry.getNodeState());
@@ -392,10 +398,10 @@ class Template {
             // TODO: Leverage the HAMT data structure for the comparison
             Set<String> baseChildNodes = new HashSet<String>();
             for (ChildNodeEntry beforeCNE
-                    : beforeTemplate.getChildNodeEntries(reader, beforeId)) {
+                    : beforeTemplate.getChildNodeEntries(store, beforeId)) {
                 String name = beforeCNE.getName();
                 NodeState beforeChild = beforeCNE.getNodeState();
-                NodeState afterChild = getChildNode(name, reader, afterId);
+                NodeState afterChild = getChildNode(name, store, afterId);
                 if (afterChild == null) {
                     diff.childNodeDeleted(name, beforeChild);
                 } else {
@@ -406,7 +412,7 @@ class Template {
                 }
             }
             for (ChildNodeEntry afterChild
-                    : getChildNodeEntries(reader, afterId)) {
+                    : getChildNodeEntries(store, afterId)) {
                 String name = afterChild.getName();
                 if (!baseChildNodes.contains(name)) {
                     diff.childNodeAdded(name, afterChild.getNodeState());

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=1452877&r1=1452876&r2=1452877&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
Tue Mar  5 16:13:53 2013
@@ -31,9 +31,7 @@ public class CompareAgainstBaseStateTest
 
     private final SegmentStore store = new MemoryStore();
 
-    private final SegmentReader reader = new SegmentReader(store);
-
-    private final SegmentWriter writer = new SegmentWriter(store, reader);
+    private final SegmentWriter writer = new SegmentWriter(store);
 
     private final NodeStateDiff diff = EasyMock.createMock(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=1452877&r1=1452876&r2=1452877&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
Tue Mar  5 16:13:53 2013
@@ -51,7 +51,7 @@ public class RecordTest {
 
     private SegmentReader reader = new SegmentReader(store);
 
-    private SegmentWriter writer = new SegmentWriter(store, reader);
+    private SegmentWriter writer = new SegmentWriter(store);
 
     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=1452877&r1=1452876&r2=1452877&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
Tue Mar  5 16:13:53 2013
@@ -145,8 +145,7 @@ public class SegmentSizeTest {
     @Test
     public void testFlatNodeUpdate() {
         SegmentStore store = new MemoryStore();
-        SegmentReader reader = new SegmentReader(store);
-        SegmentWriter writer = new SegmentWriter(store, reader);
+        SegmentWriter writer = new SegmentWriter(store);
 
         NodeBuilder builder = MemoryNodeState.EMPTY_NODE.builder();
         for (int i = 0; i < 1000; i++) {
@@ -168,7 +167,7 @@ public class SegmentSizeTest {
 
     private int getSize(NodeBuilder builder) {
         SegmentStore store = new MemoryStore();
-        SegmentWriter writer = new SegmentWriter(store, new SegmentReader(store));
+        SegmentWriter writer = new SegmentWriter(store);
         RecordId id = writer.writeNode(builder.getNodeState()).getRecordId();
         writer.flush();
         Segment segment = store.readSegment(id.getSegmentId());
@@ -177,7 +176,7 @@ public class SegmentSizeTest {
 
     private int getAmortizedSize(NodeBuilder builder) {
         SegmentStore store = new MemoryStore();
-        SegmentWriter writer = new SegmentWriter(store, new SegmentReader(store));
+        SegmentWriter writer = new SegmentWriter(store);
         NodeState state = builder.getNodeState();
         RecordId id = writer.writeNode(state).getRecordId();
         writer.flush();



Mime
View raw message