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/08 05:18:24 UTC
svn commit: r1773181 - in /jackrabbit/oak/trunk/oak-lucene/src:
main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Author: chetanm
Date: Thu Dec 8 05:18:24 2016
New Revision: 1773181
URL: http://svn.apache.org/viewvc?rev=1773181&view=rev
Log:
OAK-4400 - Correlate index with the index definition used to build it
In case of upgrade now cloned index definition would be stored upon first increment indexing of old index
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java?rev=1773181&r1=1773180&r2=1773181&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java Thu Dec 8 05:18:24 2016
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
import org.apache.jackrabbit.oak.stats.Clock;
import org.apache.jackrabbit.oak.util.PerfLogger;
import org.apache.jackrabbit.util.ISO8601;
@@ -282,10 +283,20 @@ public class LuceneIndexEditorContext {
private static IndexDefinition createIndexDefinition(NodeState root, NodeBuilder definition, IndexingContext
indexingContext, boolean asyncIndexing) {
NodeState defnState = definition.getBaseState();
- if (definition.getBoolean(LuceneIndexConstants.PROP_REFRESH_DEFN) && asyncIndexing){
- definition.removeProperty(LuceneIndexConstants.PROP_REFRESH_DEFN);
- definition.setChildNode(IndexDefinition.INDEX_DEFINITION_NODE, NodeStateCloner.cloneVisibleState(defnState));
- log.info("Refreshed the index definition for [{}]", indexingContext.getIndexPath());
+ if (asyncIndexing){
+ if (definition.getBoolean(LuceneIndexConstants.PROP_REFRESH_DEFN)){
+ definition.removeProperty(LuceneIndexConstants.PROP_REFRESH_DEFN);
+ NodeState clonedState = NodeStateCloner.cloneVisibleState(defnState);
+ definition.setChildNode(IndexDefinition.INDEX_DEFINITION_NODE, clonedState);
+ log.info("Refreshed the index definition for [{}]", indexingContext.getIndexPath());
+ if (log.isDebugEnabled()){
+ log.debug("Updated index definition is {}", NodeStateUtils.toString(clonedState));
+ }
+ } else if (!definition.hasChildNode(IndexDefinition.INDEX_DEFINITION_NODE)){
+ definition.setChildNode(IndexDefinition.INDEX_DEFINITION_NODE, NodeStateCloner.cloneVisibleState(defnState));
+ log.info("Stored the cloned index definition for [{}]. Changes in index definition would now only be " +
+ "effective post reindexing", indexingContext.getIndexPath());
+ }
}
return new IndexDefinition(root, defnState,indexingContext.getIndexPath());
}
Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1773181&r1=1773180&r2=1773181&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java Thu Dec 8 05:18:24 2016
@@ -41,6 +41,7 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.PathFilter.PROP_EXCLUDED_PATHS;
import static org.apache.jackrabbit.oak.plugins.index.PathFilter.PROP_INCLUDED_PATHS;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition.INDEX_DEFINITION_NODE;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.ANALYZERS;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_NAMES;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.ORDERED_PROP_NAMES;
@@ -54,6 +55,7 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PROP_TYPE;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.TIKA;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorTest.createCal;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.child;
import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.newNodeAggregator;
import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.useV2;
import static org.apache.jackrabbit.oak.plugins.index.property.OrderedIndex.OrderDirection;
@@ -121,6 +123,7 @@ import org.apache.jackrabbit.oak.query.A
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.Editor;
import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
import org.apache.jackrabbit.oak.spi.commit.Observer;
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
@@ -2492,6 +2495,36 @@ public class LucenePropertyIndexTest ext
assertPlanAndQuery(query, "lucene:test1(/oak:index/test1)", Collections.<String>emptyList());
}
+ @Test
+ public void updateOldIndexDefinition() throws Exception{
+ IndexDefinitionBuilder idxb = new IndexDefinitionBuilder().noAsync();
+ idxb.indexRule("nt:base").property("foo").propertyIndex();
+ Tree idx = root.getTree("/").getChild("oak:index").addChild("test1");
+ idxb.build(idx);
+
+ Tree rootTree = root.getTree("/");
+ rootTree.addChild("a").setProperty("foo", "bar");
+ rootTree.addChild("b").setProperty("bar", "bar");
+ root.commit();
+
+ //Cannot use Tree api as it cannot read hidden tree
+ String clonedDefnPath = "/oak:index/test1/" + INDEX_DEFINITION_NODE;
+ assertTrue(NodeStateUtils.getNode(nodeStore.getRoot(), clonedDefnPath).exists());
+
+ NodeBuilder builder = nodeStore.getRoot().builder();
+ child(builder, clonedDefnPath).remove();
+ nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+ root.rebase();
+ rootTree = root.getTree("/");
+ rootTree.addChild("c").setProperty("foo", "bar");
+ root.commit();
+
+ //Definition state should be recreated
+ assertTrue(NodeStateUtils.getNode(nodeStore.getRoot(), clonedDefnPath).exists());
+
+ }
+
private void assertPlanAndQuery(String query, String planExpectation, List<String> paths){
assertThat(explain(query), containsString(planExpectation));
assertQuery(query, paths);