jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1464936 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ oak-lucene/...
Date Fri, 05 Apr 2013 12:12:57 GMT
Author: alexparvulescu
Date: Fri Apr  5 12:12:56 2013
New Revision: 1464936

URL: http://svn.apache.org/r1464936
Log:
OAK-756 Allow reindexing to use Editors

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java
Fri Apr  5 12:12:56 2013
@@ -16,27 +16,40 @@
  */
 package org.apache.jackrabbit.oak.plugins.index;
 
+import javax.annotation.CheckForNull;
+
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * Represents the content of a QueryIndex as well as a mechanism for keeping
- * this content up to date.
- * <br>
+ * this content up to date. <br>
  * An IndexHook listens for changes to the content and updates the index data
  * accordingly.
  */
 public interface IndexHook extends Editor {
 
     /**
-     * Re-create this index using the given state
+     * Return an editor that can be used to recreate this index, or
+     * <code>null</code> if reindexing is not required or is taken care of by
+     * the impl directly using the provided state as a reference <br>
+     * <br>
+     * By providing an Editor an impl could help the IndexManager gain some
+     * performance on account of doing the reindexing in parallel for all
+     * indexers <br>
+     * <br>
+     * <i>Note:</i> All the existing IndexHook impls require a call to
+     * {@link #enter(NodeState, NodeState)} to build initial state before
+     * calling {@link #reindex(NodeState)}, this is enforced via the
+     * IndexManager.
      * 
      * @param state
-     *            the parent of the node "oak:index" (the node that contains the
-     *            index definition)
-     * @throws CommitFailedException
+     *            state can be used to reindex inside the IndexHook directly,
+     *            instead of providing an Editor
+     * 
      */
-    void reindex(NodeState state) throws CommitFailedException;
+    @CheckForNull
+    Editor reindex(NodeState state) throws CommitFailedException;
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
Fri Apr  5 12:12:56 2013
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
+import org.apache.jackrabbit.oak.spi.commit.VisibleEditor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -44,6 +45,6 @@ public class IndexHookManager implements
     @Override
     public Editor getRootEditor(NodeState before, NodeState after,
             NodeBuilder builder) {
-        return new IndexHookManagerDiff(provider, builder);
+        return VisibleEditor.wrap(new IndexHookManagerDiff(provider, builder));
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
Fri Apr  5 12:12:56 2013
@@ -22,6 +22,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_UNKNOWN;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 
 import java.util.HashSet;
 import java.util.List;
@@ -33,9 +34,11 @@ import org.apache.jackrabbit.oak.api.Typ
 import org.apache.jackrabbit.oak.spi.commit.CompositeEditor;
 import org.apache.jackrabbit.oak.spi.commit.DefaultEditor;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.apache.jackrabbit.oak.spi.commit.EditorHook;
+import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
+import org.apache.jackrabbit.oak.spi.commit.VisibleEditor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
 
 import com.google.common.collect.Lists;
 
@@ -101,17 +104,43 @@ class IndexHookManagerDiff implements Ed
                     hooks.addAll(hooksTmp);
                 }
             }
-            for (IndexHook ih : reindex) {
-                ih.enter(before, after);
-                ih.reindex(ref);
-            }
+            reindex(reindex, ref);
             if (!hooks.isEmpty()) {
-                this.inner = new CompositeEditor(hooks);
+                this.inner = VisibleEditor.wrap(CompositeEditor.compose(hooks));
                 this.inner.enter(before, after);
             }
         }
     }
 
+    private void reindex(List<IndexHook> hooks, NodeState state)
+            throws CommitFailedException {
+        if (hooks.isEmpty()) {
+            return;
+        }
+        List<Editor> editors = Lists.newArrayList();
+        for (IndexHook ih : hooks) {
+            ih.enter(EMPTY_NODE, state);
+            Editor e = ih.reindex(state);
+            if (e != null) {
+                editors.add(e);
+            }
+        }
+        final Editor reindexer = VisibleEditor.wrap(CompositeEditor
+                .compose(editors));
+        if (reindexer == null) {
+            return;
+        }
+        EditorProvider provider = new EditorProvider() {
+            @Override
+            public Editor getRootEditor(NodeState before, NodeState after,
+                    NodeBuilder builder) {
+                return reindexer;
+            }
+        };
+        EditorHook eh = new EditorHook(provider);
+        eh.processCommit(EMPTY_NODE, state);
+    }
+
     @Override
     public void leave(NodeState before, NodeState after)
             throws CommitFailedException {
@@ -143,27 +172,18 @@ class IndexHookManagerDiff implements Ed
     @Override
     public Editor childNodeAdded(String name, NodeState after)
             throws CommitFailedException {
-        if (NodeStateUtils.isHidden(name)) {
-            return null;
-        }
         return inner.childNodeAdded(name, after);
     }
 
     @Override
     public Editor childNodeChanged(String name, NodeState before,
             NodeState after) throws CommitFailedException {
-        if (NodeStateUtils.isHidden(name)) {
-            return null;
-        }
         return inner.childNodeChanged(name, before, after);
     }
 
     @Override
     public Editor childNodeDeleted(String name, NodeState before)
             throws CommitFailedException {
-        if (NodeStateUtils.isHidden(name)) {
-            return null;
-        }
         return inner.childNodeDeleted(name, before);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java
Fri Apr  5 12:12:56 2013
@@ -40,11 +40,8 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.p2.strategy.ContentMirrorStoreStrategy;
 import org.apache.jackrabbit.oak.plugins.index.p2.strategy.IndexStoreStrategy;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
-import org.apache.jackrabbit.oak.spi.commit.EditorHook;
-import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
@@ -279,9 +276,6 @@ class Property2IndexHook implements Inde
     @Override
     public Editor childNodeChanged(String name, NodeState before,
             NodeState after) throws CommitFailedException {
-        if (NodeStateUtils.isHidden(name)) {
-            return null;
-        }
         return new Property2IndexHook(this, name);
     }
 
@@ -292,7 +286,7 @@ class Property2IndexHook implements Inde
     }
 
     @Override
-    public void reindex(NodeState state) throws CommitFailedException {
+    public Editor reindex(NodeState state) {
         boolean reindex = false;
         for (List<Property2IndexHookUpdate> updateList : indexMap.values()) {
             for (Property2IndexHookUpdate update : updateList) {
@@ -302,16 +296,9 @@ class Property2IndexHook implements Inde
             }
         }
         if (reindex) {
-            EditorProvider provider = new EditorProvider() {
-                @Override
-                public Editor getRootEditor(NodeState before, NodeState after,
-                        NodeBuilder builder) {
-                    return new Property2IndexHook(node);
-                }
-            };
-            EditorHook eh = new EditorHook(provider);
-            eh.processCommit(EMPTY_NODE, state);
+            return new Property2IndexHook(node);
         }
+        return null;
     }
 
     // -----------------------------------------------------< Closeable >--

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
Fri Apr  5 12:12:56 2013
@@ -37,7 +37,7 @@ import javax.annotation.Nonnull;
 public class CompositeEditor implements Editor {
 
     @CheckForNull
-    public static Editor compose(@Nonnull Collection<Editor> editors) {
+    public static Editor compose(@Nonnull Collection<? extends Editor> editors) {
         checkNotNull(editors);
         switch (editors.size()) {
         case 0:

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
Fri Apr  5 12:12:56 2013
@@ -34,8 +34,6 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.IndexHook;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
-import org.apache.jackrabbit.oak.spi.commit.EditorHook;
-import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
@@ -206,7 +204,7 @@ public class LuceneIndexDiff implements 
     }
 
     @Override
-    public void reindex(NodeState state) throws CommitFailedException {
+    public Editor reindex(NodeState state) {
         boolean reindex = false;
         for (LuceneIndexUpdate update : updates.values()) {
             if (update.getAndResetReindexFlag()) {
@@ -214,16 +212,9 @@ public class LuceneIndexDiff implements 
             }
         }
         if (reindex) {
-            EditorProvider provider = new EditorProvider() {
-                @Override
-                public Editor getRootEditor(NodeState before, NodeState after,
-                        NodeBuilder builder) {
-                    return new LuceneIndexDiff(node);
-                }
-            };
-            EditorHook eh = new EditorHook(provider);
-            eh.processCommit(EMPTY_NODE, state);
+            return new LuceneIndexDiff(node);
         }
+        return null;
     }
 
     // -----------------------------------------------------< Closeable >--

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
Fri Apr  5 12:12:56 2013
@@ -22,7 +22,6 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
 public class LuceneInitializerHelper implements RepositoryInitializer {
 

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java
Fri Apr  5 12:12:56 2013
@@ -28,8 +28,6 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfiguration;
 import org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
-import org.apache.jackrabbit.oak.spi.commit.EditorHook;
-import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
@@ -204,7 +202,7 @@ public class SolrIndexDiff implements In
     }
 
     @Override
-    public void reindex(NodeState state) throws CommitFailedException {
+    public Editor reindex(NodeState state) {
         boolean reindex = false;
         for (SolrIndexUpdate update : updates.values()) {
             if (update.getAndResetReindexFlag()) {
@@ -212,16 +210,9 @@ public class SolrIndexDiff implements In
             }
         }
         if (reindex) {
-            EditorProvider provider = new EditorProvider() {
-                @Override
-                public Editor getRootEditor(NodeState before, NodeState after,
-                        NodeBuilder builder) {
-                    return new SolrIndexDiff(node, solrServer, configuration);
-                }
-            };
-            EditorHook eh = new EditorHook(provider);
-            eh.processCommit(EMPTY_NODE, state);
+            return new SolrIndexDiff(node, solrServer, configuration);
         }
+        return null;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java?rev=1464936&r1=1464935&r2=1464936&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java
Fri Apr  5 12:12:56 2013
@@ -235,7 +235,7 @@ public class SolrIndexHook implements In
     }
 
     @Override
-    public void reindex(NodeState state) throws CommitFailedException {
+    public Editor reindex(NodeState state) throws CommitFailedException {
         try {
             close();
             deleteByIdQueryBuilder.append(getPath()).append("*");
@@ -244,7 +244,7 @@ public class SolrIndexHook implements In
         } catch (IOException e) {
             throw new CommitFailedException(e);
         }
-
+        return null;
     }
 
     @Override



Mime
View raw message