Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java (revision 1708292) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java (working copy) @@ -67,6 +67,34 @@ private static final Logger log = LoggerFactory.getLogger(IndexUpdate.class); + /** + *

+ * The value of this flag determines the behavior of the IndexUpdate when + * dealing with {@code reindex} flags. + *

+ *

+ * If {@code false} (default value), the indexer will start reindexing + * immediately in the current thread, blocking a commit until this operation + * is done. + *

+ *

+ * If {@code true}, the indexer will ignore the flag, therefore ignoring any + * reindex requests. + *

+ *

+ * This is only provided as a support tool (see OAK-3505) so it should be + * used with extreme caution! + *

+ */ + private static final boolean IGNORE_REINDEX_FLAGS = Boolean + .getBoolean("IndexUpdate.ignoreReindexFlags"); + + static { + if (IGNORE_REINDEX_FLAGS) { + log.warn("Reindexing is disabled by configuration. This value is configurable via the 'IndexUpdate.ignoreReindexFlags' system property."); + } + } + private final IndexUpdateRootState rootState; private final NodeBuilder builder; @@ -145,7 +173,7 @@ String name) { PropertyState ps = definition.getProperty(REINDEX_PROPERTY_NAME); if (ps != null && ps.getValue(BOOLEAN)) { - return true; + return !IGNORE_REINDEX_FLAGS; } // reindex in the case this is a new node, even though the reindex flag // might be set to 'false' (possible via content import) @@ -316,6 +344,16 @@ public static class MissingIndexProviderStrategy { + /** + * The value of this flag determines the behavior of + * {@link #onMissingIndex(String, NodeBuilder, String)}. If + * {@code false} (default value), the method will set the + * {@code reindex} flag to true and log a warning. if {@code true}, the + * method will throw a {@link CommitFailedException} failing the commit. + */ + private boolean failOnMissingIndexProvider = Boolean + .getBoolean("IndexUpdate.failOnMissingIndexProvider"); + private final Set ignore = newHashSet("disabled"); public void onMissingIndex(String type, NodeBuilder definition, String indexPath) @@ -329,15 +367,26 @@ // already true, skip the update return; } - log.warn( - "Missing index provider of type [{}], requesting reindex on [{}]", - type, indexPath); - definition.setProperty(REINDEX_PROPERTY_NAME, true); + + if (failOnMissingIndexProvider) { + throw new CommitFailedException("IndexUpdate", 1, + "Missing index provider detected for type [" + type + + "] on index [" + indexPath + "]"); + } else { + log.warn( + "Missing index provider of type [{}], requesting reindex on [{}]", + type, indexPath); + definition.setProperty(REINDEX_PROPERTY_NAME, true); + } } boolean isDisabled(String type) { return ignore.contains(type); } + + void setFailOnMissingIndexProvider(boolean failOnMissingIndexProvider) { + this.failOnMissingIndexProvider = failOnMissingIndexProvider; + } } public IndexUpdate withMissingProviderStrategy( Index: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java (revision 1708313) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java (working copy) @@ -32,6 +32,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.Set; @@ -40,6 +41,7 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy; import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider; import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup; import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState; @@ -50,6 +52,7 @@ import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.Editor; import org.apache.jackrabbit.oak.spi.commit.EditorHook; +import org.apache.jackrabbit.oak.spi.commit.EditorProvider; import org.apache.jackrabbit.oak.spi.query.Filter; import org.apache.jackrabbit.oak.spi.query.PropertyValues; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; @@ -332,8 +335,7 @@ .getValue(Type.BOOLEAN)); assertTrue(ns1.getProperty(REINDEX_ASYNC_PROPERTY_NAME).getValue( Type.BOOLEAN)); - assertEquals(ASYNC_REINDEX_VALUE, ns1.getProperty(ASYNC_PROPERTY_NAME) - .getValue(Type.STRING)); + assertEquals(ASYNC_REINDEX_VALUE, ns1.getString(ASYNC_PROPERTY_NAME)); AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true); @@ -390,6 +392,47 @@ azerty.getProperty(REINDEX_PROPERTY_NAME)); } + /** + * OAK-3505 Provide an optionally stricter policy for missing synchronous + * index editor providers + */ + @Test + public void testMissingProviderFailsCommit() throws Exception { + + final IndexUpdateCallback noop = new IndexUpdateCallback() { + @Override + public void indexUpdate() { + } + }; + final MissingIndexProviderStrategy mips = new MissingIndexProviderStrategy(); + mips.setFailOnMissingIndexProvider(true); + + EditorHook hook = new EditorHook(new EditorProvider() { + @Override + public Editor getRootEditor(NodeState before, NodeState after, + NodeBuilder builder, CommitInfo info) + throws CommitFailedException { + return new IndexUpdate(emptyProvider(), null, after, builder, + noop).withMissingProviderStrategy(mips); + } + }); + + NodeState before = builder.getNodeState(); + + createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), + "rootIndex", true, false, ImmutableSet.of("foo"), null); + builder.child(INDEX_DEFINITIONS_NAME).child("azerty"); + builder.child("testRoot").setProperty("foo", "abc"); + NodeState after = builder.getNodeState(); + + try { + hook.processCommit(before, after, CommitInfo.EMPTY); + fail("commit should fail on missing index provider"); + } catch (CommitFailedException ex) { + // expected + } + } + @Test public void testReindexCount() throws Exception{ builder.child("testRoot").setProperty("foo", "abc");