You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2013/03/07 11:11:14 UTC

svn commit: r1453758 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: MemoryJournal.java MemoryStore.java

Author: jukka
Date: Thu Mar  7 10:11:13 2013
New Revision: 1453758

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

Extract MemoryJournal to a separate file

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryJournal.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryStore.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryJournal.java?rev=1453758&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryJournal.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MemoryJournal.java Thu Mar  7 10:11:13 2013
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.segment;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.RebaseDiff;
+
+final class MemoryJournal implements Journal {
+
+    private final SegmentStore store;
+
+    private final Journal parent;
+
+    private RecordId base;
+
+    private RecordId head;
+
+    MemoryJournal(SegmentStore store, NodeState root) {
+        this.store = checkNotNull(store);
+        this.parent = null;
+
+        SegmentWriter writer = new SegmentWriter(store);
+        RecordId id = writer.writeNode(root).getRecordId();
+        writer.flush();
+
+        this.base = id;
+        this.head = id;
+    }
+
+    MemoryJournal(SegmentStore store, String parent) {
+        this.store = checkNotNull(store);
+        this.parent = store.getJournal(checkNotNull(parent));
+        this.base = this.parent.getHead();
+        this.head = base;
+    }
+
+    @Override
+    public synchronized RecordId getHead() {
+        return head;
+    }
+
+    @Override
+    public synchronized boolean setHead(RecordId base, RecordId head) {
+        if (checkNotNull(base).equals(this.head)) {
+            this.head = checkNotNull(head);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public synchronized void merge() {
+        if (parent != null) {
+            NodeState before = new SegmentNodeState(store, base);
+            NodeState after = new SegmentNodeState(store, head);
+
+            SegmentWriter writer = new SegmentWriter(store);
+            while (!parent.setHead(base, head)) {
+                RecordId newBase = parent.getHead();
+                NodeBuilder builder =
+                        new SegmentNodeState(store, newBase).builder();
+                after.compareAgainstBaseState(
+                        before, new RebaseDiff(builder));
+                NodeState state = builder.getNodeState();
+                RecordId newHead = writer.writeNode(state).getRecordId();
+                writer.flush();
+
+                base = newBase;
+                head = newHead;
+            }
+
+            base = head;
+        }
+    }
+
+}

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=1453758&r1=1453757&r2=1453758&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 Mar  7 10:11:13 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
-import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.util.Collections;
 import java.util.Map;
@@ -24,85 +23,12 @@ import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.RebaseDiff;
 
 import com.google.common.collect.Maps;
 
 public class MemoryStore implements SegmentStore {
 
-    private static final class MemoryJournal implements Journal {
-
-        private final SegmentStore store;
-
-        private final Journal parent;
-
-        private RecordId base;
-
-        private RecordId head;
-
-        MemoryJournal(SegmentStore store, NodeState root) {
-            this.store = checkNotNull(store);
-            this.parent = null;
-
-            SegmentWriter writer = new SegmentWriter(store);
-            RecordId id = writer.writeNode(root).getRecordId();
-            writer.flush();
-
-            this.base = id;
-            this.head = id;
-        }
-
-        MemoryJournal(SegmentStore store, String parent) {
-            this.store = checkNotNull(store);
-            this.parent = store.getJournal(checkNotNull(parent));
-            this.base = this.parent.getHead();
-            this.head = base;
-        }
-
-        @Override
-        public synchronized RecordId getHead() {
-            return head;
-        }
-
-        @Override
-        public synchronized boolean setHead(RecordId base, RecordId head) {
-            if (checkNotNull(base).equals(this.head)) {
-                this.head = checkNotNull(head);
-                return true;
-            } else {
-                return false;
-            }
-        }
-
-        @Override
-        public synchronized void merge() {
-            if (parent != null) {
-                NodeState before = new SegmentNodeState(store, base);
-                NodeState after = new SegmentNodeState(store, head);
-
-                SegmentWriter writer = new SegmentWriter(store);
-                while (!parent.setHead(base, head)) {
-                    RecordId newBase = parent.getHead();
-                    NodeBuilder builder =
-                            new SegmentNodeState(store, newBase).builder();
-                    after.compareAgainstBaseState(
-                            before, new RebaseDiff(builder));
-                    NodeState state = builder.getNodeState();
-                    RecordId newHead = writer.writeNode(state).getRecordId();
-                    writer.flush();
-
-                    base = newBase;
-                    head = newHead;
-                }
-
-                base = head;
-            }
-        }
-
-    }
-
     private final Map<String, Journal> journals = Maps.newHashMap();
 
     private final ConcurrentMap<UUID, Segment> segments =