Author: chetanm
Date: Wed Oct 19 15:12:16 2016
New Revision: 1765648
URL: http://svn.apache.org/viewvc?rev=1765648&view=rev
Log:
OAK-1312 - [bundling] Bundle nodes into a document
Handle the case of bundled nodes being marked as modified instead of new
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java?rev=1765648&r1=1765647&r2=1765648&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
Wed Oct 19 15:12:16 2016
@@ -31,6 +31,7 @@ import javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.commons.PathUtils;
@@ -75,7 +76,7 @@ public class Commit {
/** Set of all nodes which have binary properties. **/
private HashSet<String> nodesWithBinaries = Sets.newHashSet();
- private HashSet<String> bundledNodes = Sets.newHashSet();
+ private HashMap<String, String> bundledNodes = Maps.newHashMap();
/**
* Create a new Commit.
@@ -143,8 +144,8 @@ public class Commit {
op.setMapEntry(key, revision, value);
}
- void addBundledNode(String path) {
- bundledNodes.add(path);
+ void addBundledNode(String path, String bundlingRootPath) {
+ bundledNodes.put(path, bundlingRootPath);
}
void markNodeHavingBinary(String path) {
@@ -660,10 +661,19 @@ public class Commit {
}
}
UpdateOp op = operations.get(path);
+
+ //In case its bundled the op would be the one for
+ //bundling root
+ boolean bundled = isBundled(path);
+ if (bundled){
+ String bundlingRoot = bundledNodes.get(path);
+ op = operations.get(bundlingRoot);
+ }
+
boolean isNew = op != null && op.isNew();
if (op == null || !hasContentChanges(op) || denotesRoot(path)) {
// track intermediate node and root
- if (!isBundled(path)) {
+ if (!bundled) {
tracker.track(path);
}
}
@@ -698,8 +708,8 @@ public class Commit {
}
}
- private boolean isBundled(String parentPath) {
- return bundledNodes.contains(parentPath);
+ private boolean isBundled(String path) {
+ return bundledNodes.containsKey(path);
}
private static final Function<UpdateOp.Key, String> KEY_TO_NAME =
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java?rev=1765648&r1=1765647&r2=1765648&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java
Wed Oct 19 15:12:16 2016
@@ -132,7 +132,7 @@ class CommitDiff implements NodeStateDif
private void informCommitAboutBundledNodes() {
if (bundlingHandler.isBundledNode()){
- commit.addBundledNode(bundlingHandler.getNodeFullPath());
+ commit.addBundledNode(bundlingHandler.getNodeFullPath(),
bundlingHandler.getRootBundlePath());
}
}
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java?rev=1765648&r1=1765647&r2=1765648&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
Wed Oct 19 15:12:16 2016
@@ -30,13 +30,13 @@ import com.google.common.collect.Iterabl
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.TestNodeObserver;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
@@ -52,6 +52,7 @@ import org.junit.Test;
import static com.google.common.collect.ImmutableList.copyOf;
import static java.lang.String.format;
+import static org.apache.commons.io.FileUtils.ONE_MB;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
import static
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor.META_PROP_BUNDLED_CHILD;
@@ -469,6 +470,31 @@ public class DocumentBundlingTest {
assertEquals(2, store.getPendingWriteCount());
}
+ @Test
+ public void bundledNodeAndNodeCache() throws Exception{
+ store.dispose();
+ store = builderProvider
+ .newBuilder()
+ .setDocumentStore(ds)
+ .memoryCacheSize(ONE_MB * 10)
+ .getNodeStore();
+
+ NodeBuilder builder = store.getRoot().builder();
+ NodeBuilder fileNode = newNode("nt:file");
+ fileNode.child("jcr:content").setProperty("jcr:data", "foo");
+ builder.child("test").setChildNode("book.jpg",
fileNode.getNodeState());
+
+ //Make some modifications under the bundled node
+ //This would cause an entry for bundled node in Commit modified set
+ childBuilder(builder,
"/test/book.jpg/jcr:content/vlt:definition").setProperty("foo", "bar");
+
+ TestNodeObserver o = new TestNodeObserver("test");
+ store.addObserver(o);
+ merge(builder);
+ assertEquals(4, o.added.size());
+
+ }
+
private void createTestNode(String path, NodeState state) throws
CommitFailedException {
String parentPath = PathUtils.getParentPath(path);
NodeBuilder builder = store.getRoot().builder();