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:17:21 UTC
svn commit: r1773175 - in /jackrabbit/oak/trunk/oak-lucene/src:
main/java/org/apache/jackrabbit/oak/plugins/index/lucene/
test/java/org/apache/jackrabbit/oak/plugins/index/lucene/
Author: chetanm
Date: Thu Dec 8 05:17:21 2016
New Revision: 1773175
URL: http://svn.apache.org/viewvc?rev=1773175&view=rev
Log:
OAK-4400 - Correlate index with the index definition used to build it
Stored the current index definition NodeState under hidden node ":index-definition" at time of reindexing and look for that node while constructing IndexDefinition instance
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
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/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java?rev=1773175&r1=1773174&r2=1773175&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java Thu Dec 8 05:17:21 2016
@@ -129,6 +129,12 @@ public final class IndexDefinition imple
static final String INDEX_VERSION = ":version";
/**
+ * Hidden node under index definition which is used to store the index definition
+ * nodestate as it was at time of reindexing
+ */
+ static final String INDEX_DEFINITION_NODE = ":index-definition";
+
+ /**
* Hidden node under index definition which is used to store meta info
*/
static final String STATUS_NODE = ":status";
@@ -299,7 +305,7 @@ public final class IndexDefinition imple
}
public IndexDefinition(NodeState root, NodeState defn, String indexPath) {
- this(root, defn, determineIndexFormatVersion(defn), determineUniqueId(defn), indexPath);
+ this(root, getIndexDefinitionState(defn), determineIndexFormatVersion(defn), determineUniqueId(defn), indexPath);
}
private IndexDefinition(NodeState root, NodeState defn, IndexFormatVersion version, String uid, String indexPath) {
@@ -1678,4 +1684,9 @@ public final class IndexDefinition imple
return Iterables.contains(async.getValue(Type.STRINGS), mode);
}
+ private static NodeState getIndexDefinitionState(NodeState defn) {
+ NodeState storedState = defn.getChildNode(INDEX_DEFINITION_NODE);
+ return storedState.exists() ? storedState : defn;
+ }
+
}
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=1773175&r1=1773174&r2=1773175&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:17:21 2016
@@ -98,6 +98,8 @@ public class LuceneIndexEditorContext {
//Set for testing ONLY
private static Clock clock = Clock.SIMPLE;
+ private final boolean indexDefnRewritten;
+
LuceneIndexEditorContext(NodeState root, NodeBuilder definition,
@Nullable IndexDefinition indexDefinition,
IndexUpdateCallback updateCallback,
@@ -117,7 +119,10 @@ public class LuceneIndexEditorContext {
this.augmentorFactory = augmentorFactory;
this.asyncIndexing = asyncIndexing;
if (this.definition.isOfOldFormat()){
+ indexDefnRewritten = true;
IndexDefinition.updateDefinition(definition, indexingContext.getIndexPath());
+ } else {
+ indexDefnRewritten = false;
}
}
@@ -181,11 +186,18 @@ public class LuceneIndexEditorContext {
reindex = true;
IndexFormatVersion version = IndexDefinition.determineVersionForFreshIndex(definitionBuilder);
definitionBuilder.setProperty(IndexDefinition.INDEX_VERSION, version.getVersion());
+
+ //Avoid obtaining the latest NodeState from builder as that would force purge of current transient state
+ //as index definition does not get modified as part of IndexUpdate run in most case we rely on base state
+ //For case where index definition is rewritten there we get fresh state
+ NodeState defnState = indexDefnRewritten ? definitionBuilder.getNodeState() : definitionBuilder.getBaseState();
+ definitionBuilder.setChildNode(IndexDefinition.INDEX_DEFINITION_NODE,
+ NodeStateCloner.cloneVisibleState(defnState));
String uid = configureUniqueId(definitionBuilder);
//Refresh the index definition based on update builder state
definition = IndexDefinition
- .newBuilder(root, definitionBuilder.getBaseState())
+ .newBuilder(root, defnState)
.indexPath(indexingContext.getIndexPath())
.version(version)
.uid(uid)
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=1773175&r1=1773174&r2=1773175&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:17:21 2016
@@ -138,6 +138,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
public class LucenePropertyIndexTest extends AbstractQueryTest {
/**
* Set the size to twice the batch size to test the pagination with sorting
@@ -158,6 +159,8 @@ public class LucenePropertyIndexTest ext
private NodeStore nodeStore;
+ private LuceneIndexProvider provider;
+
@After
public void after() {
new ExecutorCloser(executorService).close();
@@ -172,7 +175,7 @@ public class LucenePropertyIndexTest ext
protected ContentRepository createRepository() {
IndexCopier copier = createIndexCopier();
editorProvider = new LuceneIndexEditorProvider(copier, new ExtractedTextCache(10* FileUtils.ONE_MB, 100));
- LuceneIndexProvider provider = new LuceneIndexProvider(copier);
+ provider = new LuceneIndexProvider(copier);
nodeStore = new MemoryNodeStore();
return new Oak(nodeStore)
.with(new InitialContent())
@@ -804,6 +807,7 @@ public class LucenePropertyIndexTest ext
//set propb def to be node scope indexed
propTree = root.getTree(idx.getPath() + "/indexRules/nt:base/properties/propb");
propTree.setProperty(PROP_NODE_SCOPE_INDEX, true);
+ root.getTree(idx.getPath()).setProperty(REINDEX_PROPERTY_NAME, true);
root.commit();
Tree rootTree = root.getTree("/");
@@ -2424,6 +2428,35 @@ public class LucenePropertyIndexTest ext
assertPlanAndQuery("select * from [oak:TestMixA]", "lucene:test1(/oak:index/test1)", asList("/b", "/c"));
}
+ @Test
+ public void indexDefinitionModifiedPostReindex() 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();
+
+ String query = "select * from [nt:base] where [foo] = 'bar'";
+ assertPlanAndQuery(query, "lucene:test1(/oak:index/test1)", asList("/a"));
+
+ Tree barProp = root.getTree("/oak:index/test1/indexRules/nt:base/properties").addChild("bar");
+ barProp.setProperty("name", "bar");
+ barProp.setProperty("propertyIndex", true);
+ root.commit();
+
+ query = "select * from [nt:base] where [bar] = 'bar'";
+ assertThat(explain(query), not(containsString("lucene:test1(/oak:index/test1)")));
+
+ root.getTree("/oak:index/test1").setProperty(REINDEX_PROPERTY_NAME, true);
+ root.commit();
+
+ assertPlanAndQuery(query, "lucene:test1(/oak:index/test1)", asList("/b"));
+ }
+
private void assertPlanAndQuery(String query, String planExpectation, List<String> paths){
assertThat(explain(query), containsString(planExpectation));
assertQuery(query, paths);