This is an automated email from the ASF dual-hosted git repository.

mkataria pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1f1387d898 OAK-9817: Index stats logging indexing cycle failures after 
changes from OAK-9802 (#607)
1f1387d898 is described below

commit 1f1387d8980b53ac4d1c89000bd9f3218b7adea6
Author: Mohit Kataria <[email protected]>
AuthorDate: Tue Jul 12 11:26:41 2022 +0530

    OAK-9817: Index stats logging indexing cycle failures after changes from 
OAK-9802 (#607)
---
 .../elastic/index/ElasticIndexEditorProvider.java  | 75 ++++++++++++++++++++--
 .../index/elastic/ElasticWriterDisabledTest.java   | 21 ++++--
 2 files changed, 87 insertions(+), 9 deletions(-)

diff --git 
a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexEditorProvider.java
 
b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexEditorProvider.java
index 92d049934d..ac4db7e7d5 100644
--- 
a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexEditorProvider.java
+++ 
b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexEditorProvider.java
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.elastic.index;
 
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
@@ -24,12 +26,15 @@ import 
org.apache.jackrabbit.oak.plugins.index.elastic.ElasticConnection;
 import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition;
 import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexTracker;
 import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache;
+import 
org.apache.jackrabbit.oak.plugins.index.search.spi.editor.FulltextIndexEditor;
+import 
org.apache.jackrabbit.oak.plugins.index.search.spi.editor.FulltextIndexEditorContext;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import static org.apache.jackrabbit.oak.commons.PathUtils.ROOT_PATH;
 import static 
org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition.TYPE_ELASTICSEARCH;
 
 public class ElasticIndexEditorProvider implements IndexEditorProvider {
@@ -38,7 +43,7 @@ public class ElasticIndexEditorProvider implements 
IndexEditorProvider {
     private final ElasticConnection elasticConnection;
     private final ExtractedTextCache extractedTextCache;
 
-    public final static  String OAK_INDEX_ELASTIC_WRITER_DISABLE_KEY = 
"oak.index.elastic.writer.disable";
+    public final static String OAK_INDEX_ELASTIC_WRITER_DISABLE_KEY = 
"oak.index.elastic.writer.disable";
 
     private final boolean OAK_INDEX_ELASTIC_WRITER_DISABLE = 
Boolean.getBoolean(OAK_INDEX_ELASTIC_WRITER_DISABLE_KEY);
 
@@ -54,7 +59,7 @@ public class ElasticIndexEditorProvider implements 
IndexEditorProvider {
     public @Nullable Editor getIndexEditor(@NotNull String type,
                                            @NotNull NodeBuilder definition, 
@NotNull NodeState root,
                                            @NotNull IndexUpdateCallback 
callback) {
-        if (TYPE_ELASTICSEARCH.equals(type) && 
!OAK_INDEX_ELASTIC_WRITER_DISABLE) {
+        if (TYPE_ELASTICSEARCH.equals(type)) {
             if (!(callback instanceof ContextAwareCallback)) {
                 throw new IllegalStateException("callback instance not of type 
ContextAwareCallback [" + callback + "]");
             }
@@ -73,8 +78,11 @@ public class ElasticIndexEditorProvider implements 
IndexEditorProvider {
                     extractedTextCache,
                     indexingContext,
                     true);
-
-            return new ElasticIndexEditor(context);
+            if (OAK_INDEX_ELASTIC_WRITER_DISABLE) {
+                return new NOOPIndexEditor<>(context);
+            } else {
+                return new ElasticIndexEditor(context);
+            }
         }
         return null;
     }
@@ -82,4 +90,63 @@ public class ElasticIndexEditorProvider implements 
IndexEditorProvider {
     public ExtractedTextCache getExtractedTextCache() {
         return extractedTextCache;
     }
+
+    /**
+     * This is a no-op editor, so that elastic index is not updated
+     * where OAK_INDEX_ELASTIC_WRITER_DISABLE = true is set as system property.
+     */
+    private class NOOPIndexEditor<D> extends FulltextIndexEditor<D> {
+        public NOOPIndexEditor(FulltextIndexEditorContext<D> context) {
+            super(context);
+        }
+
+        @Override
+        public void enter(NodeState before, NodeState after) {
+        }
+
+        @Override
+        public void leave(NodeState before, NodeState after) {
+        }
+
+        @Override
+        public String getPath() {
+            return ROOT_PATH;
+        }
+
+        @Override
+        public void propertyAdded(PropertyState after) {
+        }
+
+        @Override
+        public void propertyChanged(PropertyState before, PropertyState after) 
{
+        }
+
+        @Override
+        public void propertyDeleted(PropertyState before) {
+        }
+
+        @Override
+        public Editor childNodeAdded(String name, NodeState after) {
+            return this;
+        }
+
+        @Override
+        public Editor childNodeChanged(String name, NodeState before, 
NodeState after) {
+            return this;
+        }
+
+        @Override
+        public Editor childNodeDeleted(String name, NodeState before) throws 
CommitFailedException {
+            return this;
+        }
+
+        @Override
+        public FulltextIndexEditorContext<D> getContext() {
+            return super.getContext();
+        }
+
+        @Override
+        public void markDirty() {
+        }
+    }
 }
diff --git 
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticWriterDisabledTest.java
 
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticWriterDisabledTest.java
index e6198f15a6..6aa4d6592f 100644
--- 
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticWriterDisabledTest.java
+++ 
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticWriterDisabledTest.java
@@ -18,8 +18,11 @@ package org.apache.jackrabbit.oak.plugins.index.elastic;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean;
 import org.apache.jackrabbit.oak.jcr.Jcr;
+import org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate;
 import org.apache.jackrabbit.oak.plugins.index.TestUtils;
+import 
org.apache.jackrabbit.oak.plugins.index.counter.NodeCounterEditorProvider;
 import 
org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditorProvider;
 import 
org.apache.jackrabbit.oak.plugins.index.elastic.query.ElasticIndexProvider;
 import 
org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder;
@@ -55,7 +58,9 @@ import java.util.UUID;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
+import static com.google.common.collect.Lists.newArrayList;
 import static org.apache.jackrabbit.oak.InitialContentHelper.INITIAL_CONTENT;
+import static 
org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider.compose;
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
@@ -77,9 +82,9 @@ public class ElasticWriterDisabledTest {
     public final RestoreSystemProperties restoreSystemProperties
             = new RestoreSystemProperties();
 
-
     private Session adminSession;
     private QueryManager qe;
+    private AsyncIndexUpdate asyncIndexUpdate;
 
     @Before
     public void setup() throws Exception {
@@ -96,7 +101,10 @@ public class ElasticWriterDisabledTest {
         ElasticIndexProvider indexProvider = new 
ElasticIndexProvider(indexTracker);
 
         NodeStore nodeStore = new MemoryNodeStore(INITIAL_CONTENT);
-
+        asyncIndexUpdate = new AsyncIndexUpdate("async", nodeStore, 
compose(newArrayList(
+                editorProvider,
+                new NodeCounterEditorProvider()
+        )));
         Oak oak = new Oak(nodeStore)
                 .with(new OpenSecurityProvider())
                 .with(editorProvider)
@@ -116,7 +124,6 @@ public class ElasticWriterDisabledTest {
     @Test
     public void elasticDoNotIndexDocuments() throws Exception {
         IndexDefinitionBuilder indexDefinitionBuilder = new 
ElasticIndexDefinitionBuilder();
-        indexDefinitionBuilder.noAsync();
         IndexDefinitionBuilder.IndexRule indexRule = 
indexDefinitionBuilder.indexRule("nt:base");
         indexRule.property("a").propertyIndex().analyzed();
 
@@ -131,18 +138,19 @@ public class ElasticWriterDisabledTest {
             c.setProperty("b", "bar");
         }
         adminSession.save();
+        asyncIndexUpdate.run();
         try {
             assertQuery("select [jcr:path] from [nt:base] where contains(a, 
'foo')", 100);
             Assert.fail("documents should not be indexed");
         } catch (AssertionError e) {
             Assert.assertEquals(e.getCause().getMessage(), "expected:<100> but 
was:<0>");
         }
+        Assert.assertFalse(((IndexStatsMBean) 
asyncIndexUpdate.getIndexStats()).isFailing());
     }
 
     @Test
     public void elasticDoNotIndexOnReindex() throws Exception {
         IndexDefinitionBuilder indexDefinitionBuilder = new 
ElasticIndexDefinitionBuilder();
-        indexDefinitionBuilder.noAsync();
         IndexDefinitionBuilder.IndexRule indexRule = 
indexDefinitionBuilder.indexRule("nt:base");
         indexRule.property("a").propertyIndex().analyzed();
 
@@ -157,6 +165,7 @@ public class ElasticWriterDisabledTest {
             c.setProperty("b", "bar");
         }
         adminSession.save();
+        asyncIndexUpdate.run();
 
         try {
             assertQuery("select [jcr:path] from [nt:base] where contains(a, 
'foo')", 100);
@@ -164,6 +173,7 @@ public class ElasticWriterDisabledTest {
         } catch (AssertionError e) {
             Assert.assertEquals(e.getCause().getMessage(), "expected:<100> but 
was:<0>");
         }
+        Assert.assertFalse(((IndexStatsMBean) 
asyncIndexUpdate.getIndexStats()).isFailing());
 
         // adding an extra content node (handled by reindex and potentially 
incremental indexing)
         Node c = content.addNode("c_100");
@@ -177,13 +187,14 @@ public class ElasticWriterDisabledTest {
         // Now we reindex and see everything works fine
         indexNode.setProperty(REINDEX_PROPERTY_NAME, true);
         adminSession.save();
-
+        asyncIndexUpdate.run();
         try {
             assertQuery("select [jcr:path] from [nt:base] where contains(a, 
'foo')", 101);
             Assert.fail("documents should not be indexed");
         } catch (AssertionError e) {
             Assert.assertEquals(e.getCause().getMessage(), "expected:<101> but 
was:<0>");
         }
+        Assert.assertFalse(((IndexStatsMBean) 
asyncIndexUpdate.getIndexStats()).isFailing());
     }
 
 

Reply via email to