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 fo...@apache.org on 2020/08/05 06:30:53 UTC

svn commit: r1880599 - in /jackrabbit/oak/trunk/oak-search-elastic/src: main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticIndexTracker.java test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java

Author: fortino
Date: Wed Aug  5 06:30:53 2020
New Revision: 1880599

URL: http://svn.apache.org/viewvc?rev=1880599&view=rev
Log:
OAK-9163: (fix) ElasticIndexTracker should never use stored index definitions

Modified:
    jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticIndexTracker.java
    jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java

Modified: jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticIndexTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticIndexTracker.java?rev=1880599&r1=1880598&r2=1880599&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticIndexTracker.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticIndexTracker.java Wed Aug  5 06:30:53 2020
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticConnection;
 import org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexTracker;
+import org.apache.jackrabbit.oak.spi.state.EqualsDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.jetbrains.annotations.NotNull;
 
@@ -35,7 +36,8 @@ class ElasticIndexTracker extends Fullte
         // The :status gets updated every time the indexed content is changed (with properties like last_update_ts),
         // removing the check on :status reduces drastically the contention between queries (that need to acquire the
         // read lock) and updates (need to acquire the write lock).
-        return isIndexDefinitionChanged(before, after);
+        // Moreover, we don't check diffs in stored index definitions since are not created for elastic.
+        return !EqualsDiff.equals(before, after);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java?rev=1880599&r1=1880598&r2=1880599&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java Wed Aug  5 06:30:53 2020
@@ -20,10 +20,10 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
+import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
-import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.Arrays;
@@ -34,6 +34,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition.INDEX_DEFINITION_NODE;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertTrue;
 
 public class ElasticFullTextAsyncTest extends ElasticAbstractQueryTest {
 
@@ -43,7 +44,7 @@ public class ElasticFullTextAsyncTest ex
     }
 
     @Test
-    public void testFullTextQuery() throws Exception {
+    public void fullTextQuery() throws Exception {
         IndexDefinitionBuilder builder = createIndex("propa");
         builder.async("async");
         builder.indexRule("nt:base").property("propa").analyzed();
@@ -70,7 +71,7 @@ public class ElasticFullTextAsyncTest ex
     }
 
     @Test
-    public void testNoStoredIndexDefinition() throws Exception {
+    public void noStoredIndexDefinition() throws Exception {
         IndexDefinitionBuilder builder = createIndex("propa");
         builder.async("async");
         builder.indexRule("nt:base").property("propa").analyzed();
@@ -82,13 +83,12 @@ public class ElasticFullTextAsyncTest ex
         assertEventually(() -> {
             NodeState node = NodeStateUtils.getNode(nodeStore.getRoot(), "/" + INDEX_DEFINITIONS_NAME + "/" + indexId);
             PropertyState ps = node.getProperty(IndexConstants.REINDEX_COUNT);
-            Assert.assertTrue(ps != null && ps.getValue(Type.LONG) == 1 && !node.hasChildNode(INDEX_DEFINITION_NODE));
+            assertTrue(ps != null && ps.getValue(Type.LONG) == 1 && !node.hasChildNode(INDEX_DEFINITION_NODE));
         });
-
     }
 
     @Test
-    public void testNodeScopeIndexedQuery() throws Exception {
+    public void nodeScopeIndexedQuery() throws Exception {
         IndexDefinitionBuilder builder = createIndex("a", "b").async("async");
         builder.indexRule("nt:base").property("a").analyzed().nodeScopeIndex();
         builder.indexRule("nt:base").property("b").analyzed().nodeScopeIndex();
@@ -114,7 +114,7 @@ public class ElasticFullTextAsyncTest ex
     }
 
     @Test
-    public void testFullTextMultiTermQuery() throws Exception {
+    public void fullTextMultiTermQuery() throws Exception {
         IndexDefinitionBuilder builder = createIndex("analyzed_field");
         builder.async("async");
         builder.indexRule("nt:base").property("analyzed_field").analyzed();
@@ -134,7 +134,7 @@ public class ElasticFullTextAsyncTest ex
     }
 
     @Test
-    public void testDefaultAnalyzer() throws Exception {
+    public void defaultAnalyzer() throws Exception {
         IndexDefinitionBuilder builder = createIndex("analyzed_field");
         builder.async("async");
         builder.indexRule("nt:base")
@@ -160,4 +160,33 @@ public class ElasticFullTextAsyncTest ex
         });
     }
 
+    @Test
+    public void fulltextWithModifiedNodeScopeIndex() throws Exception {
+        IndexDefinitionBuilder builder = createIndex("analyzed_field");
+        builder.async("async");
+        builder.indexRule("nt:base")
+                .property("analyzed_field")
+                .analyzed();
+
+        Tree index = setIndex(UUID.randomUUID().toString(), builder);
+        root.commit();
+
+        //add content
+        Tree test = root.getTree("/").addChild("test");
+
+        test.addChild("a").setProperty("analyzed_field", "sun.jpg");
+        root.commit();
+
+        assertEventually(() ->
+                assertQuery("//*[jcr:contains(@analyzed_field, 'SUN.JPG')] ", XPATH, Collections.singletonList("/test/a")));
+
+        // add nodeScopeIndex at a later stage
+        index.getChild("indexRules").getChild("nt:base").getChild("properties")
+                .getChild("analyzed_field").setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true);
+        root.commit();
+
+        assertEventually(() ->
+                assertQuery("//*[jcr:contains(., 'jpg')] ", XPATH, Collections.singletonList("/test/a")));
+    }
+
 }