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/12/12 10:11:10 UTC

svn commit: r1773759 - in /jackrabbit/oak/trunk/oak-lucene/src: main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java

Author: chetanm
Date: Mon Dec 12 10:11:10 2016
New Revision: 1773759

URL: http://svn.apache.org/viewvc?rev=1773759&view=rev
Log:
OAK-5258 - LuceneIndexEditor skips indexing for unknown nodetype due to stale NodeType registry state

Handle the case on query side also

Modified:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java?rev=1773759&r1=1773758&r2=1773759&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java Mon Dec 12 10:11:10 2016
@@ -538,6 +538,19 @@ class IndexPlanner {
                     //Theoretically there may be multiple rules for same nodeType with
                     //some condition defined. So again find a rule which applies
                     IndexingRule matchingRule = definition.getApplicableIndexingRule(rule.getNodeTypeName());
+
+                    if (matchingRule == null && rule.getNodeTypeName().equals(filter.getNodeType())){
+                        //In case nodetype registry in IndexDefinition is stale then it would not populate
+                        //rules for new nodetype even though at indexing time it was able to index (due to
+                        //use of latest nodetype reg nodestate)
+                        //In such a case if the rule name and nodetype name for query matches then it is
+                        //considered a match.
+                        //This would though not work for the case where rule is related to nodetype as used
+                        //in query matched via some inheritance chain
+                        //TODO Need a way to check if nodetype reg as seen by IndexDefinition is old then
+                        //IndexNode is reopened
+                        matchingRule = rule;
+                    }
                     if (matchingRule != null){
                         log.debug("Applicable IndexingRule found {}", matchingRule);
                         return rule;

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java?rev=1773759&r1=1773758&r2=1773759&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java Mon Dec 12 10:11:10 2016
@@ -32,6 +32,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.JcrConstants;
@@ -41,6 +42,7 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate;
+import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.counter.NodeCounterEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier;
 import org.apache.jackrabbit.oak.plugins.index.lucene.IndexTracker;
@@ -78,8 +80,10 @@ import org.junit.rules.TemporaryFolder;
 import static com.google.common.collect.ImmutableList.of;
 import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
 import static org.apache.jackrabbit.oak.spi.mount.Mounts.defaultMountInfoProvider;
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 
 public class HybridIndexTest extends AbstractQueryTest {
     private ExecutorService executorService = Executors.newFixedThreadPool(2);
@@ -271,6 +275,56 @@ public class HybridIndexTest extends Abs
         assertQuery("select [jcr:path] from [nt:base] where [bar] = 'foo'", of("/b"));
     }
 
+    @Test
+    public void newNodeTypesFoundLater2() throws Exception{
+        String idxName = "hybridtest";
+        IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
+        idx.indexRule("oak:TestNode")
+                .property(JcrConstants.JCR_PRIMARYTYPE).propertyIndex();
+        idx.indexRule("nt:base")
+                .property("foo").propertyIndex()
+                .property("bar").propertyIndex();
+        idx.async("async","sync");
+        idx.build(root.getTree("/").getChild("oak:index").addChild(idxName));
+
+        //By default nodetype index indexes every nodetype. Declare a specific list
+        //such that it does not indexes test nodetype
+        Tree nodeType = root.getTree("/oak:index/nodetype");
+        if (!nodeType.hasProperty(IndexConstants.DECLARING_NODE_TYPES)){
+            nodeType.setProperty(IndexConstants.DECLARING_NODE_TYPES, ImmutableList.of("nt:file"), Type.NAMES);
+            nodeType.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true);
+        }
+
+        root.commit();
+
+        setTraversalEnabled(false);
+
+        createPath("/a").setProperty("foo", "bar");
+        root.commit();
+        assertQuery("select [jcr:path] from [nt:base] where [foo] = 'bar'", of("/a"));
+
+        optionalEditorProvider.delegate = new TypeEditorProvider(false);
+        NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
+        root.refresh();
+
+        Tree b = createPath("/b");
+        b.setProperty(JcrConstants.JCR_PRIMARYTYPE, "oak:TestNode", Type.NAME);
+        b.setProperty("bar", "foo");
+
+        Tree c = createPath("/c");
+        c.setProperty(JcrConstants.JCR_PRIMARYTYPE, "oak:TestNode", Type.NAME);
+        root.commit();
+
+        String query = "select [jcr:path] from [oak:TestNode] ";
+        assertThat(explain(query), containsString("/oak:index/hybridtest"));
+        assertQuery(query, of("/b", "/c"));
+    }
+
+    private String explain(String query){
+        String explain = "explain " + query;
+        return executeQuery(explain, "JCR-SQL2").get(0);
+    }
+
     private void runAsyncIndex() {
         Runnable async = WhiteboardUtils.getService(wb, Runnable.class, new Predicate<Runnable>() {
             @Override