jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1448545 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: MemoryStore.java MongoStore.java SegmentNodeStore.java SegmentNodeStoreBranch.java SegmentStore.java
Date Thu, 21 Feb 2013 08:37:21 GMT
Author: jukka
Date: Thu Feb 21 08:37:20 2013
New Revision: 1448545

URL: http://svn.apache.org/r1448545
Log:
OAK-633: SegmentMK: Hierarchy of journals

Add journal name parameter to SegmentStore

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/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/SegmentStore.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=1448545&r1=1448544&r2=1448545&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
Thu Feb 21 08:37:20 2013
@@ -16,48 +16,55 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
 
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+import com.google.common.collect.Maps;
 
 public class MemoryStore implements SegmentStore {
 
-    private final Map<UUID, Segment> segments =
-        Collections.synchronizedMap(new HashMap<UUID, Segment>());
+    private final ConcurrentMap<String, RecordId> journals =
+            Maps.newConcurrentMap();
 
-    private RecordId head;
+    private final ConcurrentMap<UUID, Segment> segments =
+            Maps.newConcurrentMap();
 
-    public MemoryStore() {
+    public MemoryStore(NodeState root) {
         SegmentWriter writer = new SegmentWriter(this);
-        this.head = writer.writeNode(MemoryNodeState.EMPTY_NODE);
+        journals.put("root", writer.writeNode(root));
         writer.flush();
     }
 
-    @Override
-    public synchronized RecordId getJournalHead() {
-        return head;
+    public MemoryStore() {
+        this(MemoryNodeState.EMPTY_NODE);
     }
 
     @Override
-    public synchronized boolean setJournalHead(RecordId head, RecordId base) {
-        if (this.head.equals(base)) {
-            this.head = head;
-            return true;
+    public RecordId getJournalHead(String name) {
+        RecordId head = journals.get(name);
+        if (head != null) {
+            return head;
         } else {
-            return false;
+            throw new IllegalArgumentException("Journal not found: " + name);
         }
     }
 
     @Override
-    public Segment readSegment(UUID segmentId) {
-        Segment segment = segments.get(segmentId);
+    public boolean setJournalHead(String name, RecordId head, RecordId base) {
+        return journals.replace(name, base, head);
+    }
+
+    @Override
+    public Segment readSegment(UUID id) {
+        Segment segment = segments.get(id);
         if (segment != null) {
             return segment;
         } else {
-            throw new IllegalStateException("Segment not found: " + segmentId);
+            throw new IllegalArgumentException("Segment not found: " + id);
         }
     }
 

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=1448545&r1=1448544&r2=1448545&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
Thu Feb 21 08:37:20 2013
@@ -44,14 +44,13 @@ public class MongoStore implements Segme
 
         this.cache = cache;
 
-        SegmentWriter writer = new SegmentWriter(this);
-        RecordId id = writer.writeNode(MemoryNodeState.EMPTY_NODE);
-        writer.flush();
-        journals.update(
-                new BasicDBObject("_id", "root"),
-                new BasicDBObject(ImmutableMap.of(
-                        "_id", "root", "head", id.toString())),
-                true /* upsert */, false);
+        if (journals.findOne(new BasicDBObject("_id", "root")) == null) {
+            SegmentWriter writer = new SegmentWriter(this);
+            RecordId id = writer.writeNode(MemoryNodeState.EMPTY_NODE);
+            writer.flush();
+            journals.insert(new BasicDBObject(ImmutableMap.of(
+                    "_id", "root", "head", id.toString())));
+        }
     }
 
     public MongoStore(DB db) {
@@ -64,17 +63,17 @@ public class MongoStore implements Segme
     }
 
     @Override
-    public RecordId getJournalHead() {
-        DBObject journal = journals.findOne(new BasicDBObject("_id", "root"));
+    public RecordId getJournalHead(String name) {
+        DBObject journal = journals.findOne(new BasicDBObject("_id", name));
         return RecordId.fromString(journal.get("head").toString());
     }
 
     @Override
-    public boolean setJournalHead(RecordId head, RecordId base) {
+    public boolean setJournalHead(String name, RecordId head, RecordId base) {
         DBObject baseObject = new BasicDBObject(
-                ImmutableMap.of("_id", "root", "head", base.toString()));
+                ImmutableMap.of("_id", name, "head", base.toString()));
         DBObject headObject = new BasicDBObject(
-                ImmutableMap.of("_id", "root", "head", head.toString()));
+                ImmutableMap.of("_id", name, "head", head.toString()));
         return journals.findAndModify(baseObject, headObject) != null;
     }
 

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=1448545&r1=1448544&r2=1448545&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
Thu Feb 21 08:37:20 2013
@@ -30,21 +30,28 @@ public class SegmentNodeStore implements
 
     private final SegmentStore store;
 
+    private final String journal;
+
     private final SegmentReader reader;
 
-    public SegmentNodeStore(SegmentStore store) {
+    public SegmentNodeStore(SegmentStore store, String journal) {
         this.store = store;
+        this.journal = journal;
         this.reader = new SegmentReader(store);
     }
 
+    public SegmentNodeStore(SegmentStore store) {
+        this(store, "root");
+    }
+
     @Override @Nonnull
     public NodeState getRoot() {
-        return new SegmentNodeState(reader, store.getJournalHead());
+        return new SegmentNodeState(reader, store.getJournalHead(journal));
     }
 
     @Override @Nonnull
     public NodeStoreBranch branch() {
-        return new SegmentNodeStoreBranch(store, reader);
+        return new SegmentNodeStoreBranch(store, journal, reader);
     }
 
     @Override

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=1448545&r1=1448544&r2=1448545&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
Thu Feb 21 08:37:20 2013
@@ -43,6 +43,8 @@ class SegmentNodeStoreBranch implements 
 
     private final SegmentStore store;
 
+    private final String journal;
+
     private final SegmentReader reader;
 
     private final SegmentWriter writer;
@@ -51,11 +53,12 @@ class SegmentNodeStoreBranch implements 
 
     private RecordId rootId;
 
-    SegmentNodeStoreBranch(SegmentStore store, SegmentReader reader) {
+    SegmentNodeStoreBranch(SegmentStore store, String journal, SegmentReader reader) {
         this.store = store;
+        this.journal = journal;
         this.reader = reader;
         this.writer = new SegmentWriter(store);
-        this.baseId = store.getJournalHead();
+        this.baseId = store.getJournalHead(journal);
         this.rootId = baseId;
     }
 
@@ -157,7 +160,7 @@ class SegmentNodeStoreBranch implements 
 
     @Override
     public synchronized void rebase() {
-        RecordId newBaseId = store.getJournalHead();
+        RecordId newBaseId = store.getJournalHead(journal);
         if (!baseId.equals(newBaseId)) {
             NodeBuilder builder =
                     new MemoryNodeBuilder(new SegmentNodeState(reader, newBaseId));
@@ -178,7 +181,7 @@ class SegmentNodeStoreBranch implements 
             RecordId headId =
                     writer.writeNode(hook.processCommit(getBase(), getRoot()));
             writer.flush();
-            if (store.setJournalHead(headId, baseId)) {
+            if (store.setJournalHead(journal, headId, baseId)) {
                 baseId = headId;
                 rootId = headId;
                 return getRoot();

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=1448545&r1=1448544&r2=1448545&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
Thu Feb 21 08:37:20 2013
@@ -20,9 +20,9 @@ import java.util.UUID;
 
 public interface SegmentStore {
 
-    RecordId getJournalHead();
+    RecordId getJournalHead(String name);
 
-    boolean setJournalHead(RecordId head, RecordId base);
+    boolean setJournalHead(String name, RecordId head, RecordId base);
 
     Segment readSegment(UUID segmentId);
 



Mime
View raw message