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 2017/10/05 09:53:40 UTC

svn commit: r1811181 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/pro...

Author: chetanm
Date: Thu Oct  5 09:53:40 2017
New Revision: 1811181

URL: http://svn.apache.org/viewvc?rev=1811181&view=rev
Log:
OAK-6781 - Reindex handling with synchronous lucene property indexes

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
    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
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexUpdateCallback.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/SynchronousPropertyIndexTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java?rev=1811181&r1=1811180&r2=1811181&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java Thu Oct  5 09:53:40 2017
@@ -119,4 +119,10 @@ public interface IndexConstants {
      */
     String INDEX_NAME_OPTION = ":indexName";
 
+    /**
+     * Boolean property on any index node indicating that such a node should not be
+     * removed during reindex
+     */
+    String REINDEX_RETAIN = "retainNodeInReindex";
+
 }

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=1811181&r1=1811180&r2=1811181&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 Thu Oct  5 09:53:40 2017
@@ -234,6 +234,10 @@ public class IndexUpdate implements Edit
     private static boolean hasAnyHiddenNodes(NodeBuilder builder){
         for (String name : builder.getChildNodeNames()) {
             if (NodeStateUtils.isHidden(name)){
+                NodeBuilder childNode = builder.getChildNode(name);
+                if (childNode.getBoolean(IndexConstants.REINDEX_RETAIN)) {
+                    continue;
+                }
                 return true;
             }
         }
@@ -272,13 +276,7 @@ public class IndexUpdate implements Edit
                     } else {
                         definition.setProperty(REINDEX_PROPERTY_NAME, false);
                         incrementReIndexCount(definition);
-                        // as we don't know the index content node name
-                        // beforehand, we'll remove all child nodes
-                        for (String rm : definition.getChildNodeNames()) {
-                            if (NodeStateUtils.isHidden(rm)) {
-                                definition.getChildNode(rm).remove();
-                            }
-                        }
+                        removeIndexState(definition);
 
                         clearCorruptFlag(definition, indexPath);
                         reindex.put(concat(getPath(), INDEX_DEFINITIONS_NAME, name), editor);
@@ -288,6 +286,19 @@ public class IndexUpdate implements Edit
                 }
             }
         }
+    }
+
+    private void removeIndexState(NodeBuilder definition) {
+        // as we don't know the index content node name
+        // beforehand, we'll remove all child nodes
+        for (String rm : definition.getChildNodeNames()) {
+            if (NodeStateUtils.isHidden(rm)) {
+                NodeBuilder childNode = definition.getChildNode(rm);
+                if (!childNode.getBoolean(IndexConstants.REINDEX_RETAIN)) {
+                    definition.getChildNode(rm).remove();
+                }
+            }
+        }
     }
 
     private long getEstimatedCount(NodeBuilder indexDefinition) {

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=1811181&r1=1811180&r2=1811181&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 Thu Oct  5 09:53:40 2017
@@ -25,6 +25,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_ASYNC_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_COUNT;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefinition;
 import static org.apache.jackrabbit.oak.InitialContent.INITIAL_CONTENT;
@@ -336,6 +337,59 @@ public class IndexUpdateTest {
 
     }
 
+    /**
+     * Tests that with explicit reindex i.e. reindex=true those hidden nodes
+     * which have IndexConstants.REINDEX_RETAIN set to true are not removed
+     */
+    @Test
+    public void reindexSkipRemovalOfRetainedNodes() throws Exception{
+        builder.child("testRoot").setProperty("foo", "abc");
+        NodeState before = builder.getNodeState();
+
+        NodeBuilder nb = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
+                "rootIndex", true, false, ImmutableSet.of("foo"), null);
+        nb.child(":hidden-node-1").setProperty("foo", "bar");
+        nb.child(":hidden-node-2").setProperty(IndexConstants.REINDEX_RETAIN, true);
+        nb.child("visible-node");
+
+        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, "visible-node");
+        checkPathExists(ns, ":hidden-node-2");
+        assertFalse(ns.getChildNode(":hidden-node-1").exists());
+        assertEquals(1, ns.getLong(REINDEX_COUNT));
+    }
+
+    /**
+     * Test that an index is still reindexed if it has hidden nodes but with all such
+     * hidden nodes having IndexConstants.REINDEX_RETAIN set to true i.e. this index
+     * does not yet have any hidden nodes corresponding to persisted index like lucene
+     */
+    @Test
+    public void reindexSkipRemovalOfRetainedNodes_FreshIndex() throws Exception{
+        builder.child("testRoot").setProperty("foo", "abc");
+        NodeState before = builder.getNodeState();
+
+        NodeBuilder nb = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
+                "rootIndex", false, false, ImmutableSet.of("foo"), null);
+        nb.child(":hidden-node-2").setProperty(IndexConstants.REINDEX_RETAIN, true);
+        nb.child("visible-node");
+
+        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, "visible-node");
+        checkPathExists(ns, ":hidden-node-2");
+        assertEquals(1, ns.getLong(REINDEX_COUNT));
+    }
+
 
     /**
      * Async Reindex Test (OAK-2174)

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexUpdateCallback.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexUpdateCallback.java?rev=1811181&r1=1811180&r2=1811181&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexUpdateCallback.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexUpdateCallback.java Thu Oct  5 09:53:40 2017
@@ -27,6 +27,7 @@ import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.lucene.PropertyDefinition;
 import org.apache.jackrabbit.oak.plugins.index.lucene.PropertyUpdateCallback;
 import org.apache.jackrabbit.oak.plugins.index.property.ValuePattern;
@@ -129,6 +130,10 @@ public class PropertyIndexUpdateCallback
     private NodeBuilder getIndexNode(String propertyRelativePath, boolean unique) {
         NodeBuilder propertyIndex = builder.child(PROPERTY_INDEX);
 
+        if (propertyIndex.isNew()) {
+            propertyIndex.setProperty(IndexConstants.REINDEX_RETAIN, true);
+        }
+
         String nodeName = HybridPropertyIndexUtil.getNodeName(propertyRelativePath);
         if (unique) {
             return getUniqueIndexBuilder(propertyIndex, nodeName);

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/SynchronousPropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/SynchronousPropertyIndexTest.java?rev=1811181&r1=1811180&r2=1811181&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/SynchronousPropertyIndexTest.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/SynchronousPropertyIndexTest.java Thu Oct  5 09:53:40 2017
@@ -326,7 +326,6 @@ public class SynchronousPropertyIndexTes
 
     }
 
-    @Ignore("OAK-6781")
     @Test
     public void asyncIndexerReindexAndPropertyIndexes() throws Exception{
         defnb.async("async", "nrt");