Author: mreutegg
Date: Thu Feb 19 13:00:06 2015
New Revision: 1660872
URL: http://svn.apache.org/r1660872
Log:
OAK-2528: Entries in _commitRoot not purged
Add repair option to oak-run to purge _commitRoot on a document
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentHelper.java
(with props)
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreHelper.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentHelper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentHelper.java?rev=1660872&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentHelper.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentHelper.java
Thu Feb 19 13:00:06 2015
@@ -0,0 +1,44 @@
+/*
+ * 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 java.util.SortedMap;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Helper class to access package private methods on NodeDocument.
+ */
+public class NodeDocumentHelper {
+
+ @Nonnull
+ public static SortedMap<Revision, String> getLocalMap(
+ NodeDocument doc, String key) {
+ return doc.getLocalMap(key);
+ }
+
+ @Nonnull
+ public static SortedMap<Revision, String> getLocalCommitRoot(
+ NodeDocument doc) {
+ return doc.getLocalCommitRoot();
+ }
+
+ @Nonnull
+ public static String commitRoot() {
+ return NodeDocument.COMMIT_ROOT;
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreHelper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreHelper.java?rev=1660872&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreHelper.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreHelper.java
Thu Feb 19 13:00:06 2015
@@ -0,0 +1,96 @@
+/*
+ * 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.mongo;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.QueryBuilder;
+import com.mongodb.WriteResult;
+
+import org.apache.jackrabbit.oak.plugins.document.Document;
+import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Revision;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+
+import static com.google.common.collect.Maps.newTreeMap;
+import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
+import static
org.apache.jackrabbit.oak.plugins.document.NodeDocumentHelper.commitRoot;
+import static
org.apache.jackrabbit.oak.plugins.document.NodeDocumentHelper.getLocalCommitRoot;
+import static
org.apache.jackrabbit.oak.plugins.document.NodeDocumentHelper.getLocalMap;
+
+/**
+ * Helper class to access package private methods on MongoDocumentStore.
+ */
+public class MongoDocumentStoreHelper {
+
+ public static void repair(MongoDocumentStore store, String path) {
+ DBCollection col = store.getDBCollection(NODES);
+ String id = Utils.getIdFromPath(path);
+
+ NodeDocument doc = store.find(NODES, id);
+ if (doc == null) {
+ System.out.println("No document for path " + path);
+ return;
+ }
+
+ Set<Revision> changes = Sets.newHashSet();
+ for (String key : doc.keySet()) {
+ if (Utils.isPropertyName(key) || NodeDocument.isDeletedEntry(key))
{
+ changes.addAll(getLocalMap(doc, key).keySet());
+ }
+ }
+
+ SortedMap<Revision, String> commitRoot =
newTreeMap(getLocalCommitRoot(doc));
+ if (!commitRoot.keySet().retainAll(changes)) {
+ System.out.println("Nothing to repair on " + path);
+ return;
+ }
+
+ Number modCount = doc.getModCount();
+ if (modCount == null) {
+ System.err.println("Document does not have a modCount " + path);
+ return;
+ }
+ DBObject query = QueryBuilder.start(Document.ID).is(id)
+ .and(Document.MOD_COUNT).is(modCount).get();
+ DBObject cr = new BasicDBObject();
+ for (Map.Entry<Revision, String> entry : commitRoot.entrySet()) {
+ cr.put(entry.getKey().toString(), entry.getValue());
+ }
+
+ DBObject update = new BasicDBObject();
+ update.put("$set", new BasicDBObject(commitRoot(), cr));
+ update.put("$inc", new BasicDBObject(Document.MOD_COUNT, 1L));
+
+ WriteResult result = col.update(query, update);
+ if (result.getN() == 1) {
+ int num = getLocalCommitRoot(doc).size() - commitRoot.size();
+ System.out.println("Removed " + num + " _commitRoot entries on " +
path);
+ } else {
+ System.out.println("Unable to repair " + path + " (concurrent
update).");
+ }
+
+ }
+
+}
Propchange:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java?rev=1660872&r1=1660871&r2=1660872&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
Thu Feb 19 13:00:06 2015
@@ -84,6 +84,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.LastRevRecoveryAgent;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import
org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStoreHelper;
import
org.apache.jackrabbit.oak.plugins.document.mongo.MongoMissingLastRevSeeker;
import org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable;
import org.apache.jackrabbit.oak.plugins.document.util.MapDBMapFactory;
@@ -185,6 +186,9 @@ public class Main {
case RECOVERY:
recovery(args);
break;
+ case REPAIR:
+ repair(args);
+ break;
case HELP:
default:
System.err.print("Available run modes: ");
@@ -639,6 +643,31 @@ public class Main {
closer.close();
}
}
+
+ private static void repair(String[] args) throws IOException {
+ Closer closer = Closer.create();
+ String h = "repair mongodb://host:port/database path";
+ try {
+ NodeStore store = bootstrapNodeStore(args, closer, h);
+ if (!(store instanceof DocumentNodeStore)) {
+ System.err.println("Repair only available for
DocumentNodeStore");
+ System.exit(1);
+ }
+ DocumentNodeStore dns = (DocumentNodeStore) store;
+ if (!(dns.getDocumentStore() instanceof MongoDocumentStore)) {
+ System.err.println("Repair only available for
MongoDocumentStore");
+ System.exit(1);
+ }
+ MongoDocumentStore docStore = (MongoDocumentStore)
dns.getDocumentStore();
+
+ String path = args[args.length - 1];
+ MongoDocumentStoreHelper.repair(docStore, path);
+ } catch (Throwable e) {
+ throw closer.rethrow(e);
+ } finally {
+ closer.close();
+ }
+ }
private static void debug(String[] args) throws IOException {
if (args.length == 0) {
@@ -1166,7 +1195,8 @@ public class Main {
STANDBY("standy"),
HELP("help"),
CHECKPOINTS("checkpoints"),
- RECOVERY("recovery");
+ RECOVERY("recovery"),
+ REPAIR("repair");
private final String name;