jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1449776 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: Segment.java SegmentNodeState.java SegmentReader.java
Date Mon, 25 Feb 2013 16:52:05 GMT
Author: jukka
Date: Mon Feb 25 16:52:05 2013
New Revision: 1449776

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

Move template cache and loading code from SegmentReader to Segment to avoid unnecessary segment
lookups

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/SegmentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.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=1449776&r1=1449775&r2=1449776&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
Mon Feb 25 16:52:05 2013
@@ -20,9 +20,14 @@ import static com.google.common.base.Pre
 import static com.google.common.base.Preconditions.checkPositionIndexes;
 import static org.apache.jackrabbit.oak.plugins.segment.SegmentWriter.BLOCK_SIZE;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.UUID;
 
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+
 import com.google.common.base.Charsets;
 import com.google.common.cache.Weigher;
 
@@ -119,7 +124,57 @@ class Segment {
     private final OffsetCache<Template> templates = new OffsetCache<Template>()
{
         @Override
         protected Template load(int offset) {
-            return null;
+            int head = readInt(offset);
+            boolean hasPrimaryType = (head & (1 << 31)) != 0;
+            boolean hasMixinTypes = (head & (1 << 30)) != 0;
+            boolean zeroChildNodes = (head & (1 << 29)) != 0;
+            boolean manyChildNodes = (head & (1 << 28)) != 0;
+            int mixinCount = (head >> 18) & ((1 << 10) - 1);
+            int propertyCount = head & ((1 << 18) - 1);
+            offset += 4;
+
+            PropertyState primaryType = null;
+            if (hasPrimaryType) {
+                RecordId primaryId = readRecordId(offset);
+                primaryType = PropertyStates.createProperty(
+                        "jcr:primaryType", readString(primaryId), Type.NAME);
+                offset += Segment.RECORD_ID_BYTES;
+            }
+
+            PropertyState mixinTypes = null;
+            if (hasMixinTypes) {
+                String[] mixins = new String[mixinCount];
+                for (int i = 0; i < mixins.length; i++) {
+                    RecordId mixinId = readRecordId(offset);
+                    mixins[i] =  readString(mixinId);
+                    offset += Segment.RECORD_ID_BYTES;
+                }
+                mixinTypes = PropertyStates.createProperty(
+                        "jcr:mixinTypes", Arrays.asList(mixins), Type.NAMES);
+            }
+
+            String childName = Template.ZERO_CHILD_NODES;
+            if (manyChildNodes) {
+                childName = Template.MANY_CHILD_NODES;
+            } else if (!zeroChildNodes) {
+                RecordId childNameId = readRecordId(offset);
+                childName = readString(childNameId);
+                offset += Segment.RECORD_ID_BYTES;
+            }
+
+            PropertyTemplate[] properties =
+                    new PropertyTemplate[propertyCount];
+            for (int i = 0; i < properties.length; i++) {
+                RecordId propertyNameId = readRecordId(offset);
+                offset += Segment.RECORD_ID_BYTES;
+                byte type = readByte(offset++);
+                properties[i] = new PropertyTemplate(
+                        readString(propertyNameId),
+                        Type.fromTag(Math.abs(type), type < 0));
+            }
+
+            return new Template(
+                    primaryType, mixinTypes, properties, childName);
         }
     };
 
@@ -209,6 +264,19 @@ class Segment {
         return segment.readString(id.getOffset());
     }
 
+    Template readTemplate(int offset) {
+        return templates.get(offset);
+    }
+
+    Template readTemplate(RecordId id) {
+        checkNotNull(id);
+        Segment segment = this;
+        if (!uuid.equals(id.getSegmentId())) {
+            segment = store.readSegment(id.getSegmentId());
+        }
+        return segment.readTemplate(id.getOffset());
+    }
+
     long readLength(int offset) {
         return internalReadLength(pos(offset, 1));
     }

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=1449776&r1=1449775&r2=1449776&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
Mon Feb 25 16:52:05 2013
@@ -48,7 +48,9 @@ class SegmentNodeState extends AbstractN
 
     private synchronized Template getTemplate() {
         if (template == null) {
-            template = reader.readTemplate(reader.readRecordId(recordId, 0));
+            Segment segment = reader.getStore().readSegment(recordId.getSegmentId());
+            RecordId templateId = segment.readRecordId(recordId.getOffset());
+            template = segment.readTemplate(templateId);
         }
         return template;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.java?rev=1449776&r1=1449775&r2=1449776&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentReader.java
Mon Feb 25 16:52:05 2013
@@ -36,86 +36,10 @@ public class SegmentReader {
 
     private final SegmentStore store;
 
-    private final LoadingCache<RecordId, Template> templates =
-            CacheBuilder.newBuilder()
-            .maximumSize(1000)
-            .build(newTemplateLoader());
-
     public SegmentReader(SegmentStore store) {
         this.store = store;
     }
 
-    private CacheLoader<RecordId, Template> newTemplateLoader() {
-        return new CacheLoader<RecordId, Template>() {
-            @Override
-            public Template load(RecordId key) throws Exception {
-                Segment segment = store.readSegment(key.getSegmentId());
-                int offset = key.getOffset();
-
-                int head = segment.readInt(offset);
-                boolean hasPrimaryType = (head & (1 << 31)) != 0;
-                boolean hasMixinTypes = (head & (1 << 30)) != 0;
-                boolean zeroChildNodes = (head & (1 << 29)) != 0;
-                boolean manyChildNodes = (head & (1 << 28)) != 0;
-                int mixinCount = (head >> 18) & ((1 << 10) - 1);
-                int propertyCount = head & ((1 << 18) - 1);
-                offset += 4;
-
-                PropertyState primaryType = null;
-                if (hasPrimaryType) {
-                    RecordId primaryId = segment.readRecordId(offset);
-                    primaryType = PropertyStates.createProperty(
-                            "jcr:primaryType", segment.readString(primaryId), Type.NAME);
-                    offset += Segment.RECORD_ID_BYTES;
-                }
-
-                PropertyState mixinTypes = null;
-                if (hasMixinTypes) {
-                    String[] mixins = new String[mixinCount];
-                    for (int i = 0; i < mixins.length; i++) {
-                        RecordId mixinId = segment.readRecordId(offset);
-                        mixins[i] =  segment.readString(mixinId);
-                        offset += Segment.RECORD_ID_BYTES;
-                    }
-                    mixinTypes = PropertyStates.createProperty(
-                            "jcr:mixinTypes", Arrays.asList(mixins), Type.NAMES);
-                }
-
-                String childName = Template.ZERO_CHILD_NODES;
-                if (manyChildNodes) {
-                    childName = Template.MANY_CHILD_NODES;
-                } else if (!zeroChildNodes) {
-                    RecordId childNameId = segment.readRecordId(offset);
-                    childName = segment.readString(childNameId);
-                    offset += Segment.RECORD_ID_BYTES;
-                }
-
-                PropertyTemplate[] properties =
-                        new PropertyTemplate[propertyCount];
-                for (int i = 0; i < properties.length; i++) {
-                    RecordId propertyNameId = segment.readRecordId(offset);
-                    offset += Segment.RECORD_ID_BYTES;
-                    byte type = segment.readByte(offset++);
-                    properties[i] = new PropertyTemplate(
-                            segment.readString(propertyNameId),
-                            Type.fromTag(Math.abs(type), type < 0));
-                }
-
-                return new Template(
-                        primaryType, mixinTypes, properties, childName);
-            }
-        };
-    }
-
-    public Template readTemplate(RecordId recordId) {
-        try {
-            return templates.get(recordId);
-        } catch (ExecutionException e) {
-            throw new IllegalStateException(
-                    "Unable to access template record " + recordId, e);
-        }
-    }
-
     public long readLength(RecordId recordId) {
         checkNotNull(recordId);
         Segment segment = store.readSegment(recordId.getSegmentId());



Mime
View raw message