jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1537079 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk: CommitDiff.java MongoNodeStoreBranch.java
Date Wed, 30 Oct 2013 13:19:24 GMT
Author: mreutegg
Date: Wed Oct 30 13:19:23 2013
New Revision: 1537079

URL: http://svn.apache.org/r1537079
Log:
OAK-1080: MongoMK: improved concurrency

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/CommitDiff.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreBranch.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/CommitDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/CommitDiff.java?rev=1537079&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/CommitDiff.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/CommitDiff.java
Wed Oct 30 13:19:23 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.mongomk;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Implementation of a {@link NodeStateDiff}, which translates the diffs into
+ * {@link UpdateOp}s of a commit.
+ */
+class CommitDiff implements NodeStateDiff {
+
+    private final Commit commit;
+
+    CommitDiff(@Nonnull Commit commit) {
+        this.commit = checkNotNull(commit);
+    }
+
+    @Override
+    public boolean propertyAdded(PropertyState after) {
+        // TODO: implement
+        return false;
+    }
+
+    @Override
+    public boolean propertyChanged(PropertyState before, PropertyState after) {
+        // TODO: implement
+        return false;
+    }
+
+    @Override
+    public boolean propertyDeleted(PropertyState before) {
+        // TODO: implement
+        return false;
+    }
+
+    @Override
+    public boolean childNodeAdded(String name, NodeState after) {
+        // TODO: implement
+        return false;
+    }
+
+    @Override
+    public boolean childNodeChanged(String name,
+                                    NodeState before,
+                                    NodeState after) {
+        // TODO: implement
+        return false;
+    }
+
+    @Override
+    public boolean childNodeDeleted(String name, NodeState before) {
+        // TODO: implement
+        return false;
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/CommitDiff.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/CommitDiff.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreBranch.java?rev=1537079&r1=1537078&r2=1537079&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreBranch.java
Wed Oct 30 13:19:23 2013
@@ -53,41 +53,55 @@ public class MongoNodeStoreBranch
     }
 
     @Override
-    protected MongoNodeState persist(NodeState toPersist, MongoNodeState base) {
-        // TODO
-        return null;
+    protected MongoNodeState persist(final NodeState toPersist,
+                                     final MongoNodeState base) {
+        return persist(new Changes() {
+            @Override
+            public void with(Commit c) {
+                toPersist.compareAgainstBaseState(base, new CommitDiff(c));
+            }
+        }, base);
     }
 
     @Override
-    protected MongoNodeState copy(String source,
-                                  String target,
+    protected MongoNodeState copy(final String source,
+                                  final String target,
                                   MongoNodeState base) {
-        boolean success = false;
-        Commit c = store.newCommit(base.getRevision());
-        Revision rev;
-        try {
-            store.copyNode(source, target, c);
-            rev = store.apply(c);
-            success = true;
-        } finally {
-            if (success) {
-                store.done(c, base.getRevision().isBranch());
-            } else {
-                store.canceled(c);
+        return persist(new Changes() {
+            @Override
+            public void with(Commit c) {
+                store.copyNode(source, target, c);
             }
-        }
-        return store.getRoot(rev);
+        }, base);
     }
 
     @Override
-    protected MongoNodeState move(String source,
-                                  String target,
+    protected MongoNodeState move(final String source,
+                                  final String target,
                                   MongoNodeState base) {
+        return persist(new Changes() {
+            @Override
+            public void with(Commit c) {
+                store.moveNode(source, target, c);
+            }
+        }, base);
+    }
+
+    //------------------------------< internal >--------------------------------
+
+    /**
+     * Persist some changes on top of the given base state.
+     *
+     * @param op the changes to persist.
+     * @param base the base state.
+     * @return the result state.
+     */
+    private MongoNodeState persist(Changes op, MongoNodeState base) {
         boolean success = false;
         Commit c = store.newCommit(base.getRevision());
         Revision rev;
         try {
-            store.moveNode(source, target, c);
+            op.with(c);
             rev = store.apply(c);
             success = true;
         } finally {
@@ -99,4 +113,9 @@ public class MongoNodeStoreBranch
         }
         return store.getRoot(rev);
     }
+
+    private interface Changes {
+
+        void with(Commit c);
+    }
 }



Mime
View raw message