jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1452849 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: Segment.java SegmentReader.java SegmentStream.java
Date Tue, 05 Mar 2013 15:28:41 GMT
Author: jukka
Date: Tue Mar  5 15:28:41 2013
New Revision: 1452849

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

Move readStream() from SegmentReader to Segment

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/SegmentReader.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.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=1452849&r1=1452848&r2=1452849&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
Tue Mar  5 15:28:41 2013
@@ -195,6 +195,10 @@ class Segment {
 
     RecordId readRecordId(int offset) {
         int pos = pos(offset, RECORD_ID_BYTES);
+        return internalReadRecordId(pos);
+    }
+
+    private RecordId internalReadRecordId(int pos) {
         return new RecordId(
                 uuids[data[pos] & 0xff],
                 (data[pos + 1] & 0xff) << (8 + Segment.RECORD_ALIGN_BITS)
@@ -231,10 +235,10 @@ class Segment {
             return new String(data, pos + 2, (int) length, Charsets.UTF_8);
         } else if (length < Integer.MAX_VALUE) {
             int size = (int) ((length + BLOCK_SIZE - 1) / BLOCK_SIZE);
-            ListRecord list = new ListRecord(readRecordId(offset + 8), size);
+            ListRecord list =
+                    new ListRecord(internalReadRecordId(pos + 8), size);
             SegmentStream stream = new SegmentStream(
-                    new SegmentReader(store), new RecordId(uuid, offset),
-                    list, length);
+                    store, new RecordId(uuid, offset), list, length);
             try {
                 return stream.getString();
             } finally {
@@ -337,4 +341,23 @@ class Segment {
         }
     }
 
+    SegmentStream readStream(int offset) {
+        RecordId id = new RecordId(uuid, offset);
+        int pos = pos(offset, 1);
+        long length = internalReadLength(pos);
+        if (length < Segment.MEDIUM_LIMIT) {
+            byte[] inline = new byte[(int) length];
+            if (length < Segment.SMALL_LIMIT) {
+                System.arraycopy(data, pos + 1, inline, 0, inline.length);
+            } else {
+                System.arraycopy(data, pos + 2, inline, 0, inline.length);
+            }
+            return new SegmentStream(id, inline);
+        } else {
+            int size = (int) ((length + BLOCK_SIZE - 1) / BLOCK_SIZE);
+            ListRecord list = new ListRecord(internalReadRecordId(pos + 8), size);
+            return new SegmentStream(store, id, list, length);
+        }
+    }
+
 }

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=1452849&r1=1452848&r2=1452849&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
Tue Mar  5 15:28:41 2013
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.plugin
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkPositionIndexes;
-import static org.apache.jackrabbit.oak.plugins.segment.SegmentWriter.BLOCK_SIZE;
 
 public class SegmentReader {
 
@@ -41,23 +40,7 @@ public class SegmentReader {
 
     public SegmentStream readStream(RecordId recordId) {
         Segment segment = store.readSegment(recordId.getSegmentId());
-        int offset = recordId.getOffset();
-        long length = readLength(segment, offset);
-        if (length < Segment.MEDIUM_LIMIT) {
-            if (length < Segment.SMALL_LIMIT) {
-                offset += 1;
-            } else {
-                offset += 2;
-            }
-            byte[] data = new byte[(int) length];
-            segment.readBytes(offset, data, 0, data.length);
-            return new SegmentStream(recordId, data);
-        } else {
-            int size = (int) ((length + BLOCK_SIZE - 1) / BLOCK_SIZE);
-            ListRecord list =
-                    new ListRecord(segment.readRecordId(offset + 8), size);
-            return new SegmentStream(this, recordId, list, length);
-        }
+        return segment.readStream(recordId.getOffset());
     }
 
     public byte readByte(RecordId recordId, int position) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java?rev=1452849&r1=1452848&r2=1452849&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java
Tue Mar  5 15:28:41 2013
@@ -43,7 +43,7 @@ public class SegmentStream extends Input
     }
 
 
-    private final SegmentReader reader;
+    private final SegmentStore store;
 
     private final RecordId recordId;
 
@@ -58,9 +58,9 @@ public class SegmentStream extends Input
     private long mark = 0;
 
     SegmentStream(
-            SegmentReader reader, RecordId recordId,
+            SegmentStore store, RecordId recordId,
             ListRecord blocks, long length) {
-        this.reader = checkNotNull(reader);
+        this.store = checkNotNull(store);
         this.recordId = checkNotNull(recordId);
         this.inline = null;
         this.blocks = checkNotNull(blocks);
@@ -69,7 +69,7 @@ public class SegmentStream extends Input
     }
 
     SegmentStream(RecordId recordId, byte[] inline) {
-        this.reader = null;
+        this.store = null;
         this.recordId = checkNotNull(recordId);
         this.inline = checkNotNull(inline);
         this.blocks = null;
@@ -87,7 +87,7 @@ public class SegmentStream extends Input
             throw new IllegalStateException("Too long value: " + length);
         } else {
             SegmentStream stream =
-                    new SegmentStream(reader, recordId, blocks, length);
+                    new SegmentStream(store, recordId, blocks, length);
             try {
                 byte[] data = new byte[(int) length];
                 ByteStreams.readFully(stream, data);
@@ -156,6 +156,7 @@ public class SegmentStream extends Input
                 len = (int) (length - position);
             }
 
+            SegmentReader reader = new SegmentReader(store);
             BlockRecord block = reader.readBlock(
                     blocks.getEntry(reader, blockIndex), BLOCK_SIZE);
             len = block.read(reader, blockOffset, b, off, len);



Mime
View raw message