Author: chetanm
Date: Thu Sep 15 07:14:32 2016
New Revision: 1760833

URL: http://svn.apache.org/viewvc?rev=1760833&view=rev
Log:
OAK-4412 - Lucene hybrid index

Avoid creation of IndexDefinition instance if possible for sync indexing by 
reusing the definition from tracker. This would ensure that slightly expensive 
operation of constructing IndexDefinition is not performed for each commit and 
keeps overhead of indexing low

Modified:
    
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTracker.java
    
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
    
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java
    
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java

Modified: 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTracker.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTracker.java?rev=1760833&r1=1760832&r2=1760833&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTracker.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTracker.java
 Thu Sep 15 07:14:32 2016
@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
 import org.apache.jackrabbit.oak.commons.PathUtils;
@@ -171,6 +172,17 @@ public class IndexTracker {
         }
     }
 
+    @CheckForNull
+    public IndexDefinition getIndexDefinition(String indexPath){
+        IndexNode node = indices.get(indexPath);
+        if (node != null){
+            //Accessing the definition should not require
+            //locking as its immutable state
+            return node.getDefinition();
+        }
+        return null;
+    }
+
     Set<String> getIndexNodePaths(){
         return indices.keySet();
     }

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=1760833&r1=1760832&r2=1760833&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 Sep 15 07:14:32 2016
@@ -23,6 +23,8 @@ import java.util.Calendar;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
+import javax.annotation.Nullable;
+
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
@@ -91,7 +93,9 @@ public class LuceneIndexEditorContext {
     //Set for testing ONLY
     private static Clock clock = Clock.SIMPLE;
 
-    LuceneIndexEditorContext(NodeState root, NodeBuilder definition, 
IndexUpdateCallback updateCallback,
+    LuceneIndexEditorContext(NodeState root, NodeBuilder definition,
+                             @Nullable IndexDefinition indexDefinition,
+                             IndexUpdateCallback updateCallback,
                              LuceneIndexWriterFactory indexWriterFactory,
                              ExtractedTextCache extractedTextCache,
                              IndexAugmentorFactory augmentorFactory) {
@@ -99,7 +103,7 @@ public class LuceneIndexEditorContext {
         this.root = root;
         this.definitionBuilder = definition;
         this.indexWriterFactory = indexWriterFactory;
-        this.definition = new IndexDefinition(root, definition);
+        this.definition = indexDefinition != null ? indexDefinition : new 
IndexDefinition(root, definition);
         this.indexedNodes = 0;
         this.updateCallback = updateCallback;
         this.extractedTextCache = extractedTextCache;

Modified: 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java?rev=1760833&r1=1760832&r2=1760833&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java
 Thu Sep 15 07:14:32 2016
@@ -54,6 +54,7 @@ public class LuceneIndexEditorProvider i
     private final ExtractedTextCache extractedTextCache;
     private final IndexAugmentorFactory augmentorFactory;
     private final LuceneIndexWriterFactory indexWriterFactory;
+    private final IndexTracker indexTracker;
 
     public LuceneIndexEditorProvider() {
         this(null);
@@ -73,7 +74,16 @@ public class LuceneIndexEditorProvider i
                                      ExtractedTextCache extractedTextCache,
                                      @Nullable IndexAugmentorFactory 
augmentorFactory,
                                      MountInfoProvider mountInfoProvider) {
+        this(indexCopier, null, extractedTextCache, augmentorFactory, 
mountInfoProvider);
+    }
+
+    public LuceneIndexEditorProvider(@Nullable IndexCopier indexCopier,
+                                     @Nullable IndexTracker indexTracker,
+                                     ExtractedTextCache extractedTextCache,
+                                     @Nullable IndexAugmentorFactory 
augmentorFactory,
+                                     MountInfoProvider mountInfoProvider) {
         this.indexCopier = indexCopier;
+        this.indexTracker = indexTracker;
         this.extractedTextCache = extractedTextCache != null ? 
extractedTextCache : new ExtractedTextCache(0, 0);
         this.augmentorFactory = augmentorFactory;
         this.indexWriterFactory = new 
DefaultIndexWriterFactory(checkNotNull(mountInfoProvider), indexCopier);
@@ -89,6 +99,7 @@ public class LuceneIndexEditorProvider i
                     "ContextAwareCallback [%s]", callback);
             IndexingContext indexingContext = 
((ContextAwareCallback)callback).getIndexingContext();
             LuceneIndexWriterFactory writerFactory = indexWriterFactory;
+            IndexDefinition indexDefinition = null;
             if (!indexingContext.isAsync() && 
supportsSyncIndexing(definition)) {
 
                 //Would not participate in reindexing. Only interested in
@@ -97,12 +108,17 @@ public class LuceneIndexEditorProvider i
                     return null;
                 }
                 //TODO [hybrid] switch the builder to readonly one
-                //TODO [hybrid] Make use of existing IndexDefinition to avoid 
reinit for
-                //every commit
                 writerFactory = new LocalIndexWriterFactory(indexingContext);
+
+                //IndexDefinition from tracker might differ from one passed 
here for reindexing
+                //case which should be fine. However reusing existing 
definition would avoid
+                //creating definition instance for each commit as this gets 
executed for each commit
+                if (indexTracker != null){
+                    indexDefinition = 
indexTracker.getIndexDefinition(indexingContext.getIndexPath());
+                }
             }
 
-            LuceneIndexEditorContext context = new 
LuceneIndexEditorContext(root, definition, callback,
+            LuceneIndexEditorContext context = new 
LuceneIndexEditorContext(root, definition, indexDefinition, callback,
                     writerFactory, extractedTextCache, augmentorFactory);
             return new LuceneIndexEditor(context);
         }

Modified: 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java?rev=1760833&r1=1760832&r2=1760833&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/HybridIndexTest.java
 Thu Sep 15 07:14:32 2016
@@ -90,16 +90,18 @@ public class HybridIndexTest extends Abs
             throw new RuntimeException(e);
         }
         MountInfoProvider mip = defaultMountInfoProvider();
-        LuceneIndexEditorProvider editorProvider = new 
LuceneIndexEditorProvider(copier,
-                null,
-                null,
-                mip);
 
         NRTIndexFactory nrtIndexFactory = new NRTIndexFactory(copier);
         LuceneIndexReaderFactory indexReaderFactory = new 
DefaultIndexReaderFactory(mip, copier);
         IndexTracker tracker = new 
IndexTracker(indexReaderFactory,nrtIndexFactory);
         LuceneIndexProvider provider = new LuceneIndexProvider(tracker);
 
+        LuceneIndexEditorProvider editorProvider = new 
LuceneIndexEditorProvider(copier,
+                tracker,
+                null,
+                null,
+                mip);
+
         queue = new DocumentQueue(100, tracker, clock, sameThreadExecutor());
         LocalIndexObserver localIndexObserver = new LocalIndexObserver(queue);
 


Reply via email to