jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1477973 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/ oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ oak-run/src/...
Date Wed, 01 May 2013 12:31:28 GMT
Author: jukka
Date: Wed May  1 12:31:28 2013
New Revision: 1477973

URL: http://svn.apache.org/r1477973
Log:
OAK-788: File backend for the SegmentMK

Initial, incomplete FileStore for the SegmentMK

Modified:
    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/Segment.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.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/CompareAgainstBaseStateTest.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/fixture/OakRepositoryFixture.java

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=1477973&r1=1477972&r2=1477973&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
Wed May  1 12:31:28 2013
@@ -16,11 +16,10 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
-
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 
 import java.nio.ByteBuffer;
-import java.util.Collections;
+import java.util.Collection;
 import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
@@ -65,7 +64,15 @@ public class MemoryStore implements Segm
     }
 
     @Override
-    public void createSegment(Segment segment) {
+    public void createSegment(
+            UUID segmentId, byte[] data, int offset, int length,
+            Collection<UUID> referencedSegmentIds,
+            Map<String, RecordId> strings, Map<Template, RecordId> templates)
{
+        byte[] buffer = new byte[length];
+        System.arraycopy(data, offset, buffer, 0, length);
+        Segment segment = new Segment(
+                this, segmentId, ByteBuffer.wrap(buffer),
+                referencedSegmentIds, strings, templates);
         if (segments.putIfAbsent(segment.getSegmentId(), segment) != null) {
             throw new IllegalStateException(
                     "Segment override: " + segment.getSegmentId());
@@ -73,16 +80,6 @@ public class MemoryStore implements Segm
     }
 
     @Override
-    public void createSegment(
-            UUID segmentId, byte[] data, int offset, int length) {
-        byte[] segment = new byte[length];
-        System.arraycopy(data, offset, segment, 0, length);
-        createSegment(new Segment(
-                this, segmentId, ByteBuffer.wrap(segment),
-                Collections.<UUID>emptySet()));
-    }
-
-    @Override
     public void deleteSegment(UUID segmentId) {
         if (segments.remove(segmentId) == null) {
             throw new IllegalStateException("Missing segment: " + segmentId);

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=1477973&r1=1477972&r2=1477973&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
Wed May  1 12:31:28 2013
@@ -23,6 +23,8 @@ import static com.mongodb.ReadPreference
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 
 import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -88,22 +90,19 @@ public class MongoStore implements Segme
     }
 
     @Override
-    public void createSegment(Segment segment) {
-        cache.addSegment(segment);
-        byte[] bytes = new byte[segment.size()];
-        segment.getData().duplicate().get(bytes);
-        insertSegment(segment.getSegmentId(), bytes, segment.getUUIDs());
-    }
-
-    @Override
     public void createSegment(
-            UUID segmentId, byte[] data, int offset, int length) {
-        byte[] d = data;
-        if (offset != 0 || length != data.length) {
-            d = new byte[length];
-            System.arraycopy(data, offset, d, 0, length);
-        }
-        insertSegment(segmentId, d, new UUID[0]);
+            UUID segmentId, byte[] data, int offset, int length,
+            Collection<UUID> referencedSegmentIds,
+            Map<String, RecordId> strings, Map<Template, RecordId> templates)
{
+        byte[] d = new byte[length];
+        System.arraycopy(data, offset, d, 0, length);
+
+        cache.addSegment(new Segment(
+                this, segmentId, ByteBuffer.wrap(data), referencedSegmentIds,
+                Collections.<String, RecordId>emptyMap(),
+                Collections.<Template, RecordId>emptyMap()));
+
+        insertSegment(segmentId, d, referencedSegmentIds);
     }
 
     private Segment findSegment(UUID segmentId) {
@@ -125,11 +124,15 @@ public class MongoStore implements Segme
         for (Object object : list) {
             uuids.add(UUID.fromString(object.toString()));
         }
-        return new Segment(this, segmentId, ByteBuffer.wrap(data), uuids);
+        return new Segment(
+                this, segmentId, ByteBuffer.wrap(data), uuids,
+                Collections.<String, RecordId>emptyMap(),
+                Collections.<Template, RecordId>emptyMap());
     }
 
-    private void insertSegment(UUID segmentId, byte[] data, UUID[] uuids) {
-        List<String> list = Lists.newArrayListWithCapacity(uuids.length);
+    private void insertSegment(
+            UUID segmentId, byte[] data, Collection<UUID> uuids) {
+        List<String> list = Lists.newArrayListWithCapacity(uuids.size());
         for (UUID uuid : uuids) {
             list.add(uuid.toString());
         }

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=1477973&r1=1477972&r2=1477973&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
Wed May  1 12:31:28 2013
@@ -104,32 +104,12 @@ class Segment {
     private final OffsetCache<Template> templates;
 
     Segment(SegmentStore store,
-            UUID uuid, ByteBuffer data, Collection<UUID> uuids) {
+            UUID uuid, ByteBuffer data, Collection<UUID> uuids,
+            Map<String, RecordId> strings, Map<Template, RecordId> templates)
{
         this.store = checkNotNull(store);
         this.uuid = checkNotNull(uuid);
         this.data = checkNotNull(data);
         this.uuids = checkNotNull(uuids).toArray(NO_UUIDS);
-        this.strings = new OffsetCache<String>() {
-            @Override
-            protected String load(int offset) {
-                return loadString(offset);
-            }
-        };
-        this.templates = new OffsetCache<Template>() {
-            @Override
-            protected Template load(int offset) {
-                return loadTemplate(offset);
-            }
-        };
-    }
-
-    Segment(SegmentStore store,
-            UUID uuid, byte[] data, Collection<UUID> uuids,
-            Map<String, RecordId> strings, Map<Template, RecordId> templates)
{
-        this.store = store;
-        this.uuid = uuid;
-        this.data = ByteBuffer.wrap(data);
-        this.uuids = uuids.toArray(new UUID[uuids.size()]);
         this.strings = new OffsetCache<String>(strings) {
             @Override
             protected String load(int offset) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java?rev=1477973&r1=1477972&r2=1477973&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
Wed May  1 12:31:28 2013
@@ -17,7 +17,9 @@
 package org.apache.jackrabbit.oak.plugins.segment;
 
 import java.net.UnknownHostException;
+import java.util.Collection;
 import java.util.Dictionary;
+import java.util.Map;
 import java.util.UUID;
 
 import org.apache.felix.scr.annotations.Activate;
@@ -82,13 +84,14 @@ public class SegmentNodeStoreService ext
                 return store[0].readSegment(segmentId);
             }            
             @Override
-            public void createSegment(Segment segment) {
-                store[0].createSegment(segment);
-            }
-            @Override
             public void createSegment(
-                    UUID segmentId, byte[] bytes, int offset, int len) {
-                store[0].createSegment(segmentId, bytes, offset, len);
+                    UUID segmentId, byte[] bytes, int offset, int length,
+                    Collection<UUID> referencedSegmentIds,
+                    Map<String, RecordId> strings,
+                    Map<Template, RecordId> templates) {
+                store[0].createSegment(
+                        segmentId, bytes, offset, length,
+                        referencedSegmentIds, strings, templates);
             }
             @Override
             public void deleteSegment(UUID segmentId) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java?rev=1477973&r1=1477972&r2=1477973&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
Wed May  1 12:31:28 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
+import java.util.Collection;
+import java.util.Map;
 import java.util.UUID;
 
 public interface SegmentStore {
@@ -24,9 +26,10 @@ public interface SegmentStore {
 
     Segment readSegment(UUID segmentId);
 
-    void createSegment(Segment segment);
-
-    void createSegment(UUID segmentId, byte[] bytes, int offset, int len);
+    void createSegment(
+            UUID segmentId, byte[] bytes, int offset, int length,
+            Collection<UUID> referencedSegmentIds,
+            Map<String, RecordId> strings, Map<Template, RecordId> templates);
 
     void deleteSegment(UUID segmentId);
 

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=1477973&r1=1477972&r2=1477973&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
Wed May  1 12:31:28 2013
@@ -100,18 +100,11 @@ public class SegmentWriter {
 
     public synchronized void flush() {
         if (length > 0) {
-            byte[] data = buffer;
-            if (length < buffer.length) {
-                data = new byte[length];
-                System.arraycopy(
-                        buffer, buffer.length - length, data, 0, data.length);
-            }
-
-            store.createSegment(new Segment(
-                    store, uuid, data, uuids.keySet(), strings, templates));
+            store.createSegment(
+                    uuid, buffer, buffer.length - length, length,
+                    uuids.keySet(), strings, templates);
 
             uuid = UUID.randomUUID();
-            buffer = EMPTY_BUFFER;
             length = 0;
             uuids.clear();
             strings.clear();
@@ -504,7 +497,11 @@ public class SegmentWriter {
                 UUID segmentId = UUID.randomUUID();
                 int align = Segment.RECORD_ALIGN_BYTES - 1;
                 int bulkAlignLength = (bulkLength + align) & ~align;
-                store.createSegment(segmentId, bulk, 0, bulkAlignLength);
+                store.createSegment(
+                        segmentId, bulk, 0, bulkAlignLength,
+                        Collections.<UUID>emptyList(),
+                        Collections.<String, RecordId>emptyMap(),
+                        Collections.<Template, RecordId>emptyMap());
                 for (int pos = Segment.MAX_SEGMENT_SIZE - bulkAlignLength;
                         pos < Segment.MAX_SEGMENT_SIZE;
                         pos += BLOCK_SIZE) {

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=1477973&r1=1477972&r2=1477973&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
Wed May  1 12:31:28 2013
@@ -17,7 +17,7 @@
 package org.apache.jackrabbit.oak.plugins.segment;
 
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
-import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createControl;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
@@ -25,7 +25,6 @@ import static org.easymock.EasyMock.veri
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
-import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -38,7 +37,8 @@ public class CompareAgainstBaseStateTest
 
     private final SegmentWriter writer = new SegmentWriter(store);
 
-    private final NodeStateDiff diff = EasyMock.createMock(NodeStateDiff.class);
+    private final NodeStateDiff diff =
+            createControl().createMock("diff", NodeStateDiff.class);
 
     private final NodeBuilder builder = EMPTY_NODE.builder();
 

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java?rev=1477973&r1=1477972&r2=1477973&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
Wed May  1 12:31:28 2013
@@ -57,7 +57,8 @@ public class BenchmarkRunner {
                 OakRepositoryFixture.getMongo(
                         host.value(options), port.value(options), cacheSize * MB),
                 OakRepositoryFixture.getSegment(
-                        host.value(options), port.value(options), cacheSize * MB)
+                        host.value(options), port.value(options), cacheSize * MB),
+                OakRepositoryFixture.getTar("data.tar")
         };
         Benchmark[] allBenchmarks = new Benchmark[] {
             new LoginTest(),

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/fixture/OakRepositoryFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/fixture/OakRepositoryFixture.java?rev=1477973&r1=1477972&r2=1477973&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/fixture/OakRepositoryFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/fixture/OakRepositoryFixture.java
Wed May  1 12:31:28 2013
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.mongomk.uti
 import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.jcr.Jcr;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
+import org.apache.jackrabbit.oak.plugins.segment.FileStore;
 import org.apache.jackrabbit.oak.plugins.segment.MongoStore;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentStore;
@@ -135,6 +136,21 @@ public abstract class OakRepositoryFixtu
         };
     }
 
+    public static RepositoryFixture getTar(final String file) {
+        return new OakRepositoryFixture("Oak-Tar") {
+            @Override
+            public Repository[] setUpCluster(int n) throws Exception {
+                Repository[] cluster = new Repository[n];
+                for (int i = 0; i < cluster.length; i++) {
+                    SegmentStore store = new FileStore(file);
+                    Oak oak = new Oak(new SegmentNodeStore(store));
+                    cluster[i] = new Jcr(oak).createRepository();
+                }
+                return cluster;
+            }
+        };
+    }
+
     private final String name;
 
     protected final String unique;



Mime
View raw message