This is an automated email from the ASF dual-hosted git repository.

mreutegg pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 5b05f24ecb OAK-10357: Path option for documentstore-check
     new 9299e4f8f1 Merge pull request #1031 from mreutegg/OAK-10357
5b05f24ecb is described below

commit 5b05f24ecb02fe15ab9053e8a6230a2ef7689c24
Author: Marcel Reutegger <[email protected]>
AuthorDate: Tue Jul 18 13:51:44 2023 +0200

    OAK-10357: Path option for documentstore-check
---
 .../plugins/document/check/DocumentStoreCheck.java | 30 ++++++++++++++++++---
 .../oak/run/DocumentStoreCheckCommand.java         | 11 ++++++++
 .../oak/run/DocumentStoreCheckCommandTest.java     | 31 ++++++++++++++++++++++
 3 files changed, 69 insertions(+), 3 deletions(-)

diff --git 
a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/check/DocumentStoreCheck.java
 
b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/check/DocumentStoreCheck.java
index 7bcaf171a1..d5804088b6 100644
--- 
a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/check/DocumentStoreCheck.java
+++ 
b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/check/DocumentStoreCheck.java
@@ -24,6 +24,7 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -31,15 +32,18 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
+import java.util.stream.Collectors;
 
 import org.apache.jackrabbit.guava.common.io.Closer;
 
 import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
 import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
+import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
 import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
 import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
 import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.jackrabbit.JcrConstants.JCR_BASEVERSION;
@@ -91,6 +95,8 @@ public class DocumentStoreCheck {
 
     private final boolean consistency;
 
+    private final List<String> paths;
+
     private DocumentStoreCheck(DocumentNodeStore ns,
                                DocumentStore store,
                                Closer closer,
@@ -106,7 +112,8 @@ public class DocumentStoreCheck {
                                boolean predecessors,
                                boolean successors,
                                boolean uuid,
-                               boolean consistency) {
+                               boolean consistency,
+                               List<String> paths) {
         this.ns = ns;
         this.store = store;
         this.closer = closer;
@@ -129,6 +136,7 @@ public class DocumentStoreCheck {
         this.successors = successors;
         this.uuid = uuid;
         this.consistency = consistency;
+        this.paths = paths;
     }
 
     public void run() throws Exception {
@@ -136,7 +144,7 @@ public class DocumentStoreCheck {
         scheduleResultWriter(results);
 
         DocumentProcessor processor = createDocumentProcessor();
-        for (NodeDocument doc : getAllDocs(store)) {
+        for (NodeDocument doc : paths.isEmpty() ? getAllDocs(store) : 
getDocs(store, paths)) {
             processor.processDocument(doc, results);
         }
         processor.end(results);
@@ -233,6 +241,14 @@ public class DocumentStoreCheck {
         }
     }
 
+    private static Iterable<NodeDocument> getDocs(DocumentStore store,
+                                                  List<String> paths) {
+        return paths.stream()
+                .map(p -> store.find(Collection.NODES, Utils.getIdFromPath(p)))
+                .filter(Objects::nonNull)
+                .collect(Collectors.toList());
+    }
+
     public static class Builder {
 
         private final DocumentNodeStore ns;
@@ -267,6 +283,8 @@ public class DocumentStoreCheck {
 
         private boolean consistency;
 
+        private final List<String> paths = new ArrayList<>();
+
         public Builder(DocumentNodeStore ns,
                        DocumentStore store,
                        Closer closer) {
@@ -340,10 +358,16 @@ public class DocumentStoreCheck {
             return this;
         }
 
+        public Builder withPaths(List<String> paths) {
+            this.paths.clear();
+            this.paths.addAll(paths);
+            return this;
+        }
+
         public DocumentStoreCheck build() {
             return new DocumentStoreCheck(ns, store, closer, progress, silent,
                     summary, counter, numThreads, output, orphan, baseVersion,
-                    versionHistory, predecessors, successors, uuid, 
consistency);
+                    versionHistory, predecessors, successors, uuid, 
consistency, paths);
         }
     }
 
diff --git 
a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DocumentStoreCheckCommand.java
 
b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DocumentStoreCheckCommand.java
index 6ab3e89d67..9c99812498 100644
--- 
a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DocumentStoreCheckCommand.java
+++ 
b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DocumentStoreCheckCommand.java
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.run;
 
+import java.util.List;
+
 import org.apache.jackrabbit.guava.common.io.Closer;
 
 import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
@@ -74,6 +76,7 @@ class DocumentStoreCheckCommand implements Command {
                     .withSummary(options.withSummary())
                     .withCounter(options.withCounter())
                     .withNumThreads(options.getNumThreads())
+                    .withPaths(options.getPaths())
                     .build().run();
 
         } catch (Throwable e) {
@@ -111,6 +114,8 @@ class DocumentStoreCheckCommand implements Command {
 
         final OptionSpec<Integer> numThreads;
 
+        final OptionSpec<String> paths;
+
         public CheckOptions(String usage) {
             super(usage);
 
@@ -139,6 +144,8 @@ class DocumentStoreCheckCommand implements Command {
                     
.withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE);
             numThreads = parser.accepts("numThreads", "Use this number of 
threads to check consistency")
                     
.withRequiredArg().ofType(Integer.class).defaultsTo(Runtime.getRuntime().availableProcessors());
+            paths = parser.accepts("path", "Limit check to given path")
+                    .withRequiredArg().ofType(String.class);
         }
 
         @Override
@@ -199,6 +206,10 @@ class DocumentStoreCheckCommand implements Command {
             return numThreads.value(options);
         }
 
+        public List<String> getPaths() {
+            return paths.values(options);
+        }
+
         boolean isHelp() {
             return options.has(help);
         }
diff --git 
a/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DocumentStoreCheckCommandTest.java
 
b/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DocumentStoreCheckCommandTest.java
index b041629c82..5083b29be6 100644
--- 
a/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DocumentStoreCheckCommandTest.java
+++ 
b/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DocumentStoreCheckCommandTest.java
@@ -157,6 +157,37 @@ public class DocumentStoreCheckCommandTest {
         assertThat(lines.get(0), containsString(JCR_UUID));
     }
 
+    @Test
+    public void path() throws Exception {
+        createNodeWithUUID(false);
+        DocumentStoreCheckCommand cmd = new DocumentStoreCheckCommand();
+        cmd.execute(
+                "--summary", "false",
+                "--counter", "false",
+                "--path", "/referenceable",
+                "--out", output.getAbsolutePath(),
+                MongoUtils.URL
+        );
+        List<String> lines = Files.readAllLines(output.toPath(), UTF_8);
+        assertEquals(1, lines.size());
+        assertThat(lines.get(0), containsString(JCR_UUID));
+    }
+
+    @Test
+    public void pathDoesNotExist() throws Exception {
+        createNodeWithUUID(false);
+        DocumentStoreCheckCommand cmd = new DocumentStoreCheckCommand();
+        cmd.execute(
+                "--summary", "false",
+                "--counter", "false",
+                "--path", "/does-not-exist",
+                "--out", output.getAbsolutePath(),
+                MongoUtils.URL
+        );
+        List<String> lines = Files.readAllLines(output.toPath(), UTF_8);
+        assertThat(lines, is(empty()));
+    }
+
     private DocumentNodeStore createDocumentNodeStore() {
         MongoConnection c = connectionFactory.getConnection();
         assertNotNull(c);

Reply via email to