stefan-egli commented on a change in pull request #238:
URL: https://github.com/apache/jackrabbit-oak/pull/238#discussion_r453711842



##########
File path: 
oak-run/src/main/java/org/apache/jackrabbit/oak/run/FrozenNodeRefsUsingIndexCommand.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.run;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.plugins.memory.GenericPropertyState;
+import org.apache.jackrabbit.oak.run.Utils.NodeStoreOptions;
+import org.apache.jackrabbit.oak.run.commons.Command;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+import com.google.common.io.Closer;
+
+/**
+ * Scans and lists all references to nt:frozenNode and returns an exit code of 
1 if any are found (0 otherwise).
+ * <p/>
+ * This variant uses the /oak:index/reference by scanning through that list 
(only)
+ * and checking if any reference points to an nt:frozenNode (under 
/jcr:system/jcr:versionStorage
+ * at depth > 7).
+ * <p/>
+ * Example: 
+ * <pre>
+ * java -mx4g -jar oak-run-*.jar frozennoderefsusingindex 
mongodb://localhost/&lt;dbname&gt;
+ * </pre>
+ */
+public class FrozenNodeRefsUsingIndexCommand implements Command {
+
+    public static final String NAME = "frozennoderefsusingindex";
+
+    @Override
+    public void execute(String... args) throws Exception {
+        String help = NAME + " {<path>|<mongo-uri>|<jdbc-uri>} [options]";
+        Utils.NodeStoreOptions nopts = new 
Utils.NodeStoreOptions(help).parse(args);
+        if (hasNtFrozenNodeReferences(nopts)) {
+            System.err.println("FAILURE: References (in /oak:index/references) 
to nt:frozenNode found.");
+            System.exit(1);
+        } else {
+            System.out.println("SUCCESS: No references (in 
/oak:index/references) to nt:frozenNode found.");
+        }
+    }
+
+    private static boolean hasNtFrozenNodeReferences(NodeStoreOptions nopts) 
throws IOException {
+        Closer closer = Utils.createCloserWithShutdownHook();
+        try {
+            NodeStore store = Utils.bootstrapNodeStore(nopts, closer);
+            NodeState root = store.getRoot();
+
+            NodeBuilder b = root.builder();
+            NodeBuilder content = b.child("content");
+            PropertyState refProp = 
GenericPropertyState.referenceProperty("myref", 
"dd31e965-7e74-4c04-9a64-6698ecb4c624");
+            content.setProperty(refProp);
+            store.merge(b, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+            NodeState oakIndex = root.getChildNode("oak:index");
+            NodeState refIndex = oakIndex.getChildNode("reference");
+            NodeState uuidIndex = oakIndex.getChildNode("uuid");
+            NodeState uuids = uuidIndex.getChildNode(":index");
+            System.out.println("Scanning ... refindex = " + refIndex);
+            NodeState references = refIndex.getChildNode(":references");
+
+            List<FrozenNodeRef> list = new LinkedList<FrozenNodeRef>();

Review comment:
       Agree - changed to a `count` at 
https://github.com/apache/jackrabbit-oak/pull/238/commits/fb8b330c4f248078bb2dce62cfb19ae90a50030c




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to