jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1492200 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: kernel/ plugins/index/ plugins/memory/ plugins/segment/ spi/state/
Date Wed, 12 Jun 2013 13:40:02 GMT
Author: jukka
Date: Wed Jun 12 13:40:02 2013
New Revision: 1492200

URL: http://svn.apache.org/r1492200
Log:
OAK-763: Asynchronous indexing

Replace the commit hook in AsyncIndexUpdate with direct use of the
IndexUpdate class so we don't need to mix the checkpoint and branch
concepts in the NodeStore interface

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    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/memory/MemoryNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1492200&r1=1492199&r2=1492200&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Wed Jun 12 13:40:02 2013
@@ -153,10 +153,9 @@ public class KernelNodeStore extends Abs
     }
 
     @Override @CheckForNull
-    public NodeStoreBranch branch(@Nonnull String checkpoint) {
+    public NodeState retrieve(@Nonnull String checkpoint) {
         try {
-            return new KernelNodeStoreBranch(
-                    this, getRootState(checkNotNull(checkpoint)));
+            return getRootState(checkNotNull(checkpoint));
         } catch (MicroKernelException e) {
             // TODO: caused by the checkpoint no longer being available?
             return null;

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=1492200&r1=1492199&r2=1492200&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
Wed Jun 12 13:40:02 2013
@@ -28,8 +28,7 @@ import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
-import org.apache.jackrabbit.oak.spi.commit.EditorHook;
+import org.apache.jackrabbit.oak.spi.commit.EditorDiff;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -43,51 +42,77 @@ public class AsyncIndexUpdate implements
     private static final Logger log = LoggerFactory
             .getLogger(AsyncIndexUpdate.class);
 
+    /**
+     * Name of the hidden node under which information about the
+     * checkpoints seen and indexed by each async indexer is kept.
+     */
+    private static final String ASYNC = ":async";
+
     private static final long DEFAULT_LIFETIME = TimeUnit.HOURS.toMillis(1);
 
     private final String name;
 
     private final NodeStore store;
 
-    private final CommitHook hook;
+    private final IndexEditorProvider provider;
 
     private final long lifetime = DEFAULT_LIFETIME; // TODO: make configurable
 
+    /** Flag to avoid repeatedly logging failure warnings */
+    private boolean failing = false;
+
     public AsyncIndexUpdate(
             @Nonnull String name,
             @Nonnull NodeStore store,
             @Nonnull IndexEditorProvider provider) {
         this.name = checkNotNull(name);
         this.store = checkNotNull(store);
-        this.hook = new EditorHook(
-                new IndexUpdateProvider(checkNotNull(provider), name));
+        this.provider = checkNotNull(provider);
     }
 
     @Override
-    public void run() {
+    public synchronized void run() {
         log.debug("Running background index task {}", name);
+        NodeStoreBranch branch = store.branch();
+        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder async = builder.child(ASYNC);
+
+        NodeState before = null;
+        PropertyState property = async.getProperty(name);
+        if (property != null && property.getType() == STRING) {
+            before = store.retrieve(property.getValue(STRING));
+        }
+        if (before == null) {
+            before = MISSING_NODE;
+        }
+
         String checkpoint = store.checkpoint(lifetime);
-        NodeStoreBranch branch = store.branch(checkpoint);
-        try {
-            NodeState after = branch.getHead();
-
-            NodeState before = null;
-            PropertyState async =
-                    after.getChildNode(":async").getProperty(name);
-            if (async != null && async.getType() == STRING) {
-                before = store.branch(async.getValue(STRING)).getHead();
-            }
-            if (before == null) {
-                before = MISSING_NODE;
+        NodeState after = store.retrieve(checkpoint);
+        if (after != null) {
+            CommitFailedException exception = EditorDiff.process(
+                    new IndexUpdate(provider, name, after, builder),
+                    before, after);
+            if (exception == null) {
+                try {
+                    async.setProperty(name, checkpoint);
+                    branch.setRoot(builder.getNodeState());
+                    branch.merge(EmptyHook.INSTANCE);
+                } catch (CommitFailedException e) {
+                    exception = e;
+                }
             }
 
-            NodeState processed = hook.processCommit(before, after);
-            NodeBuilder builder = processed.builder();
-            builder.child(":async").setProperty(name, checkpoint);
-            branch.setRoot(builder.getNodeState());
-            branch.merge(EmptyHook.INSTANCE); 
-        } catch (CommitFailedException e) {
-            log.warn("Background index update " + name + " failed", e);
+            if (exception != null) {
+                if (!failing) {
+                    log.warn("Index update " + name + " failed", exception);
+                }
+                failing = true;
+            } else {
+                if (failing) {
+                    log.info("Index update " + name + " no longer fails");
+                }
+                failing = false;
+            }
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java?rev=1492200&r1=1492199&r2=1492200&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
Wed Jun 12 13:40:02 2013
@@ -82,13 +82,8 @@ public class MemoryNodeStore extends Abs
     }
 
     @Override @CheckForNull
-    public synchronized NodeStoreBranch branch(@Nonnull String checkpoint) {
-        NodeState base = checkpoints.get(checkNotNull(checkpoint));
-        if (base != null) {
-            return new MemoryNodeStoreBranch(this, base);
-        } else {
-            return null;
-        }
+    public synchronized NodeState retrieve(@Nonnull String checkpoint) {
+        return checkpoints.get(checkNotNull(checkpoint));
     }
 
     private static class MemoryNodeStoreBranch extends AbstractNodeStoreBranch {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java?rev=1492200&r1=1492199&r2=1492200&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
Wed Jun 12 13:40:02 2013
@@ -90,11 +90,10 @@ public class SegmentNodeStore extends Ab
     }
 
     @Override @CheckForNull
-    public synchronized NodeStoreBranch branch(@Nonnull String checkpoint) {
+    public synchronized NodeState retrieve(@Nonnull String checkpoint) {
         // TODO: Verify validity of the checkpoint
         RecordId id = RecordId.fromString(checkNotNull(checkpoint));
-        SegmentNodeState base = new SegmentNodeState(store, id);
-        return new SegmentNodeStoreBranch(this, new SegmentWriter(store), base);
+        return new SegmentNodeState(store, id);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java?rev=1492200&r1=1492199&r2=1492200&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
Wed Jun 12 13:40:02 2013
@@ -134,8 +134,8 @@ public class SegmentNodeStoreService ext
     }
 
     @Override @CheckForNull
-    public NodeStoreBranch branch(@Nonnull String checkpoint) {
-        return getDelegate().branch(checkpoint);
+    public NodeState retrieve(@Nonnull String checkpoint) {
+        return getDelegate().retrieve(checkpoint);
     }
 
     //------------------------------------------------------------< Object >--

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java?rev=1492200&r1=1492199&r2=1492200&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java
Wed Jun 12 13:40:02 2013
@@ -73,13 +73,13 @@ public interface NodeStore {
     String checkpoint(long lifetime);
 
     /**
-     * Starts a new branch from a previously created repository checkpoint.
+     * Retrieves the root node from a previously created repository checkpoint.
      *
      * @param checkpoint string reference of a checkpoint
-     * @return new branch starting from the given checkpoint,
+     * @return the root node of the checkpoint,
      *         or {@code null} if the checkpoint is no longer available
      */
     @CheckForNull
-    NodeStoreBranch branch(@Nonnull String checkpoint);
+    NodeState retrieve(@Nonnull String checkpoint);
 
 }



Mime
View raw message