Author: chetanm
Date: Tue Dec  6 10:32:24 2016
New Revision: 1772860

URL: http://svn.apache.org/viewvc?rev=1772860&view=rev
Log:
OAK-5219 - Reindexing for async indexes should only be done when IndexUpdate is 
running in async mode

Now any nrt/sync index would be invoked for indexing in incremental mode 
(reindex=false) even if first indexing or index is marked for reindex. Index 
implementations should be able to handle such scenario

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
    
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/hybrid/LocalIndexWriterFactoryTest.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=1772860&r1=1772859&r2=1772860&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
 Tue Dec  6 10:32:24 2016
@@ -199,6 +199,11 @@ public class IndexUpdate implements Edit
 
     private boolean shouldReindex(NodeBuilder definition, NodeState before,
             String name) {
+        //Async indexes are not considered for reindexing for sync indexing
+        if (!isMatchingIndexMode(definition)){
+            return false;
+        }
+
         PropertyState ps = definition.getProperty(REINDEX_PROPERTY_NAME);
         if (ps != null && ps.getValue(BOOLEAN)) {
             return !rootState.ignoreReindexFlags;
@@ -278,6 +283,27 @@ public class IndexUpdate implements Edit
         }
     }
 
+    /**
+     * Determines if the current indexing mode matches with the IndexUpdate 
mode.
+     * For this match it only considers indexes either as
+     * <ul>
+     *     <li>sync - Index definition does not have async property 
defined</li>
+     *     <li>async - Index definition has async property defined. It does 
not matter what its value is</li>
+     * </ul>
+     *
+     * <p>Same applies for IndexUpdate also.
+     *
+     * <p>Note that this differs from #isIncluded which also considers the 
value of <code>async</code>
+     * property to determine if the index should be selected for current 
IndexUpdate run.
+     */
+    private boolean isMatchingIndexMode(NodeBuilder definition){
+        boolean async = definition.hasProperty(ASYNC_PROPERTY_NAME);
+        //Either
+        // 1. async index and async index update
+        // 2. non async i.e. sync index and sync index update
+        return async == rootState.isAsync();
+    }
+
     private void incrementReIndexCount(NodeBuilder definition) {
         long count = 0;
         if(definition.hasProperty(REINDEX_COUNT)){
@@ -536,6 +562,10 @@ public class IndexUpdate implements Edit
             return false;
         }
 
+        public boolean isAsync(){
+            return async != null;
+        }
+
         public boolean isReindexingPerformed(){
             return !reindexedIndexes.isEmpty();
         }
@@ -614,7 +644,7 @@ public class IndexUpdate implements Edit
 
             @Override
             public boolean isAsync() {
-                return async != null;
+                return IndexUpdateRootState.this.isAsync();
             }
 
             @Override

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=1772860&r1=1772859&r2=1772860&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
 Tue Dec  6 10:32:24 2016
@@ -702,6 +702,26 @@ public class IndexUpdateTest {
         assertFalse(find(lookup, "foo", "xyz").isEmpty());
     }
 
+    @Test
+    public void shouldNotReindexAsyncIndexInSyncMode() throws Exception{
+        String indexPath = "/oak:index/rootIndex";
+        CallbackCapturingProvider provider = new CallbackCapturingProvider();
+
+        IndexUpdateProvider indexUpdate = new IndexUpdateProvider(provider);
+        EditorHook hook = new EditorHook(indexUpdate);
+
+        NodeState before = builder.getNodeState();
+        NodeBuilder idx = 
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
+                "rootIndex", true, false, ImmutableSet.of("foo"), null);
+        idx.setProperty("async", asList("async", "sync"), Type.STRINGS);
+
+        builder.child("a").setProperty("foo", "abc");
+        NodeState after = builder.getNodeState();
+
+        NodeState indexed = hook.processCommit(before, after, 
CommitInfo.EMPTY);
+        assertFalse(provider.getContext(indexPath).isReindexing());
+    }
+
     private static void markCorrupt(NodeBuilder builder, String indexName) {
         builder.getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(indexName)
                 .setProperty(IndexConstants.CORRUPT_PROPERTY_NAME, 
ISO8601.format(Calendar.getInstance()));

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=1772860&r1=1772859&r2=1772860&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
 Tue Dec  6 10:32:24 2016
@@ -105,7 +105,6 @@ public class LuceneIndexEditorContext {
                              ExtractedTextCache extractedTextCache,
                              IndexAugmentorFactory augmentorFactory,
                              IndexingContext indexingContext, boolean 
asyncIndexing) {
-        configureUniqueId(definition);
         this.root = root;
         this.indexingContext = checkNotNull(indexingContext);
         this.definitionBuilder = definition;

Modified: 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LocalIndexWriterFactoryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LocalIndexWriterFactoryTest.java?rev=1772860&r1=1772859&r2=1772860&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LocalIndexWriterFactoryTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LocalIndexWriterFactoryTest.java
 Tue Dec  6 10:32:24 2016
@@ -79,8 +79,8 @@ public class LocalIndexWriterFactoryTest
 
         //This is reindex case so nothing would be indexed
         //So now holder should be present in context
-        assertNull(getHolder());
-        assertNull(getCommitAttribute(LuceneDocumentHolder.NAME));
+        assertNotNull(getHolder());
+        assertNotNull(getCommitAttribute(LuceneDocumentHolder.NAME));
     }
 
     @Test


Reply via email to