From e80415733d755e15770859e2007fe838c65ad7b7 Mon Sep 17 00:00:00 2001 From: Vikas Saurabh Date: Thu, 15 Sep 2016 03:24:44 +0530 Subject: [PATCH] OAK-4805: Misconfigured lucene index definition can render the whole system unusable --- .../plugins/index/lucene/LucenePropertyIndex.java | 3 +++ .../index/lucene/LucenePropertyIndexTest.java | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java index 1ca79b8..55b61b8 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java @@ -244,6 +244,9 @@ public class LucenePropertyIndex implements AdvancedQueryIndex, QueryIndex, Nati plans.add(plan); } } + } catch (IllegalArgumentException iae) { + LOG.error("Error getting plan for {}", path); + LOG.error("Exception:", iae); } finally { if (indexNode != null) { indexNode.release(); diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java index 8bb33a8..07c026e 100644 --- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java +++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java @@ -32,6 +32,7 @@ import static org.apache.jackrabbit.oak.api.QueryEngine.NO_BINDINGS; import static org.apache.jackrabbit.oak.api.QueryEngine.NO_MAPPINGS; import static org.apache.jackrabbit.oak.api.Type.NAMES; import static org.apache.jackrabbit.oak.api.Type.STRINGS; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ASYNC_PROPERTY_NAME; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES; 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; @@ -241,6 +242,27 @@ public class LucenePropertyIndexTest extends AbstractQueryTest { assertQuery("select * from [nt:base] where CONTAINS(*, 'fox was jumping')", asList("/test")); } + //OAK-4805 + @Test + public void badIndexDefinitionShouldLetQEWork() throws Exception { + Tree idx = createFulltextIndex(root.getTree("/"), "badIndex"); + TestUtil.useV2(idx); + + //This would allow index def to get committed. Else bad index def can't be created. + idx.setProperty(ASYNC_PROPERTY_NAME, "async"); + + Tree anl = idx.addChild(LuceneIndexConstants.ANALYZERS).addChild(LuceneIndexConstants.ANL_DEFAULT); + anl.addChild(LuceneIndexConstants.ANL_TOKENIZER).setProperty(LuceneIndexConstants.ANL_NAME, "Standard"); + Tree synFilter = anl.addChild(LuceneIndexConstants.ANL_FILTERS).addChild("Synonym"); + synFilter.setProperty("synonyms", "syn.txt"); + // Don't add syn.txt to make analyzer (and hence index def) invalid + // synFilter.addChild("syn.txt").addChild(JCR_CONTENT).setProperty(JCR_DATA, "blah, foo, bar"); + root.commit(); + + //Using this version of executeQuery as we don't want a result row quoting the exception + executeQuery("SELECT * FROM [nt:base] where a='b'", SQL2, NO_BINDINGS); + } + private Tree createFulltextIndex(Tree index, String name) throws CommitFailedException { Tree def = index.addChild(INDEX_DEFINITIONS_NAME).addChild(name); def.setProperty(JcrConstants.JCR_PRIMARYTYPE, -- 2.8.3