Author: chetanm
Date: Thu Sep 15 07:21:57 2016
New Revision: 1760875

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

Benchmarking - Bootstrap a fulltext index for both property and nrt case. This 
would bring it closer to real life as there async index job would be taking cpu 
cycle for async work. With nrt we would just have one extra editor 
participating in diff.

Modified:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java?rev=1760875&r1=1760874&r2=1760875&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java
 Thu Sep 15 07:21:57 2016
@@ -48,6 +48,7 @@ import com.google.common.collect.Iterato
 import com.google.common.util.concurrent.MoreExecutors;
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean;
 import org.apache.jackrabbit.oak.fixture.JcrCreator;
 import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture;
 import org.apache.jackrabbit.oak.fixture.RepositoryFixture;
@@ -56,6 +57,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
 import org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier;
 import org.apache.jackrabbit.oak.plugins.index.lucene.IndexTracker;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants;
 import 
org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider;
 import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue;
@@ -110,6 +112,7 @@ public class HybridIndexTest extends Abs
     private int asyncInterval = Integer.getInteger("asyncInterval", 5);
     private int queueSize = Integer.getInteger("queueSize", 1000);
     private boolean hybridIndexEnabled = 
Boolean.getBoolean("hybridIndexEnabled");
+    private boolean dumpStats = Boolean.getBoolean("dumpStats");
     private boolean useOakCodec = Boolean.getBoolean("useOakCodec");
     private String indexingMode = System.getProperty("indexingMode", "nrt");
 
@@ -146,17 +149,24 @@ public class HybridIndexTest extends Abs
                 @Override
                 public Jcr customize(Oak oak) {
                     Jcr jcr = new Jcr(oak);
+                    prepareLuceneIndexer(workDir);
+                    jcr.with((QueryIndexProvider) luceneIndexProvider)
+                            .with((Observer) luceneIndexProvider)
+                            .with(luceneEditorProvider);
+
                     if (hybridIndexEnabled) {
-                        prepareLuceneIndexer(workDir);
-                        jcr.with((QueryIndexProvider) luceneIndexProvider)
-                                .with((Observer) luceneIndexProvider)
-                                .with(localIndexObserver)
-                                .with(luceneEditorProvider);
+                        jcr.with(localIndexObserver);
                         indexInitializer = new LuceneIndexInitializer();
                     }
+
                     whiteboard = oak.getWhiteboard();
                     jcr.with(indexInitializer);
 
+                    //Configure the default global fulltext index as it impacts
+                    //both pure property index based setup and nrt based
+                    //So more closer to real world
+                    jcr.with(new LuceneFullTextInitializer());
+
                     //Async indexing is enabled for both property and lucene
                     //as for property it relies on counter index
                     oak.withAsyncIndexing("async", asyncInterval);
@@ -219,11 +229,13 @@ public class HybridIndexTest extends Abs
 
     @Override
     protected void afterSuite() throws Exception {
+        //TODO This to avoid issue with Indexing still running post afterSuite 
call
+        //TO handle this properly we would need a callback after repository 
shutdown
+        //and before NodeStore teardown
+        getAsyncIndexUpdate().close();
+
+        //Close hybrid stuff after async is closed
         if (hybridIndexEnabled){
-            //TODO This to avoid issue with Indexing still running post 
afterSuite call
-            //TO handle this properly we would need a callback after 
repository shutdown
-            //and before NodeStore teardown
-            getAsyncIndexUpdate().close();
             queue.close();
             nrtIndexFactory.close();
         }
@@ -235,6 +247,10 @@ public class HybridIndexTest extends Abs
                         "hybridIndexEnabled: %s, indexingMode: %s, 
useOakCodec: %s %n",
                 numOfIndexes, refreshDeltaMillis, asyncInterval, queueSize, 
hybridIndexEnabled,
                 indexingMode, useOakCodec);
+
+        if (dumpStats) {
+            dumpStats();
+        }
     }
 
     @Override
@@ -266,7 +282,6 @@ public class HybridIndexTest extends Abs
         }
 
         commentElements.add("numIdxs:"+ numOfIndexes);
-        commentElements.add("async:"+ asyncInterval);
         return Joiner.on(',').join(commentElements);
     }
 
@@ -303,7 +318,7 @@ public class HybridIndexTest extends Abs
     private void prepareLuceneIndexer(File workDir) {
         try {
             indexCopierDir = createTemporaryFolderIn(workDir);
-            copier = new IndexCopier(executorService, indexCopierDir);
+            copier = new IndexCopier(executorService, indexCopierDir, true);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -337,6 +352,11 @@ public class HybridIndexTest extends Abs
             });
     }
 
+    private void dumpStats() {
+        IndexStatsMBean indexStats = WhiteboardUtils.getService(whiteboard, 
IndexStatsMBean.class);
+        System.out.println(indexStats.getConsolidatedExecutionStats());
+    }
+
     @SuppressWarnings("ResultOfMethodCallIgnored")
     private static File createTemporaryFolderIn(File parentFolder) throws 
IOException {
         File createdFolder = File.createTempFile("oak-", "", parentFolder);
@@ -374,7 +394,7 @@ public class HybridIndexTest extends Abs
 
             IndexDefinitionBuilder defnBuilder = new IndexDefinitionBuilder();
             defnBuilder.evaluatePathRestrictions();
-            defnBuilder.async("async", indexingMode);
+            defnBuilder.async("async", indexingMode, "async");
             
defnBuilder.indexRule("nt:base").property(indexedPropName).propertyIndex();
             if (useOakCodec) {
                 defnBuilder.codec("oakCodec");
@@ -388,6 +408,21 @@ public class HybridIndexTest extends Abs
         }
     }
 
+    private class LuceneFullTextInitializer implements RepositoryInitializer {
+        @Override
+        public void initialize(@Nonnull NodeBuilder builder) {
+            NodeBuilder oakIndex = IndexUtils.getOrCreateOakIndex(builder);
+
+            IndexDefinitionBuilder defnBuilder = new IndexDefinitionBuilder();
+            defnBuilder.async("async", "async");
+            defnBuilder.codec("Lucene46");
+            defnBuilder.indexRule("nt:base")
+                    .property(LuceneIndexConstants.REGEX_ALL_PROPS, true)
+                    .nodeScopeIndex();
+            oakIndex.setChildNode("globalIndex", defnBuilder.build());
+        }
+    }
+
     private class Searcher implements Runnable {
         final Session session = loginWriter();
         int resultSize = 0;


Reply via email to