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 ch...@apache.org on 2016/10/19 15:08:10 UTC
svn commit: r1765626 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/document/
main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/
test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/
Author: chetanm
Date: Wed Oct 19 15:08:10 2016
New Revision: 1765626
URL: http://svn.apache.org/viewvc?rev=1765626&view=rev
Log:
OAK-1312 - [bundling] Bundle nodes into a document
Avoid setting of hasChildren flag for the bundled nodes
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/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.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=1765626&r1=1765625&r2=1765626&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:08:10 2016
@@ -76,6 +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();
/**
* Create a new Commit.
@@ -143,6 +144,10 @@ public class Commit {
op.setMapEntry(key, revision, value);
}
+ void addBundledNode(String path) {
+ bundledNodes.add(path);
+ }
+
void markNodeHavingBinary(String path) {
this.nodesWithBinaries.add(path);
}
@@ -378,6 +383,11 @@ public class Commit {
continue;
}
+ //Ignore setting children path for bundled nodes
+ if (bundledNodes.contains(parentPath)){
+ continue;
+ }
+
processedParents.add(parentPath);
UpdateOp op = getUpdateOperationForNode(parentPath);
NodeDocument.setChildrenFlag(op, true);
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=1765626&r1=1765625&r2=1765626&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:08:10 2016
@@ -61,6 +61,7 @@ class CommitDiff implements NodeStateDif
this.builder = builder;
this.blobs = blobs;
setMetaProperties();
+ informCommitAboutBundledNodes();
}
@Override
@@ -122,6 +123,12 @@ class CommitDiff implements NodeStateDif
}
}
+ private void informCommitAboutBundledNodes() {
+ if (bundlingHandler.isBundledNode()){
+ commit.addBundledNode(bundlingHandler.getNodeFullPath());
+ }
+ }
+
private void setProperty(PropertyState property) {
builder.resetWriter();
JsonSerializer serializer = new JsonSerializer(builder, blobs);
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java?rev=1765626&r1=1765625&r2=1765626&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java Wed Oct 19 15:08:10 2016
@@ -60,6 +60,20 @@ public class BundlingHandler {
return ctx.isBundling() ? ctx.getPropertyPath(propertyName) : propertyName;
}
+ /**
+ * Returns true if and only if current node is bundled in another node
+ */
+ public boolean isBundledNode(){
+ return ctx.matcher.depth() > 0;
+ }
+
+ /**
+ * Returns absolute path of the current node
+ */
+ public String getNodeFullPath() {
+ return path;
+ }
+
public Set<PropertyState> getMetaProps() {
return metaProps;
}
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.java?rev=1765626&r1=1765625&r2=1765626&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.java Wed Oct 19 15:08:10 2016
@@ -72,16 +72,19 @@ public class BundlingHandlerTest {
BundlingHandler fileHandler = childHandler(handler, state, "/sunrise.jpg");
assertEquals("/sunrise.jpg", fileHandler.getRootBundlePath());
assertTrue(fileHandler.isBundlingRoot());
+ assertFalse(fileHandler.isBundledNode());
assertEquals("foo", fileHandler.getPropertyPath("foo"));
BundlingHandler jcrContentHandler = childHandler(handler, state, "/sunrise.jpg/jcr:content");
assertEquals("/sunrise.jpg", jcrContentHandler.getRootBundlePath());
assertFalse(jcrContentHandler.isBundlingRoot());
+ assertTrue(jcrContentHandler.isBundledNode());
assertEquals("jcr:content/foo", jcrContentHandler.getPropertyPath("foo"));
BundlingHandler metadataHandler = childHandler(handler, state, "/sunrise.jpg/metadata");
assertEquals("/sunrise.jpg/metadata", metadataHandler.getRootBundlePath());
assertTrue(metadataHandler.isBundlingRoot());
+ assertFalse(metadataHandler.isBundledNode());
assertEquals("foo", metadataHandler.getPropertyPath("foo"));
// /sunrise.jpg/jcr:content/bar should have bundle root reset
@@ -120,7 +123,7 @@ public class BundlingHandlerTest {
assertEquals("foo", fileHandler.getPropertyPath("foo"));
assertEquals(0, fileHandler.getMetaProps().size());
}
-
+
private BundlingHandler childHandler(BundlingHandler parent, NodeState parentState, String childPath) {
BundlingHandler result = parent;
NodeState state = parentState;
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=1765626&r1=1765625&r2=1765626&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:08:10 2016
@@ -19,39 +19,60 @@
package org.apache.jackrabbit.oak.plugins.document.bundlor;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
+import javax.annotation.Nonnull;
+
+import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
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.Collection;
+import org.apache.jackrabbit.oak.plugins.document.Document;
import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+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;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
import org.apache.jackrabbit.oak.spi.state.EqualsDiff;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class DocumentBundlingTest {
@Rule
public DocumentMKBuilderProvider builderProvider = new DocumentMKBuilderProvider();
private DocumentNodeStore store;
+ private RecordingDocumentStore ds = new RecordingDocumentStore();
@Before
public void setUpBundlor() throws CommitFailedException {
- store = builderProvider.newBuilder().getNodeStore();
+ store = builderProvider
+ .newBuilder()
+ .setDocumentStore(ds)
+ .memoryCacheSize(0)
+ .getNodeStore();
NodeState registryState = BundledTypesRegistry.builder()
.forType("nt:file", "jcr:content")
.registry()
- .forType("app:Asset", "jcr:content", "jcr:content/metadata")
+ .forType("app:Asset")
+ .include("jcr:content")
+ .include("jcr:content/metadata")
+ .include("jcr:content/renditions")
+ .include("jcr:content/renditions/**")
.build();
NodeBuilder builder = store.getRoot().builder();
@@ -77,6 +98,25 @@ public class DocumentBundlingTest {
assertTrue(PartialEqualsDiff.equals(fileNode.getNodeState(), fileNodeState.getChildNode("book.jpg")));
}
+ //TODO Test _bin being set
+
+ @Test
+ public void bundledParent() throws Exception{
+ NodeBuilder builder = store.getRoot().builder();
+ NodeBuilder appNB = newNode("app:Asset");
+ createChild(appNB,
+ "jcr:content", //Bundled
+ "jcr:content/comments" //Not bundled. Parent bundled
+ );
+ builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
+ store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+ assertTrue(PartialEqualsDiff.equals(appNB.getNodeState(), getNode(store.getRoot(), "/test/book.jpg")));
+ }
+
+ private static void dump(NodeState state){
+ System.out.println(NodeStateUtils.toString(state));
+ }
private static NodeBuilder newNode(String typeName){
NodeBuilder builder = EMPTY_NODE.builder();
@@ -84,6 +124,44 @@ public class DocumentBundlingTest {
return builder;
}
+ private static NodeBuilder createChild(NodeBuilder root, String ... paths){
+ for (String path : paths){
+ NodeBuilder nb = root;
+ for (String nodeName : PathUtils.elements(path)){
+ nb = nb.child(nodeName);
+ }
+ }
+ return root;
+ }
+
+ private static class RecordingDocumentStore extends MemoryDocumentStore {
+ final List<String> queryPaths = new ArrayList<>();
+ final List<String> findPaths = new ArrayList<>();
+
+ @Override
+ public <T extends Document> T find(Collection<T> collection, String key, int maxCacheAge) {
+ if (collection == Collection.NODES){
+ findPaths.add(Utils.getPathFromId(key));
+ }
+ return super.find(collection, key);
+ }
+
+ @Nonnull
+ @Override
+ public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey,
+ String indexedProperty, long startValue, int limit) {
+ if (collection == Collection.NODES){
+ queryPaths.add(Utils.getPathFromId(Utils.getParentIdFromLowerLimit(fromKey)));
+ }
+ return super.query(collection, fromKey, toKey, indexedProperty, startValue, limit);
+ }
+
+ public void reset(){
+ queryPaths.clear();
+ findPaths.clear();
+ }
+ }
+
private static class PartialEqualsDiff extends EqualsDiff {
private final Set<String> ignoredProps = Sets.newHashSet(DocumentBundlor.META_PROP_PATTERN);