Author: mduerig
Date: Thu Aug 15 14:14:18 2013
New Revision: 1514283
URL: http://svn.apache.org/r1514283
Log:
OAK-659 Move purge logic for transient changes below the NodeBuilder interface
revert changes from revisions 1513469, 1513503, 1513767, 1513791, 1513891,
1513924, 1514190, 1514191, 1514206, 1514217
Removed:
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/segment/SegmentNodeBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentRootBuilder.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
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/KernelNodeState.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.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/spi/state/AbstractNodeStore.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
jackrabbit/oak/trunk/oak-parent/pom.xml
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
Thu Aug 15 14:14:18 2013
@@ -18,11 +18,6 @@
*/
package org.apache.jackrabbit.oak.core;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
-import static org.apache.jackrabbit.oak.commons.PathUtils.isAncestor;
-
import java.io.IOException;
import java.io.InputStream;
import java.security.PrivilegedAction;
@@ -61,9 +56,18 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
import org.apache.jackrabbit.oak.util.LazyValue;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
+
public abstract class AbstractRoot implements Root {
/**
+ * Number of {@link #updated} calls for which changes are kept in memory.
+ */
+ private static final int PURGE_LIMIT =
Integer.getInteger("oak.root.purgeLimit", 1000);
+
+ /**
* The underlying store to which this root belongs
*/
private final NodeStore store;
@@ -86,19 +90,14 @@ public abstract class AbstractRoot imple
private final MutableTree rootTree;
/**
- * Unsecured builder for the root tree
- */
- private final NodeBuilder builder;
-
- /**
* Secured builder for the root tree
*/
private final SecureNodeBuilder secureBuilder;
/**
- * Base state of the root tree
+ * Unsecured builder for the root tree
*/
- private NodeState base;
+ private final NodeBuilder builder;
/**
* Current branch this root operates on
@@ -111,7 +110,8 @@ public abstract class AbstractRoot imple
private Move lastMove = new Move();
/**
- * Number of {@link #updated} occurred.
+ * Number of {@link #updated} occurred so since the last
+ * purge.
*/
private long modCount;
@@ -147,8 +147,9 @@ public abstract class AbstractRoot imple
this.securityProvider = checkNotNull(securityProvider);
this.indexProvider = indexProvider;
- base = store.getRoot();
- builder = base.builder();
+ branch = this.store.branch();
+ NodeState root = branch.getHead();
+ builder = root.builder();
secureBuilder = new SecureNodeBuilder(builder, permissionProvider,
getAcContext());
rootTree = new MutableTree(this, secureBuilder, lastMove);
}
@@ -168,27 +169,22 @@ public abstract class AbstractRoot imple
@Override
public boolean move(String sourcePath, String destPath) {
- if (isAncestor(sourcePath, destPath)) {
+ if (PathUtils.isAncestor(sourcePath, destPath)) {
return false;
}
checkLive();
- MutableTree source = rootTree.getTree(sourcePath);
- if (!source.exists()) {
+ MutableTree destParent = rootTree.getTree(getParentPath(destPath));
+ if (!destParent.exists()) {
return false;
}
-
- String newName = getName(destPath);
- MutableTree newParent = rootTree.getTree(getParentPath(destPath));
- if (!newParent.exists() || newParent.hasChild(newName)) {
- return false;
- }
-
- boolean success = source.moveTo(newParent, newName);
+ purgePendingChanges();
+ boolean success = branch.move(sourcePath, destPath);
+ reset();
if (success) {
getTree(getParentPath(sourcePath)).updateChildOrder();
getTree(getParentPath(destPath)).updateChildOrder();
- lastMove = lastMove.setMove(sourcePath, newParent, newName);
+ lastMove = lastMove.setMove(sourcePath, destParent,
getName(destPath));
updated();
}
return success;
@@ -197,18 +193,9 @@ public abstract class AbstractRoot imple
@Override
public boolean copy(String sourcePath, String destPath) {
checkLive();
- MutableTree source = rootTree.getTree(sourcePath);
- if (!source.exists()) {
- return false;
- }
-
- String newName = getName(destPath);
- MutableTree newParent = rootTree.getTree(getParentPath(destPath));
- if (!newParent.exists() || newParent.hasChild(newName)) {
- return false;
- }
-
- boolean success = source.copyTo(newParent, newName);
+ purgePendingChanges();
+ boolean success = branch.copy(sourcePath, destPath);
+ reset();
if (success) {
getTree(getParentPath(destPath)).updateChildOrder();
updated();
@@ -226,7 +213,9 @@ public abstract class AbstractRoot imple
public void rebase() {
checkLive();
if (!store.getRoot().equals(getBaseState())) {
- secureBuilder.reset(store.rebase(builder));
+ purgePendingChanges();
+ branch.rebase();
+ reset();
if (permissionProvider != null) {
permissionProvider.get().refresh();
}
@@ -236,8 +225,8 @@ public abstract class AbstractRoot imple
@Override
public final void refresh() {
checkLive();
- base = store.reset(builder);
- secureBuilder.reset(base);
+ branch = store.branch();
+ reset();
modCount = 0;
if (permissionProvider != null) {
permissionProvider.get().refresh();
@@ -247,17 +236,13 @@ public abstract class AbstractRoot imple
@Override
public void commit() throws CommitFailedException {
checkLive();
+ purgePendingChanges();
CommitFailedException exception = Subject.doAs(
getCommitSubject(), new
PrivilegedAction<CommitFailedException>() {
@Override
public CommitFailedException run() {
try {
- base = store.merge(builder, getCommitHook(), postHook);
- secureBuilder.reset(base);
- modCount = 0;
- if (permissionProvider != null) {
- permissionProvider.get().refresh();
- }
+ branch.merge(getCommitHook(), postHook);
return null;
} catch (CommitFailedException e) {
return e;
@@ -267,6 +252,7 @@ public abstract class AbstractRoot imple
if (exception != null) {
throw exception;
}
+ refresh();
}
/**
@@ -365,7 +351,7 @@ public abstract class AbstractRoot imple
*/
@Nonnull
NodeState getBaseState() {
- return base;
+ return branch.getBase();
}
/**
@@ -374,11 +360,15 @@ public abstract class AbstractRoot imple
* @return secure base node state
*/
NodeState getSecureBase() {
- return new SecureNodeState(base, permissionProvider.get(),
getAcContext());
+ NodeState root = branch.getBase();
+ return new SecureNodeState(root, permissionProvider.get(),
getAcContext());
}
+ // TODO better way to determine purge limit. See OAK-175
void updated() {
- modCount++;
+ if (++modCount % PURGE_LIMIT == 0) {
+ purgePendingChanges();
+ }
}
//------------------------------------------------------------< private
>---
@@ -394,6 +384,22 @@ public abstract class AbstractRoot imple
return builder.getNodeState();
}
+ /**
+ * Purge all pending changes to the underlying {@link NodeStoreBranch}.
+ */
+ private void purgePendingChanges() {
+ branch.setRoot(getRootState());
+ reset();
+ }
+
+ /**
+ * Reset the root builder to the branch's current root state
+ */
+ private void reset() {
+ NodeState root = branch.getHead();
+ secureBuilder.reset(root);
+ }
+
@Nonnull
private Context getAcContext() {
return getAcConfig().getContext();
@@ -456,7 +462,7 @@ public abstract class AbstractRoot imple
Move move = this;
while (move.next != null) {
if (move.source.equals(tree.getPathInternal())) {
- tree.setParentAndName(move.destParent, move.destName);
+ tree.moveTo(move.destParent, move.destName);
}
move = move.next;
}
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=1514283&r1=1514282&r2=1514283&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
Thu Aug 15 14:14:18 2013
@@ -371,37 +371,14 @@ public class MutableTree extends Abstrac
//-----------------------------------------------------------< internal
>---
/**
- * Set the parent and name of this tree.
- * @param parent parent of this tree
- * @param name name of this tree
- */
- void setParentAndName(MutableTree parent, String name) {
- this.name = name;
- this.parent = parent;
- }
-
- /**
* Move this tree to the parent at {@code destParent} with the new name
- * {@code newName}.
- * @param newParent new parent for this tree
- * @param newName new name for this tree
- */
- 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);
- }
-
- /**
- * Copy this tree to the parent at {@code destParent} with the new name
- * {@code newName}.
- * @param newParent new parent for this tree
- * @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);
+ * {@code destName}.
+ * @param destParent new parent for this tree
+ * @param destName new name for this tree
+ */
+ void moveTo(MutableTree destParent, String destName) {
+ name = destName;
+ parent = destParent;
}
/**
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=1514283&r1=1514282&r2=1514283&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
Thu Aug 15 14:14:18 2013
@@ -150,17 +150,6 @@ class SecureNodeBuilder implements NodeB
return exists() && builder.remove();
}
-
- @Override
- public boolean moveTo(NodeBuilder newParent, String newName) {
- return exists() && builder.moveTo(newParent, newName);
- }
-
- @Override
- public boolean copyTo(NodeBuilder newParent, String newName) {
- return exists() && builder.copyTo(newParent, newName);
- }
-
@Override @CheckForNull
public PropertyState getProperty(String name) {
PropertyState property = builder.getProperty(name);
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Thu Aug 15 14:14:18 2013
@@ -24,6 +24,9 @@ import static org.apache.jackrabbit.oak.
import static
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
import static
org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -97,9 +100,15 @@ public final class KernelNodeState exten
* path and revision. This object is only used internally and never leaves
* this {@link KernelNodeState}.
*/
- private static final KernelNodeState NULL = new KernelNodeState();
-
- private final KernelNodeStore store;
+ private static final KernelNodeState NULL = new KernelNodeState(
+ (MicroKernel)
Proxy.newProxyInstance(MicroKernel.class.getClassLoader(),
+ new Class[]{MicroKernel.class}, new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ throw new UnsupportedOperationException();
+ }
+ }), "null", "null", DUMMY_CACHE);
private final MicroKernel kernel;
@@ -119,15 +128,6 @@ public final class KernelNodeState exten
private Set<String> childNames;
- /**
- * {@code true} is this is a node state from a branch. {@code false}
- * otherwise.
- * <p>
- * TODO: this is a workaround to avoid creating branches from a branch
- * until this is supported by the MicroKernel. See {@link
KernelNodeState#builder()}.
- */
- private boolean isBranch;
-
private final LoadingCache<String, KernelNodeState> cache;
/**
@@ -135,29 +135,20 @@ public final class KernelNodeState exten
* given {@code path} and {@code revision}. It is an error if the
* underlying Microkernel does not contain such a node.
*
- * @param store the underlying KernelNodeStore
+ * @param kernel the underlying MicroKernel
* @param path the path of this KernelNodeState
* @param revision the revision of the node to read from the kernel.
* @param cache the KernelNodeState cache
*/
public KernelNodeState(
- KernelNodeStore store, String path, String revision,
+ MicroKernel kernel, String path, String revision,
LoadingCache<String, KernelNodeState> cache) {
- this.store = store;
- this.kernel = store.getKernel();
+ this.kernel = checkNotNull(kernel);
this.path = checkNotNull(path);
this.revision = checkNotNull(revision);
this.cache = checkNotNull(cache);
}
- private KernelNodeState() {
- this.store = null;
- this.kernel = null;
- this.path = "null";
- this.revision = "null";
- this.cache = DUMMY_CACHE;
- }
-
private void init() {
boolean initialized = false;
synchronized (this) {
@@ -426,23 +417,9 @@ public final class KernelNodeState exten
};
}
- /**
- * This implementation returns a {@link KernelNodeBuilder} unless this is
not
- * a root node or {@link #isBranch} is {@code true} in which case a
- * {@link MemoryNodeBuilder} is returned.
- * <p>
- * TODO: this is a workaround to avoid creating branches from a branch
- * until this is supported by the MicroKernel.
- */
@Override
public NodeBuilder builder() {
- if (isBranch) {
- return new MemoryNodeBuilder(this);
- } else if ("/".equals(path)) {
- return new KernelRootBuilder(this, store);
- } else {
- return new MemoryNodeBuilder(this);
- }
+ return new MemoryNodeBuilder(this);
}
/**
@@ -539,18 +516,6 @@ public final class KernelNodeState exten
}
/**
- * Mark this instance as from being on branch.
- * <p>
- * TODO this is a workaround to avoid creating branches from a branch
- * until this is supported by the MicroKernel. See {@link
KernelNodeState#builder()}.
- * @return {@code this}
- */
- NodeState setBranch() {
- isBranch = true;
- return this;
- }
-
- /**
* @return the approximate memory usage of this node state.
*/
synchronized int getMemory() {
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Thu Aug 15 14:14:18 2013
@@ -37,13 +37,9 @@ import com.google.common.util.concurrent
import org.apache.jackrabbit.mk.api.MicroKernel;
import org.apache.jackrabbit.mk.api.MicroKernelException;
import org.apache.jackrabbit.oak.cache.CacheStats;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.EmptyObserver;
import org.apache.jackrabbit.oak.spi.commit.Observer;
-import org.apache.jackrabbit.oak.spi.commit.PostCommitHook;
import org.apache.jackrabbit.oak.spi.state.AbstractNodeStore;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
@@ -98,7 +94,7 @@ public class KernelNodeStore extends Abs
int slash = key.indexOf('/');
String revision = key.substring(0, slash);
String path = key.substring(slash);
- return new KernelNodeState(KernelNodeStore.this, path,
revision, cache);
+ return new KernelNodeState(kernel, path, revision,
cache);
}
@Override
@@ -148,53 +144,6 @@ public class KernelNodeStore extends Abs
return root;
}
- /**
- * This implementation delegates to {@link
KernelRootBuilder#merge(CommitHook, PostCommitHook)}
- * if {@code builder} is a {@link KernelNodeBuilder} instance. Otherwise
it falls
- * back to the default implementation of its super class.
- */
- @Override
- public NodeState merge(@Nonnull NodeBuilder builder, @Nonnull CommitHook
commitHook,
- PostCommitHook committed) throws CommitFailedException {
- if (builder instanceof KernelRootBuilder) {
- return ((KernelRootBuilder) builder).merge(commitHook, committed);
- } else {
- return super.merge(builder, commitHook, committed);
- }
- }
-
- /**
- * This implementation delegates to {@link KernelRootBuilder#rebase()} if
{@code builder}
- * is a {@link KernelNodeBuilder} instance. Otherwise it falls back to the
default
- * implementation of its super class.
- * @param builder the builder to rebase
- * @return
- */
- @Override
- public NodeState rebase(@Nonnull NodeBuilder builder) {
- if (builder instanceof KernelRootBuilder) {
- return ((KernelRootBuilder) builder).rebase();
- } else {
- return super.rebase(builder);
- }
- }
-
- /**
- * This implementation delegates to {@link KernelRootBuilder#reset()} if
{@code builder}
- * is a {@link KernelNodeBuilder} instance. Otherwise it falls back to the
default
- * implementation of its super class.
- * @param builder the builder to rebase
- * @return
- */
- @Override
- public NodeState reset(@Nonnull NodeBuilder builder) {
- if (builder instanceof KernelRootBuilder) {
- return ((KernelRootBuilder) builder).reset();
- } else {
- return super.reset(builder);
- }
- }
-
@Override
public NodeStoreBranch branch() {
return new KernelNodeStoreBranch(this, getRoot(), mergeLock);
@@ -252,10 +201,6 @@ public class KernelNodeStore extends Abs
return getRootState(kernel.commit("", jsop, baseRevision, null));
}
- NodeStoreBranch branch(KernelNodeState base) {
- return new KernelNodeStoreBranch(this, base, mergeLock);
- }
-
NodeState merge(String headRevision) {
return getRootState(kernel.merge(headRevision, null));
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Thu Aug 15 14:14:18 2013
@@ -238,7 +238,7 @@ class KernelNodeStoreBranch extends Abst
persistTransientHead();
headRevision = kernel.commit("", jsop, headRevision, null);
- head = store.getRootState(headRevision).setBranch();
+ head = store.getRootState(headRevision);
}
private void persistTransientHead() {
@@ -261,7 +261,7 @@ class KernelNodeStoreBranch extends Abst
}
} else {
// compare against head of branch
- NodeState branchHead =
store.getRootState(headRevision).setBranch();
+ NodeState branchHead = store.getRootState(headRevision);
if (head.equals(branchHead)) {
// nothing to persist
success = true;
@@ -273,7 +273,7 @@ class KernelNodeStoreBranch extends Abst
// if we get here we have something to persist
// and a branch exists
headRevision = kernel.commit("", diff.toString(), headRevision,
null);
- head = store.getRootState(headRevision).setBranch();
+ head = store.getRootState(headRevision);
success = true;
} finally {
// revert to old state if unsuccessful
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=1514283&r1=1514282&r2=1514283&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
Thu Aug 15 14:14:18 2013
@@ -119,7 +119,7 @@ public class MemoryNodeBuilder implement
* @param parent parent builder
* @param name name of this node
*/
- protected MemoryNodeBuilder(MemoryNodeBuilder parent, String name) {
+ private MemoryNodeBuilder(MemoryNodeBuilder parent, String name) {
this.parent = parent;
this.name = name;
this.rootBuilder = parent.rootBuilder;
@@ -189,28 +189,11 @@ public class MemoryNodeBuilder implement
* Called whenever <em>this</em> node is modified, i.e. a property is
* added, changed or removed, or a child node is added or removed. Changes
* inside child nodes or the subtrees below are not reported. The default
- * implementation triggers an {@link #updated()} call on the root builder
- * (unless this is already the root builder), which subclasses can use
- * to capture aggregate update information across the whole tree.
+ * implementation does nothing, but subclasses may override this method
+ * to better track changes.
*/
protected void updated() {
- if (this != rootBuilder) {
- rootBuilder.updated();
- }
- }
-
- /**
- * Accessor for parent builder
- */
- protected final MemoryNodeBuilder getParent() {
- return parent;
- }
-
- /**
- * Accoessor for name
- */
- protected final String getName() {
- return name;
+ // do nothing
}
//--------------------------------------------------------< NodeBuilder
>---
@@ -302,27 +285,6 @@ public class MemoryNodeBuilder implement
}
@Override
- public boolean moveTo(NodeBuilder newParent, String newName) {
- if (isRoot()) {
- return false;
- } else {
- checkNotNull(newParent).setChildNode(checkNotNull(newName),
getNodeState());
- remove();
- return true;
- }
- }
-
- @Override
- public boolean copyTo(NodeBuilder newParent, String newName) {
- if (isRoot()) {
- return false;
- } else {
- checkNotNull(newParent).setChildNode(checkNotNull(newName),
getNodeState());
- return true;
- }
- }
-
- @Override
public long getPropertyCount() {
return head().getCurrentNodeState().getPropertyCount();
}
@@ -409,9 +371,9 @@ public class MemoryNodeBuilder implement
}
/**
- * @return path of this builder.
+ * @return path of this builder. For debugging purposes only
*/
- protected final String getPath() {
+ private String getPath() {
return parent == null ? "/" : getPath(new StringBuilder()).toString();
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
Thu Aug 15 14:14:18 2013
@@ -25,6 +25,7 @@ import javax.annotation.Nonnull;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -33,13 +34,6 @@ import org.apache.jackrabbit.oak.spi.sta
public class SegmentNodeState extends AbstractNodeState {
- static boolean fastEquals(NodeState a, NodeState b) {
- return a instanceof SegmentNodeState
- && b instanceof SegmentNodeState
- && ((SegmentNodeState) a).recordId.equals(
- ((SegmentNodeState) b).recordId);
- }
-
private final SegmentStore store;
private final RecordId recordId;
@@ -131,7 +125,7 @@ public class SegmentNodeState extends Ab
@Override @Nonnull
public NodeBuilder builder() {
- return new SegmentRootBuilder(this);
+ return new MemoryNodeBuilder(this);
}
@Override
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=1514283&r1=1514282&r2=1514283&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 Aug 15 14:14:18 2013
@@ -26,15 +26,11 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.apache.jackrabbit.oak.api.Blob;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.EmptyObserver;
import org.apache.jackrabbit.oak.spi.commit.Observer;
-import org.apache.jackrabbit.oak.spi.commit.PostCommitHook;
import org.apache.jackrabbit.oak.spi.state.AbstractNodeStore;
-import org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
public class SegmentNodeStore extends AbstractNodeStore {
@@ -79,31 +75,6 @@ public class SegmentNodeStore extends Ab
return getHead().getChildNode(ROOT);
}
- @Override
- public NodeState merge(@Nonnull NodeBuilder builder, @Nonnull CommitHook
commitHook, PostCommitHook committed) throws CommitFailedException {
- return super.merge(builder, commitHook, committed); // TODO
implement merge
- }
-
- @Override @Nonnull
- public NodeState rebase(@Nonnull NodeBuilder builder) {
- NodeState oldBase = builder.getBaseState();
- NodeState newBase = getRoot();
- if (!SegmentNodeState.fastEquals(oldBase, newBase)) {
- NodeBuilder newBuilder = newBase.builder();
- builder.getNodeState().compareAgainstBaseState(
- oldBase, new ConflictAnnotatingRebaseDiff(newBuilder));
- builder.reset(newBuilder.getNodeState());
- }
- return builder.getNodeState();
- }
-
- @Override @Nonnull
- public NodeState reset(@Nonnull NodeBuilder builder) {
- NodeState state = getRoot();
- checkNotNull(builder).reset(state);
- return state;
- }
-
@Override @Nonnull
public SegmentNodeStoreBranch branch() {
return new SegmentNodeStoreBranch(
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStore.java
Thu Aug 15 14:14:18 2013
@@ -17,72 +17,12 @@
package org.apache.jackrabbit.oak.spi.state;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import javax.annotation.Nonnull;
-
-import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
-import org.apache.jackrabbit.oak.spi.commit.PostCommitHook;
-
/**
* Abstract base class for {@link NodeStore} implementations.
*/
public abstract class AbstractNodeStore implements NodeStore {
- /**
- * This default implementation is equal to atomically first rebase the
builder
- * and then applying it to a new branch and immediately merging it back.
- *
- * @param builder the builder whose changes to apply
- * @param commitHook the commit hook to apply while merging changes
- * @param committed the pos commit hook
- * @return the node state resulting from the merge.
- * @throws CommitFailedException
- */
- @Override
- public NodeState merge(@Nonnull NodeBuilder builder, @Nonnull CommitHook
commitHook,
- PostCommitHook committed) throws CommitFailedException {
- checkNotNull(builder);
- checkNotNull(commitHook);
- synchronized (this) {
- rebase(builder);
- NodeStoreBranch branch = branch();
- branch.setRoot(builder.getNodeState());
- return branch.merge(commitHook, committed);
- }
- }
-
- /**
- * This default implementation is equal to applying the differences between
- * the builders base state and its head state to a fresh builder on the
- * stores root state using {@link ConflictAnnotatingRebaseDiff} for
resolving
- * conflicts.
- * @param builder the builder to rebase
- * @return the node state resulting from the rebase.
- */
- @Override
- public NodeState rebase(@Nonnull NodeBuilder builder) {
- NodeState head = checkNotNull(builder).getNodeState();
- NodeState base = builder.getBaseState();
- builder.reset(getRoot());
- head.compareAgainstBaseState(base, new
ConflictAnnotatingRebaseDiff(builder));
- return builder.getNodeState();
- }
-
- /**
- * This default implementation is equal resetting the builder to the root
of
- * the store and returning the resulting node state from the builder.
- * @param builder the builder to reset
- * @return the node state resulting from the reset.
- */
- @Override
- public NodeState reset(@Nonnull NodeBuilder builder) {
- builder.reset(getRoot());
- return builder.getNodeState();
- }
-
-//------------------------------------------------------------< Object >--
+ //------------------------------------------------------------< Object >--
/**
* Returns a string representation the head state of this node store.
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
Thu Aug 15 14:14:18 2013
@@ -224,22 +224,6 @@ public interface NodeBuilder {
boolean remove();
/**
- * Move this child to a new parent with a new name.
- * @param newParent builder for the new parent.
- * @param newName name of this child at the new parent
- * @return {@code true} on success, {@code false} otherwise
- */
- boolean moveTo(@Nonnull NodeBuilder newParent, @Nonnull String newName);
-
- /**
- * Copy this child to a new parent with a new name.
- * @param newParent builder for the new parent.
- * @param newName name of this child at the new parent
- * @return {@code true} on success, {@code false} otherwise
- */
- boolean copyTo(@Nonnull NodeBuilder newParent, @Nonnull String newName);
-
- /**
* Returns the current number of properties.
*
* @return number of properties
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
Thu Aug 15 14:14:18 2013
@@ -23,9 +23,6 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.apache.jackrabbit.oak.api.Blob;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
-import org.apache.jackrabbit.oak.spi.commit.PostCommitHook;
/**
* Storage abstraction for trees. At any given point in time the stored
@@ -46,36 +43,6 @@ public interface NodeStore {
NodeState getRoot();
/**
- * Merges the changes from the passed {@code builder} into
- * the store.
- *
- * @param builder the builder whose changes to apply
- * @param commitHook the commit hook to apply while merging changes
- * @param committed the post commit hook
- * @return the node state resulting from the merge.
- * @throws CommitFailedException if the merge failed
- */
- @Nonnull
- NodeState merge(@Nonnull NodeBuilder builder, @Nonnull CommitHook
commitHook,
- PostCommitHook committed) throws CommitFailedException;
-
- /**
- * Rebase the changes in the passed {@code builder} on top of the current
root state.
- * @param builder the builder to rebase
- * @return the node state resulting from the rebase.
- */
- @Nonnull
- NodeState rebase(@Nonnull NodeBuilder builder);
-
- /**
- * Reset the passed {@code builder} by throwing away all its changes and
- * setting its base state to the current root state.
- * @param builder the builder to reset
- * @return the node state resulting from the reset.
- */
- NodeState reset(@Nonnull NodeBuilder builder);
-
- /**
* Creates a new branch of the tree to which transient changes can be
applied.
*
* @return branch
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
Thu Aug 15 14:14:18 2013
@@ -98,16 +98,6 @@ public class ReadOnlyBuilder implements
}
@Override
- public boolean moveTo(NodeBuilder newParent, String newName) {
- throw unsupported();
- }
-
- @Override
- public boolean copyTo(NodeBuilder newParent, String newName) {
- throw unsupported();
- }
-
- @Override
public long getPropertyCount() {
return state.getPropertyCount();
}
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
Thu Aug 15 14:14:18 2013
@@ -30,8 +30,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import javax.annotation.Nonnull;
-
import org.apache.jackrabbit.oak.NodeStoreFixture;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
@@ -324,44 +322,6 @@ public class NodeStoreTest {
}
@Test
- public void merge() throws CommitFailedException {
- NodeStoreBranch branch1 = store.branch();
- NodeBuilder builder1 = branch1.getHead().builder();
-
- NodeStoreBranch branch2 = store.branch();
- NodeBuilder builder2 = branch1.getHead().builder();
-
- builder1.setChildNode("node1");
- branch1.setRoot(builder1.getNodeState());
- builder2.setChildNode("node2");
- branch2.setRoot(builder2.getNodeState());
-
- store.merge(builder1, EmptyHook.INSTANCE, new PostCommitHook() {
- @Override
- public void contentChanged(@Nonnull NodeState before, @Nonnull
NodeState after) {
- assertFalse(before.hasChildNode("node1"));
- assertFalse(before.hasChildNode("node2"));
- assertTrue(after.hasChildNode("node1"));
- assertFalse(after.hasChildNode("node2"));
- }
- });
- assertTrue(store.getRoot().hasChildNode("node1"));
- assertFalse(store.getRoot().hasChildNode("node2"));
-
- store.merge(builder2, EmptyHook.INSTANCE, new PostCommitHook() {
- @Override
- public void contentChanged(@Nonnull NodeState before, @Nonnull
NodeState after) {
- assertTrue(before.hasChildNode("node1"));
- assertFalse(before.hasChildNode("node2"));
- assertTrue(after.hasChildNode("node1"));
- assertTrue(after.hasChildNode("node2"));
- }
- });
- assertTrue(store.getRoot().hasChildNode("node1"));
- assertTrue(store.getRoot().hasChildNode("node2"));
- }
-
- @Test
public void compareAgainstBaseState0() throws CommitFailedException {
compareAgainstBaseState(0);
}
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
Thu Aug 15 14:14:18 2013
@@ -20,28 +20,26 @@ package org.apache.jackrabbit.oak.query.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
import org.apache.jackrabbit.mk.api.MicroKernel;
import org.apache.jackrabbit.mk.core.MicroKernelImpl;
import org.apache.jackrabbit.oak.kernel.KernelNodeState;
-import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
import org.apache.jackrabbit.oak.spi.query.Cursor;
import org.junit.Test;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+
/**
* Tests the TraversingCursor.
*/
public class TraversingIndexTest {
+
private final MicroKernel mk = new MicroKernelImpl();
- private final KernelNodeStore store = new KernelNodeStore(mk);
private final LoadingCache<String, KernelNodeState> cache =
CacheBuilder.newBuilder().build(new CacheLoader<String,
KernelNodeState>() {
@@ -52,10 +50,14 @@ public class TraversingIndexTest {
String path = key.substring(slash);
// this method is strictly called _after_ the cache is
initialized,
// when the fields are set
- return new KernelNodeState(store, path, revision,
getCache());
+ return new KernelNodeState(getMicroKernel(), path,
revision, getCache());
}
});
-
+
+ MicroKernel getMicroKernel() {
+ return mk;
+ }
+
LoadingCache<String, KernelNodeState> getCache() {
return cache;
}
@@ -71,7 +73,7 @@ public class TraversingIndexTest {
f.setPath("/");
List<String> paths = new ArrayList<String>();
- Cursor c = t.query(f, new KernelNodeState(store, "/", head, cache));
+ Cursor c = t.query(f, new KernelNodeState(mk, "/", head, cache));
while (c.hasNext()) {
paths.add(c.next().getPath());
}
@@ -86,7 +88,7 @@ public class TraversingIndexTest {
assertFalse(c.hasNext());
f.setPath("/nowhere");
- c = t.query(f, new KernelNodeState(store, "/", head, cache));
+ c = t.query(f, new KernelNodeState(mk, "/", head, cache));
assertFalse(c.hasNext());
// endure it stays false
assertFalse(c.hasNext());
Modified: jackrabbit/oak/trunk/oak-parent/pom.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-parent/pom.xml?rev=1514283&r1=1514282&r2=1514283&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-parent/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-parent/pom.xml Thu Aug 15 14:14:18 2013
@@ -34,7 +34,7 @@
<packaging>pom</packaging>
<properties>
- <test.opts>-Xmx512m -XX:MaxPermSize=48m -Dupdate.limit=100</test.opts>
+ <test.opts>-Xmx512m -XX:MaxPermSize=48m
-Doak.root.purgeLimit=100</test.opts>
<skip.deployment>false</skip.deployment>
<known.issues />
<project.reporting.outputEncoding>