Author: chetanm
Date: Sat Jan 14 08:39:36 2017
New Revision: 1778731
URL: http://svn.apache.org/viewvc?rev=1778731&view=rev
Log:
OAK-5448 - Aggregate logic should optimize for case where patterns do not
include wildcard
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java?rev=1778731&r1=1778730&r2=1778731&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java
Sat Jan 14 08:39:36 2017
@@ -19,6 +19,7 @@
package org.apache.jackrabbit.oak.plugins.index.lucene;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -33,6 +34,7 @@ import com.google.common.collect.Lists;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.plugins.index.lucene.util.ConfigUtil;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -125,7 +127,35 @@ class Aggregate {
private static void collectAggregates(NodeState nodeState, List<Matcher>
matchers,
ResultCollector collector) {
- for (ChildNodeEntry cne : nodeState.getChildNodeEntries()) {
+ if (hasPatternMatcher(matchers)){
+ collectAggregatesForPatternMatchers(nodeState, matchers,
collector);
+ } else {
+ collectAggregatesForDirectMatchers(nodeState, matchers, collector);
+ }
+ }
+
+ private static void collectAggregatesForDirectMatchers(NodeState
nodeState, List<Matcher> matchers,
+ ResultCollector collector) {
+ List<ChildNodeEntry> entries = Lists.newArrayList();
+ //Collect potentially matching child nodestates based on matcher name
+ for (Matcher m : matchers){
+ String nodeName = m.getNodeName();
+ NodeState child = nodeState.getChildNode(nodeName);
+ if (child.exists()){
+ entries.add(new MemoryChildNodeEntry(nodeName, child));
+ }
+ }
+ matchChildren(matchers, collector, entries);
+ }
+
+ private static void collectAggregatesForPatternMatchers(NodeState
nodeState, List<Matcher> matchers,
+ ResultCollector collector) {
+ matchChildren(matchers, collector, nodeState.getChildNodeEntries());
+ }
+
+ private static void matchChildren(List<Matcher> matchers, ResultCollector
collector,
+ Iterable<? extends ChildNodeEntry>
children) {
+ for (ChildNodeEntry cne : children) {
List<Matcher> nextSet = newArrayListWithCapacity(matchers.size());
for (Matcher m : matchers) {
Matcher result = m.match(cne.getName(), cne.getNodeState());
@@ -143,6 +173,15 @@ class Aggregate {
}
}
+ private static boolean hasPatternMatcher(List<Matcher> matchers){
+ for (Matcher m : matchers){
+ if (m.isPatternBased()){
+ return true;
+ }
+ }
+ return false;
+ }
+
private List<Matcher> createMatchers() {
List<Matcher> matchers = newArrayListWithCapacity(includes.size());
for (Include include : includes) {
@@ -217,6 +256,17 @@ class Aggregate {
public Aggregate getAggregate(NodeState matchedNodeState) {
return null;
}
+
+ public boolean isPattern(int depth){
+ return MATCH_ALL.equals(elements[depth]);
+
+ }
+
+ public String getElementNameIfNotAPattern(int depth) {
+ checkArgument(!isPattern(depth),
+ "Element at %s is pattern instead of specific name in %s",
depth, Arrays.toString(elements));
+ return elements[depth];
+ }
}
public static class NodeInclude extends Include<NodeInclude> {
@@ -410,12 +460,12 @@ class Aggregate {
}
}
- public static interface AggregateRoot {
+ public interface AggregateRoot {
void markDirty();
}
public static class Matcher {
- public static enum Status {CONTINUE, MATCH_FOUND, FAIL}
+ public enum Status {CONTINUE, MATCH_FOUND, FAIL}
private static class RootState {
final AggregateRoot root;
@@ -492,6 +542,18 @@ class Aggregate {
this.aggregateStack = ImmutableList.copyOf(paths);
}
+ public boolean isPatternBased() {
+ return currentInclude.isPattern(depth);
+ }
+
+ /**
+ * Returns the nodeName at current depth. This should only be called
+ * if and only if #isPatternBased is false otherwise it would throw
exception
+ */
+ public String getNodeName() {
+ return currentInclude.getElementNameIfNotAPattern(depth);
+ }
+
public Matcher match(String name, NodeState nodeState) {
boolean result = currentInclude.match(name, nodeState, depth);
if (result){
Modified:
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java?rev=1778731&r1=1778730&r2=1778731&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java
Sat Jan 14 08:39:36 2017
@@ -25,7 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
-import javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.collect.ArrayListMultimap;
@@ -41,7 +40,6 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.junit.Ignore;
import org.junit.Test;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -63,7 +61,6 @@ import static org.junit.Assert.assertTru
import static org.junit.matchers.JUnitMatchers.hasItems;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
public class AggregateTest {
@@ -98,7 +95,6 @@ public class AggregateTest {
assertThat(col.getNodePaths(), hasItems("a"));
}
- @Ignore("OAK-5448")
@Test
public void noOfChildNodeRead() throws Exception{
Aggregate ag = new Aggregate("nt:base", of(ni("a")));