jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1559827 - 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/property/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ref...
Date Mon, 20 Jan 2014 20:40:21 GMT
Author: alexparvulescu
Date: Mon Jan 20 20:40:20 2014
New Revision: 1559827

URL: http://svn.apache.org/r1559827
Log:
OAK-1292 Avoid async indexer commits when there are no changes to index


Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardIndexEditorProvider.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.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-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorProvider.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/SolrIndexEditorProviderService.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
Mon Jan 20 20:40:20 2014
@@ -24,6 +24,7 @@ import static org.apache.jackrabbit.oak.
 
 import java.util.Calendar;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.annotation.Nonnull;
 
@@ -98,8 +99,6 @@ public class AsyncIndexUpdate implements
             return;
         }
 
-        preAsyncRun(store);
-
         NodeBuilder builder = store.getRoot().builder();
         NodeBuilder async = builder.child(ASYNC);
 
@@ -112,30 +111,49 @@ public class AsyncIndexUpdate implements
             before = MISSING_NODE;
         }
 
-        CommitFailedException exception = EditorDiff.process(new IndexUpdate(
-                provider, name, after, builder), before, after);
+        final AtomicBoolean dirty = new AtomicBoolean(false);
+
+        IndexUpdateCallback callback = new IndexUpdateCallback() {
+
+            @Override
+            public void beforeIndex() throws CommitFailedException {
+                if (dirty.get()) {
+                    return;
+                }
+                preAsyncRun(store, name);
+                dirty.set(true);
+            }
+        };
+
+        IndexUpdate indexUpdate = new IndexUpdate(provider, name, after,
+                builder, callback);
+
+        CommitFailedException exception = EditorDiff.process(indexUpdate,
+                before, after);
         if (exception == null) {
-            try {
-                async.setProperty(name, checkpoint);
-                postAsyncRunStatus(builder);
-                store.merge(builder, new CommitHook() {
-                    @Override
-                    @Nonnull
-                    public NodeState processCommit(NodeState before,
-                            NodeState after) throws CommitFailedException {
-                        // check for concurrent updates by this async task
-                        PropertyState stateAfterRebase = before.getChildNode(
-                                ASYNC).getProperty(name);
-                        if (Objects.equal(state, stateAfterRebase)) {
-                            return after;
-                        } else {
-                            throw CONCURRENT_UPDATE;
+            async.setProperty(name, checkpoint);
+            if (dirty.get()) {
+                try {
+                    store.merge(builder, new CommitHook() {
+                        @Override
+                        @Nonnull
+                        public NodeState processCommit(NodeState before,
+                                NodeState after) throws CommitFailedException {
+                            // check for concurrent updates by this async task
+                            PropertyState stateAfterRebase = before
+                                    .getChildNode(ASYNC).getProperty(name);
+                            if (Objects.equal(state, stateAfterRebase)) {
+                                return postAsyncRunStatus(after.builder())
+                                        .getNodeState();
+                            } else {
+                                throw CONCURRENT_UPDATE;
+                            }
                         }
+                    }, null);
+                } catch (CommitFailedException e) {
+                    if (e != CONCURRENT_UPDATE) {
+                        exception = e;
                     }
-                }, null);
-            } catch (CommitFailedException e) {
-                if (e != CONCURRENT_UPDATE) {
-                    exception = e;
                 }
             }
         }
@@ -153,17 +171,14 @@ public class AsyncIndexUpdate implements
         }
     }
 
-    private void preAsyncRun(NodeStore store) {
+    private static void preAsyncRun(NodeStore store, String name)
+            throws CommitFailedException {
         NodeBuilder builder = store.getRoot().builder();
         preAsyncRunStatus(builder);
-        try {
-            store.merge(builder, EmptyHook.INSTANCE, null);
-        } catch (CommitFailedException e) {
-            log.warn("Index status update {} failed", name, e);
-        }
+        store.merge(builder, EmptyHook.INSTANCE, null);
     }
 
-    private boolean isAlreadyRunning(NodeStore store) {
+    private static boolean isAlreadyRunning(NodeStore store) {
         NodeState indexState = store.getRoot().getChildNode(IndexConstants.INDEX_DEFINITIONS_NAME);
 
         //Probably the first run
@@ -198,11 +213,12 @@ public class AsyncIndexUpdate implements
                 .removeProperty("async-done");
     }
 
-    private static void postAsyncRunStatus(NodeBuilder builder) {
+    private static NodeBuilder postAsyncRunStatus(NodeBuilder builder) {
         builder.getChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)
                 .setProperty("async-status", "done")
                 .setProperty("async-done", now(), Type.DATE)
                 .removeProperty("async-start");
+        return builder;
     }
 
     private static String now() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java
Mon Jan 20 20:40:20 2014
@@ -43,7 +43,7 @@ public class CompositeIndexEditorProvide
             return new IndexEditorProvider() {
                 @Override
                 public Editor getIndexEditor(
-                        String type, NodeBuilder builder, NodeState root) {
+                        String type, NodeBuilder builder, NodeState root, IndexUpdateCallback
callback) {
                     return null;
                 }
             };
@@ -67,11 +67,11 @@ public class CompositeIndexEditorProvide
 
     @Override
     public Editor getIndexEditor(
-            String type, NodeBuilder builder, NodeState root)
+            String type, NodeBuilder builder, NodeState root, IndexUpdateCallback callback)
             throws CommitFailedException {
         List<Editor> indexes = Lists.newArrayList();
         for (IndexEditorProvider provider : providers) {
-            Editor e = provider.getIndexEditor(type, builder, root);
+            Editor e = provider.getIndexEditor(type, builder, root, callback);
             if (e != null) {
                 indexes.add(e);
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java
Mon Jan 20 20:40:20 2014
@@ -44,10 +44,12 @@ public interface IndexEditorProvider {
      * @param type  index type
      * @param definition index definition node builder, used for updates
      * @param root root node state, used for things like node type information
+     * @param callback used to register for index update notifications
      * @return index update editor, or {@code null} if type is unknown
      */
     @CheckForNull
     Editor getIndexEditor(
             @Nonnull String type, @Nonnull NodeBuilder definition,
-            @Nonnull NodeState root) throws CommitFailedException;
+            @Nonnull NodeState root, 
+            @CheckForNull IndexUpdateCallback callback) throws CommitFailedException;
 }

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=1559827&r1=1559826&r2=1559827&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
Mon Jan 20 20:40:20 2014
@@ -61,13 +61,20 @@ class IndexUpdate implements Editor {
      */
     private final List<Editor> reindex = newArrayList();
 
+    /**
+     * Callback for the 'before' events of the indexing job
+     */
+    private final IndexUpdateCallback updateCallback;
+
     IndexUpdate(
             IndexEditorProvider provider, String async,
-            NodeState root, NodeBuilder builder) {
+            NodeState root, NodeBuilder builder,
+            IndexUpdateCallback updateCallback) {
         this.provider = checkNotNull(provider);
         this.async = async;
         this.root = checkNotNull(root);
         this.builder = checkNotNull(builder);
+        this.updateCallback = updateCallback;
     }
 
     private IndexUpdate(IndexUpdate parent, String name) {
@@ -76,6 +83,7 @@ class IndexUpdate implements Editor {
         this.async = parent.async;
         this.root = parent.root;
         this.builder = parent.builder.child(checkNotNull(name));
+        this.updateCallback = parent.updateCallback;
     }
 
     @Override
@@ -101,7 +109,7 @@ class IndexUpdate implements Editor {
             NodeBuilder definition = definitions.getChildNode(name);
             if (Objects.equal(async, definition.getString(ASYNC_PROPERTY_NAME))) {
                 String type = definition.getString(TYPE_PROPERTY_NAME);
-                Editor editor = provider.getIndexEditor(type, definition, root);
+                Editor editor = provider.getIndexEditor(type, definition, root, updateCallback);
                 if (editor == null) {
                     // trigger reindexing when an indexer becomes available
                     definition.setProperty(REINDEX_PROPERTY_NAME, true);

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java?rev=1559827&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java
Mon Jan 20 20:40:20 2014
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.index;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+
+public abstract class IndexUpdateCallback {
+
+    private boolean dirty = false;
+
+    public void indexUpdate() throws CommitFailedException {
+        if (!dirty) {
+            dirty = true;
+            beforeIndex();
+        }
+    }
+
+    /**
+     * Called when the indexer finds the first changes that need indexing when
+     * running the diff
+     */
+    abstract protected void beforeIndex() throws CommitFailedException;
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java
Mon Jan 20 20:40:20 2014
@@ -43,7 +43,7 @@ public class IndexUpdateProvider impleme
     @Override @CheckForNull
     public Editor getRootEditor(
             NodeState before, NodeState after, NodeBuilder builder) {
-        return new IndexUpdate(provider, async, after, builder);
+        return new IndexUpdate(provider, async, after, builder, null);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
Mon Jan 20 20:40:20 2014
@@ -37,6 +37,7 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.plugins.index.property.strategy.ContentMirrorStoreStrategy;
 import org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy;
 import org.apache.jackrabbit.oak.plugins.index.property.strategy.UniqueEntryStoreStrategy;
@@ -101,7 +102,10 @@ class PropertyIndexEditor implements Ind
      */
     private Set<String> afterKeys;
 
-    public PropertyIndexEditor(NodeBuilder definition, NodeState root) {
+    private final IndexUpdateCallback updateCallback;
+
+    public PropertyIndexEditor(NodeBuilder definition, NodeState root,
+            IndexUpdateCallback updateCallback) {
         this.parent = null;
         this.name = null;
         this.path = "/";
@@ -130,6 +134,7 @@ class PropertyIndexEditor implements Ind
         } else {
             this.keysToCheckForUniqueness = null;
         }
+        this.updateCallback = updateCallback;
     }
 
     private PropertyIndexEditor(PropertyIndexEditor parent, String name) {
@@ -140,6 +145,7 @@ class PropertyIndexEditor implements Ind
         this.propertyNames = parent.propertyNames;
         this.typePredicate = parent.typePredicate;
         this.keysToCheckForUniqueness = parent.keysToCheckForUniqueness;
+        this.updateCallback = parent.updateCallback;
     }
 
     /**
@@ -235,6 +241,9 @@ class PropertyIndexEditor implements Ind
             }
 
             if (!beforeKeys.isEmpty() || !afterKeys.isEmpty()) {
+                if (updateCallback != null) {
+                    updateCallback.indexUpdate();
+                }
                 NodeBuilder index = definition.child(INDEX_CONTENT_NODE_NAME);
                 getStrategy(keysToCheckForUniqueness != null).update(
                         index, getPath(), beforeKeys, afterKeys);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java
Mon Jan 20 20:40:20 2014
@@ -20,6 +20,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -38,9 +39,9 @@ public class PropertyIndexEditorProvider
 
     @Override
     public Editor getIndexEditor(
-            String type, NodeBuilder definition, NodeState root) {
+            String type, NodeBuilder definition, NodeState root, IndexUpdateCallback callback)
{
         if (TYPE.equals(type)) {
-            return new PropertyIndexEditor(definition, root);
+            return new PropertyIndexEditor(definition, root, callback);
         }
         return null;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditorProvider.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditorProvider.java
Mon Jan 20 20:40:20 2014
@@ -21,6 +21,7 @@ import static org.apache.jackrabbit.oak.
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -31,7 +32,7 @@ public class ReferenceEditorProvider imp
 
     @Override
     public Editor getIndexEditor(String type, NodeBuilder definition,
-            NodeState root) {
+            NodeState root, IndexUpdateCallback callback) {
         if (TYPE.equals(type)) {
             return new ReferenceEditor(definition, root);
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardIndexEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardIndexEditorProvider.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardIndexEditorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardIndexEditorProvider.java
Mon Jan 20 20:40:20 2014
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.spi.wh
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -38,15 +39,15 @@ public class WhiteboardIndexEditorProvid
     }
 
     @Override
-    public Editor getIndexEditor(
-            String type, NodeBuilder builder, NodeState root)
+    public Editor getIndexEditor(String type, NodeBuilder builder,
+            NodeState root, IndexUpdateCallback callback)
             throws CommitFailedException {
         IndexEditorProvider composite = CompositeIndexEditorProvider
                 .compose(getServices());
         if (composite == null) {
             return null;
         }
-        return composite.getIndexEditor(type, builder, root);
+        return composite.getIndexEditor(type, builder, root, callback);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java
Mon Jan 20 20:40:20 2014
@@ -22,6 +22,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefinition;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 
 import java.util.Set;
 
@@ -86,6 +87,8 @@ public class AsyncIndexUpdateTest {
         // first check that the index content nodes exist
         checkPathExists(root, INDEX_DEFINITIONS_NAME, "rootIndex",
                 INDEX_CONTENT_NODE_NAME);
+        assertFalse(root.getChildNode(INDEX_DEFINITIONS_NAME).hasChildNode(
+                ":conflict"));
 
         PropertyIndexLookup lookup = new PropertyIndexLookup(root);
         assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
Mon Jan 20 20:40:20 2014
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -70,11 +71,13 @@ public class LuceneIndexEditor implement
 
     private boolean propertiesChanged = false;
 
-    LuceneIndexEditor(NodeBuilder definition, Analyzer analyzer) throws CommitFailedException
{
+    LuceneIndexEditor(NodeBuilder definition, Analyzer analyzer,
+            IndexUpdateCallback updateCallback) throws CommitFailedException {
         this.parent = null;
         this.name = null;
         this.path = "/";
-        this.context = new LuceneIndexEditorContext(definition, analyzer);
+        this.context = new LuceneIndexEditorContext(definition, analyzer,
+                updateCallback);
     }
 
     private LuceneIndexEditor(LuceneIndexEditor parent, String name) {
@@ -158,6 +161,7 @@ public class LuceneIndexEditor implement
             // Remove all index entries in the removed subtree
             writer.deleteDocuments(newPathTerm(path));
             writer.deleteDocuments(new PrefixQuery(newPathTerm(path + "/")));
+            this.context.indexUpdate();
         } catch (IOException e) {
             throw new CommitFailedException(
                     "Lucene", 5, "Failed to remove the index entries of"
@@ -182,7 +186,7 @@ public class LuceneIndexEditor implement
         return false;
     }
 
-    private Document makeDocument(String path, NodeState state, boolean isUpdate) {
+    private Document makeDocument(String path, NodeState state, boolean isUpdate) throws
CommitFailedException {
         Document document = new Document();
         boolean dirty = false;
         for (PropertyState property : state.getProperties()) {
@@ -191,10 +195,12 @@ public class LuceneIndexEditor implement
                     && (context.getPropertyTypes() & (1 << property.getType()
                             .tag())) != 0 && context.includeProperty(pname)) {
                 if (Type.BINARY.tag() == property.getType().tag()) {
+                    this.context.indexUpdate();
                     addBinaryValue(document, property, state);
                     dirty = true;
                 } else {
                     for (String value : property.getValue(Type.STRINGS)) {
+                        this.context.indexUpdate();
                         document.add(newPropertyField(pname, value));
                         document.add(newFulltextField(value));
                         dirty = true;

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=1559827&r1=1559826&r2=1559827&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
Mon Jan 20 20:40:20 2014
@@ -29,8 +29,10 @@ import java.util.Set;
 
 import javax.jcr.PropertyType;
 
+import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.index.IndexWriter;
@@ -102,7 +104,9 @@ public class LuceneIndexEditorContext {
 
     private long indexedNodes;
 
-    LuceneIndexEditorContext(NodeBuilder definition, Analyzer analyzer) {
+    private final IndexUpdateCallback updateCallback;
+
+    LuceneIndexEditorContext(NodeBuilder definition, Analyzer analyzer, IndexUpdateCallback
updateCallback) {
         this.definition = definition;
         this.config = getIndexWriterConfig(analyzer);
 
@@ -127,6 +131,7 @@ public class LuceneIndexEditorContext {
             excludes = ImmutableSet.of();
         }
         this.indexedNodes = 0;
+        this.updateCallback = updateCallback;
     }
 
     int getPropertyTypes() {
@@ -166,4 +171,10 @@ public class LuceneIndexEditorContext {
         return indexedNodes;
     }
 
+    void indexUpdate() throws CommitFailedException {
+        if (this.updateCallback != null) {
+            updateCallback.indexUpdate();
+        }
+    }
+
 }

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=1559827&r1=1559826&r2=1559827&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
Mon Jan 20 20:40:20 2014
@@ -16,14 +16,15 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.lucene;
 
-import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.TYPE_LUCENE;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.ANALYZER;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.TYPE_LUCENE;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -47,10 +48,10 @@ public class LuceneIndexEditorProvider i
 
     @Override
     public Editor getIndexEditor(
-            String type, NodeBuilder definition, NodeState root)
+            String type, NodeBuilder definition, NodeState root, IndexUpdateCallback callback)
             throws CommitFailedException {
         if (TYPE_LUCENE.equals(type)) {
-            return new LuceneIndexEditor(definition, analyzer);
+            return new LuceneIndexEditor(definition, analyzer, callback);
         }
         return null;
     }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
Mon Jan 20 20:40:20 2014
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration;
 import org.apache.jackrabbit.oak.plugins.index.solr.util.OakSolrUtils;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
@@ -57,15 +58,19 @@ public class SolrIndexEditor implements 
 
     private boolean propertiesChanged = false;
 
+    private IndexUpdateCallback updateCallback;
+
     SolrIndexEditor(
             NodeBuilder definition, SolrServer solrServer,
-            OakSolrConfiguration configuration) throws CommitFailedException {
+            OakSolrConfiguration configuration,
+            IndexUpdateCallback callback) throws CommitFailedException {
         this.parent = null;
         this.name = null;
         this.path = "/";
         this.definition = definition;
         this.solrServer = solrServer;
         this.configuration = configuration;
+        this.updateCallback = callback;
     }
 
     private SolrIndexEditor(SolrIndexEditor parent, String name) {
@@ -75,6 +80,7 @@ public class SolrIndexEditor implements 
         this.definition = parent.definition;
         this.solrServer = parent.solrServer;
         this.configuration = parent.configuration;
+        this.updateCallback = parent.updateCallback;
     }
 
     public String getPath() {
@@ -92,6 +98,7 @@ public class SolrIndexEditor implements 
     public void leave(NodeState before, NodeState after)
             throws CommitFailedException {
         if (propertiesChanged || !before.exists()) {
+            indexUpdate();
             try {
                 solrServer.add(docFromState(after));
             } catch (SolrServerException e) {
@@ -152,6 +159,7 @@ public class SolrIndexEditor implements 
         try {
             solrServer.deleteByQuery(String.format(
                     "%s:%s\\/*", configuration.getPathField(), path));
+            indexUpdate();
         } catch (SolrServerException e) {
             throw new CommitFailedException(
                     "Solr", 5, "Failed to remove documents from Solr", e);
@@ -191,4 +199,10 @@ public class SolrIndexEditor implements 
         return inputDocument;
     }
 
+    protected void indexUpdate() throws CommitFailedException {
+        if (updateCallback != null) {
+            updateCallback.indexUpdate();
+        }
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorProvider.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorProvider.java
Mon Jan 20 20:40:20 2014
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex;
 import org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider;
@@ -50,7 +51,7 @@ public class SolrIndexEditorProvider imp
 
     @Override
     public Editor getIndexEditor(
-            String type, NodeBuilder definition, NodeState root)
+            String type, NodeBuilder definition, NodeState root, IndexUpdateCallback callback)
             throws CommitFailedException {
 
         if (SolrQueryIndex.TYPE.equals(type)
@@ -59,7 +60,7 @@ public class SolrIndexEditorProvider imp
                 return new SolrIndexEditor(
                         definition,
                         solrServerProvider.getSolrServer(),
-                        oakSolrConfigurationProvider.getConfiguration());
+                        oakSolrConfigurationProvider.getConfiguration(), callback);
             } catch (Exception e) {
                 if (log.isErrorEnabled()) {
                     log.error("unable to create SolrIndexEditor", e);

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/SolrIndexEditorProviderService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/SolrIndexEditorProviderService.java?rev=1559827&r1=1559826&r2=1559827&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/SolrIndexEditorProviderService.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/SolrIndexEditorProviderService.java
Mon Jan 20 20:40:20 2014
@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider;
@@ -55,11 +56,11 @@ public class SolrIndexEditorProviderServ
     @Override
     @CheckForNull
     public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, 
-                    @Nonnull NodeState root) throws CommitFailedException {
+                    @Nonnull NodeState root, IndexUpdateCallback callback) throws CommitFailedException
{
         Editor indexEditor = null;
         if (solrServerProvider != null && oakSolrConfigurationProvider != null &&
solrIndexEditorProvider == null) {
             solrIndexEditorProvider = new SolrIndexEditorProvider(solrServerProvider, oakSolrConfigurationProvider);
-            indexEditor = solrIndexEditorProvider.getIndexEditor(type, definition, root);
+            indexEditor = solrIndexEditorProvider.getIndexEditor(type, definition, root,
callback);
         }
         return indexEditor;
     }



Mime
View raw message