jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1575339 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: AbstractStore.java SegmentNodeBuilder.java SegmentStore.java SegmentWriter.java memory/MemoryStore.java
Date Fri, 07 Mar 2014 17:42:51 GMT
Author: jukka
Date: Fri Mar  7 17:42:50 2014
New Revision: 1575339

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

Make MemoryStore implement SegmentStore directly to make it easier to simplify caching in
AbstractStore.
Drop SegmentStore.isInstance().

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.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/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java?rev=1575339&r1=1575338&r2=1575339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
Fri Mar  7 17:42:50 2014
@@ -152,12 +152,6 @@ public abstract class AbstractStore impl
         }
     }
 
-    @Override
-    public boolean isInstance(Object object, Class<? extends Record> type) {
-        assert Record.class.isAssignableFrom(type);
-        return type.isInstance(object) && ((Record) object).getStore() == this;
-    }
-
     @Override @CheckForNull
     public Blob readBlob(String reference) {
         return null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java?rev=1575339&r1=1575338&r2=1575339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeBuilder.java
Fri Mar  7 17:42:50 2014
@@ -58,13 +58,12 @@ public class SegmentNodeBuilder extends 
     @Override
     public SegmentNodeState getNodeState() {
         NodeState state = super.getNodeState();
-        if (!store.isInstance(state, SegmentNodeState.class)) {
-            state = store.getWriter().writeNode(state);
-            set(state);
+        SegmentNodeState sstate = store.getWriter().writeNode(state);
+        if (state != sstate) {
+            set(sstate);
             updateCount = 0;
         }
-        // guaranteed to be a SegmentNodeState from the same store as the base
-        return (SegmentNodeState) state;
+        return sstate;
     }
 
 }

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=1575339&r1=1575338&r2=1575339&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
Fri Mar  7 17:42:50 2014
@@ -59,17 +59,6 @@ public interface SegmentStore {
     void close();
 
     /**
-     * Checks whether the given object is a record of the given type and
-     * is stored in this segment store.
-     *
-     * @param object possible record object
-     * @param type record type
-     * @return {@code true} if the object is a record of the given type
-     *         from this store, {@code false} otherwise
-     */
-    boolean isInstance(Object object, Class<? extends Record> type);
-
-    /**
      * Read a blob from external storage.
      *
      * @param reference blob reference

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=1575339&r1=1575338&r2=1575339&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
Fri Mar  7 17:42:50 2014
@@ -669,17 +669,18 @@ public class SegmentWriter {
     }
 
     public SegmentBlob writeBlob(Blob blob) throws IOException {
-        if (store.isInstance(blob, SegmentBlob.class)) {
+        if (blob instanceof SegmentBlob
+                && ((SegmentBlob) blob).getStore() == store) {
             return (SegmentBlob) blob;
-        } else {
-            String reference = blob.getReference();
-            if (reference != null) {
-                RecordId id = writeValueRecord(reference, blob.length());
-                return new SegmentBlob(dummySegment, id);
-            } else {
-                return writeStream(blob.getNewStream());
-            }
         }
+
+        String reference = blob.getReference();
+        if (reference != null) {
+            RecordId id = writeValueRecord(reference, blob.length());
+            return new SegmentBlob(dummySegment, id);
+        }
+
+        return writeStream(blob.getNewStream());
     }
 
     /**
@@ -869,7 +870,8 @@ public class SegmentWriter {
     }
 
     public SegmentNodeState writeNode(NodeState state) {
-        if (store.isInstance(state, SegmentNodeState.class)) {
+        if (state instanceof SegmentNodeState
+                && ((SegmentNodeState) state).getStore() == store) {
             return (SegmentNodeState) state;
         }
 
@@ -879,7 +881,8 @@ public class SegmentWriter {
         if (state instanceof ModifiedNodeState) {
             after = (ModifiedNodeState) state;
             NodeState base = after.getBaseState();
-            if (store.isInstance(base, SegmentNodeState.class)) {
+            if (base instanceof SegmentNodeState
+                    && ((SegmentNodeState) base).getStore() == store) {
                 before = (SegmentNodeState) base;
                 beforeTemplate = before.getTemplate();
             }
@@ -939,9 +942,11 @@ public class SegmentWriter {
             String name = pt.getName();
             PropertyState property = state.getProperty(name);
 
-            if (store.isInstance(property, SegmentPropertyState.class)) {
+            if (property instanceof SegmentPropertyState
+                    && ((SegmentPropertyState) property).getStore() == store) {
                 ids.add(((SegmentPropertyState) property).getRecordId());
-            } else if (!store.isInstance(before, SegmentNodeState.class)) {
+            } else if (!(before instanceof SegmentNodeState)
+                    || ((SegmentNodeState) before).getStore() != store) {
                 ids.add(writeProperty(property));
             } else {
                 // reuse previously stored property, if possible

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java?rev=1575339&r1=1575338&r2=1575339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/memory/MemoryStore.java
Fri Mar  7 17:42:50 2014
@@ -24,16 +24,22 @@ import java.util.concurrent.ConcurrentMa
 
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.oak.plugins.segment.AbstractStore;
+import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.plugins.segment.Segment;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentIdFactory;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeState;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentStore;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentWriter;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import com.google.common.collect.Maps;
 
-public class MemoryStore extends AbstractStore {
+public class MemoryStore implements SegmentStore {
+
+    private final SegmentIdFactory factory = new SegmentIdFactory();
+
+    private final SegmentWriter writer = new SegmentWriter(this, factory);
 
     private SegmentNodeState head;
 
@@ -41,8 +47,6 @@ public class MemoryStore extends Abstrac
             Maps.newConcurrentMap();
 
     public MemoryStore(NodeState root) {
-        super(0);
-
         NodeBuilder builder = EMPTY_NODE.builder();
         builder.setChildNode("root", root);
 
@@ -56,7 +60,8 @@ public class MemoryStore extends Abstrac
     }
 
     @Override
-    public void close() {
+    public SegmentWriter getWriter() {
+        return writer;
     }
 
     @Override
@@ -75,12 +80,12 @@ public class MemoryStore extends Abstrac
     }
 
     @Override @Nonnull
-    protected Segment loadSegment(UUID id) {
-        Segment segment = segments.get(id);
+    public Segment readSegment(UUID uuid) {
+        Segment segment = segments.get(uuid);
         if (segment != null) {
             return segment;
         } else {
-            throw new IllegalArgumentException("Segment not found: " + id);
+            throw new IllegalArgumentException("Segment not found: " + uuid);
         }
     }
 
@@ -90,11 +95,19 @@ public class MemoryStore extends Abstrac
         ByteBuffer buffer = ByteBuffer.allocate(length);
         buffer.put(data, offset, length);
         buffer.rewind();
-        Segment segment = createSegment(segmentId, buffer);
-        if (segments.putIfAbsent(segment.getSegmentId(), segment) != null) {
-            throw new IllegalStateException(
-                    "Segment override: " + segment.getSegmentId());
+        Segment segment = new Segment(this, factory, segmentId, buffer);
+        if (segments.putIfAbsent(segmentId, segment) != null) {
+            throw new IllegalStateException("Segment override: " + segmentId);
         }
     }
 
+    @Override
+    public void close() {
+    }
+
+    @Override
+    public Blob readBlob(String reference) {
+        return null;
+    }
+
 }



Mime
View raw message