Author: mreutegg
Date: Mon Jul 8 13:11:25 2019
New Revision: 1862746
URL: http://svn.apache.org/viewvc?rev=1862746&view=rev
Log:
OAK-8449: LastRev check/fix in DocumentNodeStore MBean
Patch provided by Vinod Holani.
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1862746&r1=1862745&r2=1862746&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Mon Jul 8 13:11:25 2019
@@ -3416,4 +3416,8 @@ public final class DocumentNodeStore
int getUpdateLimit() {
return updateLimit;
}
+
+ boolean isReadOnlyMode() {
+ return readOnlyMode;
+ }
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java?rev=1862746&r1=1862745&r2=1862746&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java
Mon Jul 8 13:11:25 2019
@@ -64,4 +64,16 @@ public interface DocumentNodeStoreMBean
CompositeData getBranchCommitHistory();
CompositeData getMergeBranchCommitHistory();
+
+ @Description("Triggers last revision recovery of nodes, below a given path
and clusterId.\n" +
+ "Returns number of records updated after performing recovery.\n" +
+ "Note: Recovery can only be performed on inactive clusterIds. If
the clusterNode is in ReadOnly mode,\n" +
+ "it will return the no. of documents which needs update and won't
perform recovery")
+ int recover(
+ @Description("The absolute path of a node.")
+ @Name("path")
+ String path,
+ @Description("The id of an inactive cluster node.")
+ @Name("clusterId")
+ int clusterId);
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java?rev=1862746&r1=1862745&r2=1862746&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java
Mon Jul 8 13:11:25 2019
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.oak.plugins.document;
import java.text.SimpleDateFormat;
+import java.util.List;
import java.util.TimeZone;
import javax.management.NotCompliantMBeanException;
@@ -27,9 +28,15 @@ import com.google.common.base.Predicate;
import org.apache.jackrabbit.api.stats.RepositoryStatistics;
import org.apache.jackrabbit.api.stats.TimeSeries;
+import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.stats.TimeSeriesStatsUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.toArray;
import static com.google.common.collect.Iterables.transform;
@@ -45,6 +52,7 @@ final class DocumentNodeStoreMBeanImpl e
private final DocumentNodeStore nodeStore;
private final RepositoryStatistics repoStats;
private final Iterable<ClusterNodeInfoDocument> clusterNodes;
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
DocumentNodeStoreMBeanImpl(DocumentNodeStore nodeStore,
RepositoryStatistics repoStats,
@@ -184,4 +192,51 @@ final class DocumentNodeStoreMBeanImpl e
private TimeSeries getTimeSeries(String name) {
return repoStats.getTimeSeries(name, true);
}
+
+ @Override
+ public int recover(String path, int clusterId) {
+ checkNotNull(path, "path must not be null");
+ checkArgument(PathUtils.isAbsolute(path), "path must be absolute");
+ checkArgument(clusterId >= 0, "clusterId must not be a negative");
+
+ DocumentStore docStore = nodeStore.getDocumentStore();
+ boolean isActive = false;
+
+ for (ClusterNodeInfoDocument it :
ClusterNodeInfoDocument.all(docStore)) {
+ if (it.getClusterId() == clusterId && it.isActive()) {
+ isActive = true;
+ }
+ }
+
+ if (isActive) {
+ throw new IllegalStateException(
+ "Cannot run recover on clusterId " + clusterId + " as it's
currently active");
+ }
+
+ String p = path;
+ NodeDocument nodeDocument = docStore.find(Collection.NODES,
Utils.getIdFromPath(p));
+ if(nodeDocument == null) {
+ throw new DocumentStoreException("Document node with given path =
" + p + " does not exist");
+ }
+
+ boolean dryRun = nodeStore.isReadOnlyMode();
+ int sum = 0;
+ for (;;) {
+ log.info("Running recovery on child documents of path = " + p);
+ List<NodeDocument> childDocs = getChildDocs(p);
+ sum += nodeStore.getLastRevRecoveryAgent().recover(childDocs,
clusterId, dryRun);
+ if (PathUtils.denotesRoot(p)) {
+ break;
+ }
+ p = PathUtils.getParentPath(p);
+ }
+ return sum;
+ }
+
+ private List<NodeDocument> getChildDocs(String path) {
+ Path pathRef = Path.fromString(path);
+ final String to = Utils.getKeyUpperLimit(pathRef);
+ final String from = Utils.getKeyLowerLimit(pathRef);
+ return nodeStore.getDocumentStore().query(Collection.NODES, from, to,
10000);
+ }
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1862746&r1=1862745&r2=1862746&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Mon Jul 8 13:11:25 2019
@@ -686,6 +686,71 @@ public class DocumentNodeStoreTest {
assertTrue(active[0].startsWith(cId2 + "="));
}
+ //OAK-8449
+ @Test
+ public void lastRevisionRecovery() throws Exception {
+ DocumentStore docStore = new MemoryDocumentStore();
+ DocumentNodeStore ns1 = builderProvider.newBuilder().setAsyncDelay(0)
+ .setClusterId(1).setDocumentStore(docStore)
+ .getNodeStore();
+ int cId1 = ns1.getClusterId();
+ NodeBuilder builder = ns1.getRoot().builder();
+
+ //Validating null path
+ try {
+ ns1.getMBean().recover(null, cId1);
+ fail("must fail with NullPointerException");
+ } catch (NullPointerException expected) {}
+
+ //Validating empty path
+ try {
+ ns1.getMBean().recover("", cId1);
+ fail("must fail with IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {}
+
+ //Validating negative clusterId
+ try {
+ ns1.getMBean().recover("/foo", -1);
+ fail("must fail with IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {}
+
+ //Validating recovery on active node
+ try {
+ ns1.getMBean().recover("/foo", cId1);
+ fail("must fail with IllegalStateException");
+ } catch (IllegalStateException expected) {}
+
+ builder.child("foo").child("bar");
+ merge(ns1, builder);
+
+ builder = ns1.getRoot().builder();
+ builder.child("foo").child("bar").setProperty("key", "value");
+ merge(ns1, builder);
+ ns1.dispose();
+
+ UpdateOp op = new UpdateOp(Utils.getIdFromPath("/foo"), false);
+ op.removeMapEntry("_lastRev", new Revision(0, 0, cId1));
+ assertNotNull(docStore.findAndUpdate(Collection.NODES, op));
+
+ //Validate no. of affected paths in readOnlyMode
+ DocumentNodeStore ns2 = builderProvider.newBuilder().setAsyncDelay(0)
+ .setClusterId(2).setDocumentStore(docStore).setReadOnlyMode()
+ .getNodeStore();
+ assertEquals(1, ns2.getMBean().recover("/foo", cId1));
+
+ //Validate no. of recovered paths
+ DocumentNodeStore ns3 = builderProvider.newBuilder().setAsyncDelay(0)
+ .setClusterId(3).setDocumentStore(docStore)
+ .getNodeStore();
+ assertEquals(1, ns3.getMBean().recover("/foo", cId1));
+
+ //Validating recovery on non existing path
+ try {
+ ns2.getMBean().recover("/foo1", cId1);
+ fail("must fail with DocumentStoreException");
+ } catch (DocumentStoreException expected) {}
+ }
+
// OAK-2288
@Test
public void mergedBranchVisibility() throws Exception {