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:05:51 UTC
svn commit: r1765615 - 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:05:51 2016
New Revision: 1765615
URL: http://svn.apache.org/viewvc?rev=1765615&view=rev
Log:
OAK-1312 - [bundling] Bundle nodes into a document
Copy the bundling pattern as a meta property into the newly added NodeState.
For changed and deleted case rely on the meta property to determine the bundling pattern
Modified:
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/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.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/DocumentBundlorTest.java
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=1765615&r1=1765614&r2=1765615&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:05:51 2016
@@ -60,6 +60,7 @@ class CommitDiff implements NodeStateDif
this.bundlingHandler = bundlingHandler;
this.builder = builder;
this.blobs = blobs;
+ setMetaProperties();
}
@Override
@@ -82,9 +83,8 @@ class CommitDiff implements NodeStateDif
@Override
public boolean childNodeAdded(String name, NodeState after) {
- BundlingHandler child = bundlingHandler.childHandler(name, after);
+ BundlingHandler child = bundlingHandler.childAdded(name, after);
if (child.isBundlingRoot()) {
- //TODO Seed in the bundling pattern
//TODO Handle case for leaf node optimization
commit.addNode(new DocumentNodeState(store, child.getRootBundlePath(),
new RevisionVector(commit.getRevision())));
@@ -98,14 +98,14 @@ class CommitDiff implements NodeStateDif
NodeState before,
NodeState after) {
//TODO [bundling] Handle change of primaryType
- BundlingHandler child = bundlingHandler.childHandler(name, after);
+ BundlingHandler child = bundlingHandler.childChanged(name, after);
return after.compareAgainstBaseState(before,
new CommitDiff(store, commit, child, builder, blobs));
}
@Override
public boolean childNodeDeleted(String name, NodeState before) {
- BundlingHandler child = bundlingHandler.childHandler(name, before);
+ BundlingHandler child = bundlingHandler.childDeleted(name, before);
if (child.isBundlingRoot()) {
//TODO [bundling] Handle delete
commit.removeNode(child.getRootBundlePath(), before);
@@ -116,6 +116,12 @@ class CommitDiff implements NodeStateDif
//----------------------------< internal >----------------------------------
+ private void setMetaProperties() {
+ for (PropertyState ps : bundlingHandler.getMetaProps()){
+ setProperty(ps);
+ }
+ }
+
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=1765615&r1=1765614&r2=1765615&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:05:51 2016
@@ -19,6 +19,12 @@
package org.apache.jackrabbit.oak.plugins.document.bundlor;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.annotation.CheckForNull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -28,39 +34,93 @@ public class BundlingHandler {
private final BundledTypesRegistry registry;
private final String path;
private final BundlingRoot root;
+ private final Set<PropertyState> metaProps;
public BundlingHandler(BundledTypesRegistry registry) {
- this(registry, new BundlingRoot(), ROOT_PATH);
+ this(registry, new BundlingRoot(), ROOT_PATH, Collections.<PropertyState>emptySet());
}
private BundlingHandler(BundledTypesRegistry registry, BundlingRoot root, String path) {
+ this(registry, root, path, Collections.<PropertyState>emptySet());
+ }
+
+ private BundlingHandler(BundledTypesRegistry registry, BundlingRoot root, String path, Set<PropertyState> metaProps) {
this.registry = registry;
this.path = path;
this.root = root;
+ this.metaProps = metaProps;
}
public String getPropertyPath(String propertyName) {
return root.getPropertyPath(path, propertyName);
}
+ public Set<PropertyState> getMetaProps() {
+ return metaProps;
+ }
+
public String getRootBundlePath() {
return root.bundlingEnabled() ? root.getPath() : path;
}
- public BundlingHandler childHandler(String name, NodeState state) {
- String childPath = PathUtils.concat(path, name);
+ public BundlingHandler childAdded(String name, NodeState state){
+ String childPath = childPath(name);
+ BundlingRoot childRoot;
+ Set<PropertyState> metaProps = Collections.emptySet();
+ if (root.isBundled(childPath)) {
+ //TODO Add meta prop for bundled child node
+ childRoot = root;
+ } else {
+ DocumentBundlor bundlor = registry.getBundlor(state);
+ if (bundlor != null){
+ PropertyState bundlorConfig = bundlor.asPropertyState();
+ metaProps = Collections.singleton(bundlorConfig);
+ }
+ childRoot = new BundlingRoot(childPath, bundlor);
+ }
+
+ return new BundlingHandler(registry, childRoot, childPath, metaProps);
+ }
+
+ public BundlingHandler childDeleted(String name, NodeState state){
+ String childPath = childPath(name);
+ BundlingRoot childRoot;
+ if (root.isBundled(childPath)) {
+ //TODO Add meta prop for bundled child node
+ childRoot = root;
+ } else {
+ childRoot = new BundlingRoot(childPath, getBundlorFromEmbeddedConfig(state));
+ }
+ return new BundlingHandler(registry, childRoot, childPath);
+ }
+
+ public BundlingHandler childChanged(String name, NodeState state){
+ String childPath = childPath(name);
+ BundlingRoot childRoot;
if (root.isBundled(childPath)) {
- return new BundlingHandler(registry, root, childPath);
+ childRoot = root;
+ } else {
+ childRoot = new BundlingRoot(childPath, getBundlorFromEmbeddedConfig(state));
}
- //TODO For only add we should lookup (fully new add) we should lookup new bundlor
- //For update and delete we should always rely on existing bundlor config
- //TODO Check for pattern from state first
- DocumentBundlor bundlor = registry.getBundlor(state);
- return new BundlingHandler(registry, new BundlingRoot(childPath, bundlor), childPath);
+ return new BundlingHandler(registry, childRoot, childPath);
}
public boolean isBundlingRoot() {
return root.getPath().equals(path);
}
+
+ private String childPath(String name){
+ return PathUtils.concat(path, name);
+ }
+
+ @CheckForNull
+ private static DocumentBundlor getBundlorFromEmbeddedConfig(NodeState state) {
+ PropertyState bundlorConfig = state.getProperty(DocumentBundlor.META_PROP_PATTERN);
+ DocumentBundlor bundlor = null;
+ if (bundlorConfig != null){
+ bundlor = DocumentBundlor.from(bundlorConfig);
+ }
+ return bundlor;
+ }
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java?rev=1765615&r1=1765614&r2=1765615&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlor.java Wed Oct 19 15:05:51 2016
@@ -19,22 +19,28 @@
package org.apache.jackrabbit.oak.plugins.document.bundlor;
+import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.spi.state.NodeState;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
+
public class DocumentBundlor {
+ /**
+ * Hidden property to store the pattern as part of NodeState
+ */
+ public static final String META_PROP_PATTERN = ":pattern";
+
public static final String PROP_PATTERN = "pattern";
private final List<Include> includes;
- public DocumentBundlor(List<Include> includes) {
- //TODO Have assertion for that all intermediate paths are included
- this.includes = ImmutableList.copyOf(includes);
- }
-
public static DocumentBundlor from(NodeState nodeState){
Preconditions.checkArgument(nodeState.hasProperty(PROP_PATTERN), "NodeStated [%s] does not have required " +
"property [%s]", nodeState, PROP_PATTERN);
@@ -49,6 +55,16 @@ public class DocumentBundlor {
return new DocumentBundlor(includes);
}
+ public static DocumentBundlor from(PropertyState prop){
+ Preconditions.checkArgument(META_PROP_PATTERN.equals(prop.getName()));
+ return from(prop.getValue(Type.STRINGS));
+ }
+
+ private DocumentBundlor(List<Include> includes) {
+ //TODO Have assertion for that all intermediate paths are included
+ this.includes = ImmutableList.copyOf(includes);
+ }
+
public boolean isBundled(String relativePath) {
for (Include include : includes){
if (include.match(relativePath)){
@@ -58,6 +74,14 @@ public class DocumentBundlor {
return false;
}
+ public PropertyState asPropertyState(){
+ List<String> includePatterns = new ArrayList<>(includes.size());
+ for (Include i : includes){
+ includePatterns.add(i.getPattern());
+ }
+ return createProperty(META_PROP_PATTERN, includePatterns, STRINGS);
+ }
+
@Override
public String toString() {
return includes.toString();
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java?rev=1765615&r1=1765614&r2=1765615&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java Wed Oct 19 15:05:51 2016
@@ -45,6 +45,7 @@ public class Include {
enum Directive {ALL, NONE}
private final String[] elements;
private final Directive directive;
+ private final String pattern;
public Include(String pattern){
List<String> pathElements = ImmutableList.copyOf(PathUtils.elements(pattern));
@@ -66,6 +67,7 @@ public class Include {
this.elements = elementList.toArray(new String[0]);
this.directive = directive;
+ this.pattern = pattern;
}
public boolean match(String relativePath) {
@@ -94,9 +96,13 @@ public class Include {
return true;
}
+ public String getPattern() {
+ return pattern;
+ }
+
@Override
public String toString() {
- return String.format("%s(%s)", Arrays.toString(elements), directive);
+ return pattern;
}
Directive getDirective() {
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=1765615&r1=1765614&r2=1765615&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:05:51 2016
@@ -33,6 +33,7 @@ import static org.junit.Assert.assertTru
public class BundlingHandlerTest {
+
private NodeBuilder builder = EMPTY_NODE.builder();
@Test
@@ -90,12 +91,42 @@ public class BundlingHandlerTest {
assertEquals("foo", barHandler.getPropertyPath("foo"));
}
+ @Test
+ public void childAdded_BundlingStart() throws Exception{
+ BundledTypesRegistry registry = BundledTypesRegistry.builder().forType("nt:file", "jcr:content").buildRegistry();
+
+ BundlingHandler handler = new BundlingHandler(registry);
+ childBuilder(builder, "sunrise.jpg/jcr:content").setProperty("jcr:data", "foo");
+ type(childBuilder(builder, "sunrise.jpg"), "nt:file");
+ NodeState state = builder.getNodeState();
+
+ BundlingHandler fileHandler = handler.childAdded("sunrise.jpg", state.getChildNode("sunrise.jpg"));
+ assertEquals("/sunrise.jpg", fileHandler.getRootBundlePath());
+ assertTrue(fileHandler.isBundlingRoot());
+ assertEquals("foo", fileHandler.getPropertyPath("foo"));
+ assertEquals(1, fileHandler.getMetaProps().size());
+ }
+
+ @Test
+ public void childAdded_NoBundling() throws Exception{
+ BundlingHandler handler = new BundlingHandler(BundledTypesRegistry.from(EMPTY_NODE));
+ childBuilder(builder, "sunrise.jpg/jcr:content").setProperty("jcr:data", "foo");
+ type(childBuilder(builder, "sunrise.jpg"), "nt:file");
+ NodeState state = builder.getNodeState();
+
+ BundlingHandler fileHandler = handler.childAdded("sunrise.jpg", state.getChildNode("sunrise.jpg"));
+ assertEquals("/sunrise.jpg", fileHandler.getRootBundlePath());
+ assertTrue(fileHandler.isBundlingRoot());
+ 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;
for (String name : PathUtils.elements(checkNotNull(childPath))) {
state = state.getChildNode(name);
- result = result.childHandler(name, state);
+ result = result.childAdded(name, state);
}
return result;
}
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlorTest.java?rev=1765615&r1=1765614&r2=1765615&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlorTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlorTest.java Wed Oct 19 15:05:51 2016
@@ -19,6 +19,7 @@
package org.apache.jackrabbit.oak.plugins.document.bundlor;
+import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.junit.Test;
@@ -28,6 +29,7 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class DocumentBundlorTest {
@@ -50,4 +52,17 @@ public class DocumentBundlorTest {
DocumentBundlor.from(builder.getNodeState());
}
+ @Test
+ public void asPropertyState() throws Exception{
+ builder.setProperty(createProperty(PROP_PATTERN, asList("x", "x/y", "z"), STRINGS));
+ DocumentBundlor bundlor = DocumentBundlor.from(builder.getNodeState());
+ PropertyState ps = bundlor.asPropertyState();
+
+ assertNotNull(ps);
+ DocumentBundlor bundlor2 = DocumentBundlor.from(ps);
+ assertTrue(bundlor2.isBundled("x"));
+ assertTrue(bundlor2.isBundled("x/y"));
+ assertFalse(bundlor2.isBundled("m"));
+ }
+
}
\ No newline at end of file