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 al...@apache.org on 2014/06/11 16:59:11 UTC
svn commit: r1601922 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
Author: alexparvulescu
Date: Wed Jun 11 14:59:11 2014
New Revision: 1601922
URL: http://svn.apache.org/r1601922
Log:
OAK-1874 Indexes: re-index automatically when adding an index
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java?rev=1601922&r1=1601921&r2=1601922&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java Wed Jun 11 14:59:11 2014
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.newArrayListWithCapacity;
+import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ASYNC_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ASYNC_REINDEX_VALUE;
@@ -108,7 +109,7 @@ public class IndexUpdate implements Edit
@Override
public void enter(NodeState before, NodeState after)
throws CommitFailedException {
- collectIndexEditors(builder.getChildNode(INDEX_DEFINITIONS_NAME));
+ collectIndexEditors(builder.getChildNode(INDEX_DEFINITIONS_NAME), before);
// no-op when reindex is empty
CommitFailedException exception = EditorDiff.process(
@@ -122,17 +123,30 @@ public class IndexUpdate implements Edit
}
}
- private void collectIndexEditors(NodeBuilder definitions)
- throws CommitFailedException {
+ private boolean shouldReindex(NodeBuilder definition, NodeState before,
+ String name) {
+ PropertyState ps = definition.getProperty(REINDEX_PROPERTY_NAME);
+ if (ps != null && ps.getValue(BOOLEAN)) {
+ return true;
+ }
+ // reindex in the case this is a new node, even though the reindex flag
+ // might be set to 'false' (possible via content import)
+ return !before.getChildNode(INDEX_DEFINITIONS_NAME).hasChildNode(name);
+ }
+
+ private void collectIndexEditors(NodeBuilder definitions,
+ NodeState before) throws CommitFailedException {
for (String name : definitions.getChildNodeNames()) {
NodeBuilder definition = definitions.getChildNode(name);
if (Objects.equal(async, definition.getString(ASYNC_PROPERTY_NAME))) {
String type = definition.getString(TYPE_PROPERTY_NAME);
+ boolean shouldReindex = shouldReindex(definition,
+ before, name);
Editor editor = provider.getIndexEditor(type, definition, root, updateCallback);
if (editor == null) {
// trigger reindexing when an indexer becomes available
definition.setProperty(REINDEX_PROPERTY_NAME, true);
- } else if (definition.getBoolean(REINDEX_PROPERTY_NAME)) {
+ } else if (shouldReindex) {
if (definition.getBoolean(REINDEX_ASYNC_PROPERTY_NAME)
&& definition.getString(ASYNC_PROPERTY_NAME) == null) {
// switch index to an async update mode
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java?rev=1601922&r1=1601921&r2=1601922&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java Wed Jun 11 14:59:11 2014
@@ -172,6 +172,39 @@ public class IndexUpdateTest {
assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
+ /**
+ * Auto Reindex Test
+ * <ul>
+ * <li>Add some content</li>
+ * <li>Add an index definition without a reindex flag (see OAK-1874)</li>
+ * <li>Search & verify</li>
+ * </ul>
+ */
+ @Test
+ public void testReindexAuto() throws Exception {
+ builder.child("testRoot").setProperty("foo", "abc");
+ NodeState before = builder.getNodeState();
+
+ createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
+ "rootIndex", false, false, ImmutableSet.of("foo"), null);
+
+ NodeState after = builder.getNodeState();
+
+ NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
+
+ // first check that the index content nodes exist
+ NodeState ns = checkPathExists(indexed, INDEX_DEFINITIONS_NAME,
+ "rootIndex");
+ checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
+ PropertyState ps = ns.getProperty(REINDEX_PROPERTY_NAME);
+ assertNotNull(ps);
+ assertFalse(ps.getValue(Type.BOOLEAN));
+
+ // next, lookup
+ PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
+ assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
+ }
+
@Test
public void testIndexDefinitions() throws Exception {
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),