You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2018/06/19 08:37:40 UTC

svn commit: r1833793 - in /jackrabbit/oak/trunk/oak-store-document/src: main/java/org/apache/jackrabbit/oak/plugins/document/ test/java/org/apache/jackrabbit/oak/plugins/document/

Author: mreutegg
Date: Tue Jun 19 08:37:40 2018
New Revision: 1833793

URL: http://svn.apache.org/viewvc?rev=1833793&view=rev
Log:
OAK-7554: Extract InactiveRevisionContext from LastRevRecoveryAgent

Added:
    jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContext.java   (with props)
    jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContextTest.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java

Modified: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java?rev=1833793&r1=1833792&r2=1833793&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java Tue Jun 19 08:37:40 2018
@@ -35,7 +35,6 @@ import java.util.concurrent.atomic.Atomi
 import java.util.concurrent.locks.ReentrantLock;
 
 import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
@@ -199,8 +198,9 @@ public class LastRevRecoveryAgent {
             // only run a sweep for a cluster node that already has a
             // sweep revision. Initial sweep is not the responsibility
             // of the recovery agent.
-            final RevisionContext context = new InactiveRevisionContext(
-                    rootDoc, nodeStore, clusterId);
+            final RevisionContext context = new RecoveryContext(rootDoc,
+                    nodeStore.getClock(), clusterId,
+                    nodeStore::getCommitValue);
             final NodeDocumentSweeper sweeper = new NodeDocumentSweeper(context, true);
             sweeper.sweep(suspects, new NodeDocumentSweepListener() {
                 @Override
@@ -546,66 +546,5 @@ public class LastRevRecoveryAgent {
             return clusterId == input.getClusterId();
         }
     }
-
-    /**
-     * A revision context that represents an inactive cluster node for which
-     * recovery is performed.
-     */
-    private static class InactiveRevisionContext implements RevisionContext {
-
-        private final NodeDocument root;
-        private final RevisionContext context;
-        private final int clusterId;
-
-        InactiveRevisionContext(NodeDocument root,
-                                RevisionContext context,
-                                int clusterId) {
-            this.root = root;
-            this.context = context;
-            this.clusterId = clusterId;
-        }
-
-        @Override
-        public UnmergedBranches getBranches() {
-            // an inactive cluster node does not have active unmerged branches
-            return new UnmergedBranches();
-        }
-
-        @Override
-        public UnsavedModifications getPendingModifications() {
-            // an inactive cluster node does not have
-            // pending in-memory _lastRev updates
-            return new UnsavedModifications();
-        }
-
-        @Override
-        public int getClusterId() {
-            return clusterId;
-        }
-
-        @Nonnull
-        @Override
-        public RevisionVector getHeadRevision() {
-            return new RevisionVector(root.getLastRev().values());
-        }
-
-        @Nonnull
-        @Override
-        public Revision newRevision() {
-            return Revision.newRevision(clusterId);
-        }
-
-        @Nonnull
-        @Override
-        public Clock getClock() {
-            return context.getClock();
-        }
-
-        @Override
-        public String getCommitValue(@Nonnull Revision changeRevision,
-                                     @Nonnull NodeDocument doc) {
-            return context.getCommitValue(changeRevision, doc);
-        }
-    }
 }
 

Added: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContext.java?rev=1833793&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContext.java (added)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContext.java Tue Jun 19 08:37:40 2018
@@ -0,0 +1,95 @@
+/*
+ * 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.document;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.stats.Clock;
+
+/**
+ * A revision context that represents a cluster node with an expired lease for
+ * which recovery is performed.
+ */
+final class RecoveryContext implements RevisionContext {
+
+    private final NodeDocument root;
+    private final Clock clock;
+    private final int clusterId;
+    private final CommitValueResolver resolver;
+
+    /**
+     * A new recovery context.
+     *
+     * @param root the current root document.
+     * @param clock the clock.
+     * @param clusterId the clusterId for which to run recovery.
+     * @param resolver a commit resolver.
+     */
+    RecoveryContext(NodeDocument root,
+                    Clock clock,
+                    int clusterId,
+                    CommitValueResolver resolver) {
+        this.root = root;
+        this.clock = clock;
+        this.clusterId = clusterId;
+        this.resolver = resolver;
+    }
+
+    @Override
+    public UnmergedBranches getBranches() {
+        // an expired cluster node does not have active unmerged branches
+        return new UnmergedBranches();
+    }
+
+    @Override
+    public UnsavedModifications getPendingModifications() {
+        // an expired cluster node does not have
+        // pending in-memory _lastRev updates
+        return new UnsavedModifications();
+    }
+
+    @Override
+    public int getClusterId() {
+        return clusterId;
+    }
+
+    @Nonnull
+    @Override
+    public RevisionVector getHeadRevision() {
+        return new RevisionVector(root.getLastRev().values());
+    }
+
+    @Nonnull
+    @Override
+    public Revision newRevision() {
+        return Revision.newRevision(clusterId);
+    }
+
+    @Nonnull
+    @Override
+    public Clock getClock() {
+        return clock;
+    }
+
+    @CheckForNull
+    @Override
+    public String getCommitValue(@Nonnull Revision changeRevision,
+                                 @Nonnull NodeDocument doc) {
+        return resolver.resolve(changeRevision, doc);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContextTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContextTest.java?rev=1833793&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContextTest.java (added)
+++ jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContextTest.java Tue Jun 19 08:37:40 2018
@@ -0,0 +1,42 @@
+/*
+ * 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.document;
+
+import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.empty;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+public class RecoveryContextTest {
+
+    @Test
+    public void recoveryContext() {
+        DocumentStore store = new MemoryDocumentStore();
+        NodeDocument doc = new NodeDocument(store);
+        int clusterId = 1;
+
+        RevisionContext context = new RecoveryContext(doc, Clock.SIMPLE,
+                clusterId, (r, d) -> null);
+        assertEquals(clusterId, context.getClusterId());
+        assertEquals(0, context.getBranches().size());
+        assertThat(context.getPendingModifications().getPaths(), empty());
+        assertEquals(clusterId, context.newRevision().getClusterId());
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/RecoveryContextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native