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 2019/09/05 10:47:08 UTC
svn commit: r1866447 - in /jackrabbit/oak/branches/1.10: ./
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/
oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/
Author: mreutegg
Date: Thu Sep 5 10:47:07 2019
New Revision: 1866447
URL: http://svn.apache.org/viewvc?rev=1866447&view=rev
Log:
OAK-8449: LastRev check/fix in DocumentNodeStore MBean
Merge revision 1862746 from trunk
Modified:
jackrabbit/oak/branches/1.10/ (props changed)
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Propchange: jackrabbit/oak/branches/1.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Sep 5 10:47:07 2019
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852135,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853083,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854539,1854579-1854580,1854596,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1854990-1854991,1855032,1855221,1855477-1855478,1855522,1855776,1855905,1855993,1856049,1856056,1856538,1856545,1857000,1857010,1857104,1857159,1857212,1857221,1857238,1857242,1857247,1857253,1857294,1857314,1857332,1857463,1857480,1857577,1857589,1857592,1857627,1857634-1857635,1857638,1857640,1857687,1857936,1858032,1858053,1858123,1858139,1858385,1858424,1858571,1858578,1858810,1858926,1858931,1859020,1859231,1859292,1859294,1859350-1859351,1859359,1859365,1859533,1859609
,1859612,1859619,1859711,1859716,1859772,1859776,1859780,1859843,1859854,1859881,1860120,1860131,1860137,1860202,1860278,1860328,1860330,1860355,1860393,1860442,1860548,1860564-1860565,1860931,1861114,1861270,1861626,1861743,1861757,1861763,1861770,1861776,1861780,1862044,1862093,1862266,1862370,1862422,1862447-1862448,1862465,1862499,1862531,1862536-1862537,1862728,1862806,1862817,1862881,1862926-1862927,1862976-1862977,1863076,1863081,1863086,1863369,1863405,1863540,1863633-1863634,1863642,1863645,1864349,1864353,1865752
+/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852135,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853083,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854539,1854579-1854580,1854596,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1854990-1854991,1855032,1855221,1855477-1855478,1855522,1855776,1855905,1855993,1856049,1856056,1856538,1856545,1857000,1857010,1857104,1857159,1857212,1857221,1857238,1857242,1857247,1857253,1857294,1857314,1857332,1857463,1857480,1857577,1857589,1857592,1857627,1857634-1857635,1857638,1857640,1857687,1857936,1858032,1858053,1858123,1858139,1858385,1858424,1858571,1858578,1858810,1858926,1858931,1859020,1859231,1859292,1859294,1859350-1859351,1859359,1859365,1859533,1859609
,1859612,1859619,1859711,1859716,1859772,1859776,1859780,1859843,1859854,1859881,1860120,1860131,1860137,1860202,1860278,1860328,1860330,1860355,1860393,1860442,1860548,1860564-1860565,1860931,1861114,1861270,1861626,1861743,1861757,1861763,1861770,1861776,1861780,1862044,1862093,1862266,1862370,1862422,1862447-1862448,1862465,1862499,1862531,1862536-1862537,1862728,1862746,1862806,1862817,1862881,1862926-1862927,1862976-1862977,1863076,1863081,1863086,1863369,1863405,1863540,1863633-1863634,1863642,1863645,1864349,1864353,1865752
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1866447&r1=1866446&r2=1866447&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Thu Sep 5 10:47:07 2019
@@ -3386,4 +3386,8 @@ public final class DocumentNodeStore
int getUpdateLimit() {
return updateLimit;
}
+
+ boolean isReadOnlyMode() {
+ return readOnlyMode;
+ }
}
Modified: jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java?rev=1866447&r1=1866446&r2=1866447&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java (original)
+++ jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBean.java Thu Sep 5 10:47:07 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/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java?rev=1866447&r1=1866446&r2=1866447&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java (original)
+++ jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java Thu Sep 5 10:47:07 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,50 @@ 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) {
+ final String to = Utils.getKeyUpperLimit(path);
+ final String from = Utils.getKeyLowerLimit(path);
+ return nodeStore.getDocumentStore().query(Collection.NODES, from, to, 10000);
+ }
}
Modified: jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1866447&r1=1866446&r2=1866447&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java (original)
+++ jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java Thu Sep 5 10:47:07 2019
@@ -684,6 +684,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 {