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 md...@apache.org on 2013/09/20 16:27:33 UTC
svn commit: r1525016 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
core/ kernel/ plugins/memory/
Author: mduerig
Date: Fri Sep 20 14:27:33 2013
New Revision: 1525016
URL: http://svn.apache.org/r1525016
Log:
OAK-659 Move purge logic for transient changes below the NodeBuilder interface
Avoid falling back to MemoryNodeBuilder.moveTo/copyTo in case the newParent is SecureNodeBuilder
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java?rev=1525016&r1=1525015&r2=1525016&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java Fri Sep 20 14:27:33 2013
@@ -391,7 +391,6 @@ public class MutableTree extends Abstrac
boolean moveTo(MutableTree newParent, String newName) {
name = newName;
parent = newParent;
- // FIXME this falls back to MemoryNodeBuilder#moveTo if newParent is a SecureNodeState
return nodeBuilder.moveTo(newParent.nodeBuilder, newName);
}
@@ -402,7 +401,6 @@ public class MutableTree extends Abstrac
* @param newName new name for this tree
*/
boolean copyTo(MutableTree newParent, String newName) {
- // FIXME this falls back to MemoryNodeBuilder#copyTo if newParent is a SecureNodeState
return nodeBuilder.copyTo(newParent.nodeBuilder, newName);
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java?rev=1525016&r1=1525015&r2=1525016&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java Fri Sep 20 14:27:33 2013
@@ -35,13 +35,15 @@ import com.google.common.base.Predicate;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.kernel.FastCopyMove;
+import org.apache.jackrabbit.oak.kernel.KernelNodeBuilder;
import org.apache.jackrabbit.oak.spi.security.Context;
import org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.oak.util.LazyValue;
-class SecureNodeBuilder implements NodeBuilder {
+class SecureNodeBuilder implements NodeBuilder, FastCopyMove {
/**
* Root builder, or {@code this} for the root builder itself.
@@ -323,6 +325,30 @@ class SecureNodeBuilder implements NodeB
}
/**
+ * This implementation simply delegates back to {@code moveTo} method
+ * of {@code source} passing the underlying builder for {@code newParent}.
+ * @param source source to move to this builder
+ * @param newName the new name
+ * @return
+ */
+ @Override
+ public boolean moveFrom(KernelNodeBuilder source, String newName) {
+ return source.moveTo(builder, newName);
+ }
+
+ /**
+ * This implementation simply delegates back to {@code copyTo} method
+ * of {@code source} passing the underlying builder for {@code newParent}.
+ * @param source source to move to this builder
+ * @param newName the new name
+ * @return
+ */
+ @Override
+ public boolean copyFrom(KernelNodeBuilder source, String newName) {
+ return source.copyTo(builder, newName);
+ }
+
+ /**
* Security context of this subtree. This accessor memoises the security context
* as long as {@link #reset(NodeState)} has not been called.
*/
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java?rev=1525016&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/FastCopyMove.java Fri Sep 20 14:27:33 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.kernel;
+
+/**
+ * This interface is intended to be implemented by
+ * {@link org.apache.jackrabbit.oak.spi.state.NodeBuilder} implementations to indicate
+ * support for optimised move and copy operations.
+ */
+public interface FastCopyMove {
+
+ /**
+ * Move the {@code source} builder to this builder with the
+ * given new name
+ * @param source source to move to this builder
+ * @param newName the new name
+ * @return {@code true} on success, {@code false} otherwise
+ */
+ boolean moveFrom(KernelNodeBuilder source, String newName);
+
+ /**
+ * Copy the {@code source} builder to this builder with the
+ * given new name
+ * @param source source to copy to this builder
+ * @param newName the new name
+ * @return {@code true} on success, {@code false} otherwise
+ */
+ boolean copyFrom(KernelNodeBuilder source, String newName);
+}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java?rev=1525016&r1=1525015&r2=1525016&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java Fri Sep 20 14:27:33 2013
@@ -28,7 +28,7 @@ import org.apache.jackrabbit.oak.spi.sta
* them to the underlying store if possible.
* @see KernelRootBuilder
*/
-public class KernelNodeBuilder extends MemoryNodeBuilder {
+public class KernelNodeBuilder extends MemoryNodeBuilder implements FastCopyMove {
private final KernelRootBuilder root;
@@ -65,10 +65,8 @@ public class KernelNodeBuilder extends M
*/
@Override
public boolean moveTo(NodeBuilder newParent, String newName) {
- if (newParent instanceof KernelNodeBuilder) {
- String source = getPath();
- String target = PathUtils.concat(((KernelNodeBuilder) newParent).getPath(), checkNotNull(newName));
- return root.move(source, target);
+ if (newParent instanceof FastCopyMove) {
+ return ((FastCopyMove) newParent).moveFrom(this, newName);
} else {
return super.moveTo(newParent, newName);
}
@@ -84,12 +82,25 @@ public class KernelNodeBuilder extends M
*/
@Override
public boolean copyTo(NodeBuilder newParent, String newName) {
- if (newParent instanceof KernelNodeBuilder) {
- String source = getPath();
- String target = PathUtils.concat(((KernelNodeBuilder) newParent).getPath(), checkNotNull(newName));
- return root.copy(source, target);
+ if (newParent instanceof FastCopyMove) {
+ return ((FastCopyMove) newParent).copyFrom(this, newName);
} else {
return super.copyTo(newParent, newName);
}
}
+
+ @Override
+ public boolean moveFrom(KernelNodeBuilder source, String newName) {
+ String sourcePath = source.getPath();
+ String destPath = PathUtils.concat(getPath(), newName);
+ return root.move(sourcePath, destPath);
+ }
+
+ @Override
+ public boolean copyFrom(KernelNodeBuilder source, String newName) {
+ String sourcePath = source.getPath();
+ String destPath = PathUtils.concat(getPath(), newName);
+ return root.copy(sourcePath, destPath);
+ }
+
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java?rev=1525016&r1=1525015&r2=1525016&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java Fri Sep 20 14:27:33 2013
@@ -30,7 +30,7 @@ import org.apache.jackrabbit.oak.spi.sta
* This implementation tracks the number of pending changes and purges them to
* a private branch of the underlying store if a certain threshold is met.
*/
-class KernelRootBuilder extends MemoryNodeBuilder {
+class KernelRootBuilder extends MemoryNodeBuilder implements FastCopyMove {
/**
* Number of content updates that need to happen before the updates
@@ -94,6 +94,18 @@ class KernelRootBuilder extends MemoryNo
}
}
+ @Override
+ public boolean moveFrom(KernelNodeBuilder source, String newName) {
+ String sourcePath = source.getPath();
+ return move(sourcePath, '/' + newName);
+ }
+
+ @Override
+ public boolean copyFrom(KernelNodeBuilder source, String newName) {
+ String sourcePath = source.getPath();
+ return copy(sourcePath, '/' + newName);
+ }
+
//------------------------------------------------------------< internal >---
/**
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1525016&r1=1525015&r2=1525016&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java Fri Sep 20 14:27:33 2013
@@ -417,7 +417,7 @@ public class MemoryNodeBuilder implement
/**
* @return path of this builder.
*/
- protected final String getPath() {
+ public final String getPath() {
return parent == null ? "/" : getPath(new StringBuilder()).toString();
}