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 2023/06/26 14:17:02 UTC
[jackrabbit-oak] branch trunk updated: OAK-10313: Counter for DocumentStore check
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 495f96a098 OAK-10313: Counter for DocumentStore check
new 0b6d60bfc3 Merge pull request #996 from mreutegg/OAK-10315
495f96a098 is described below
commit 495f96a0981248f0da6f7d555bda9c8c9cce8dba
Author: Marcel Reutegger <ma...@gmail.com>
AuthorDate: Tue Jun 20 17:16:30 2023 +0200
OAK-10313: Counter for DocumentStore check
---
.../plugins/document/check/DocumentStoreCheck.java | 16 ++++-
.../oak/plugins/document/check/NodeCounter.java | 77 ++++++++++++++++++++++
.../oak/run/DocumentStoreCheckCommand.java | 9 +++
3 files changed, 101 insertions(+), 1 deletion(-)
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 a6cd3dd503..1bde0c8fbe 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
@@ -69,6 +69,8 @@ public class DocumentStoreCheck {
private final boolean summary;
+ private final boolean counter;
+
private final int numThreads;
private final ExecutorService executorService;
@@ -93,6 +95,7 @@ public class DocumentStoreCheck {
boolean progress,
boolean silent,
boolean summary,
+ boolean counter,
int numThreads,
String output,
boolean orphan,
@@ -107,6 +110,7 @@ public class DocumentStoreCheck {
this.progress = progress;
this.silent = silent;
this.summary = summary;
+ this.counter = counter;
this.numThreads = numThreads;
this.executorService = new ThreadPoolExecutor(
numThreads, numThreads, 1, TimeUnit.MINUTES,
@@ -176,6 +180,9 @@ public class DocumentStoreCheck {
private DocumentProcessor createDocumentProcessor() {
List<DocumentProcessor> processors = new ArrayList<>();
+ if (counter) {
+ processors.add(new NodeCounter(ns, ns.getHeadRevision(), executorService));
+ }
if (summary) {
processors.add(new Summary(numThreads));
}
@@ -233,6 +240,8 @@ public class DocumentStoreCheck {
private boolean summary;
+ private boolean counter;
+
private int numThreads = Runtime.getRuntime().availableProcessors();
private String output;
@@ -272,6 +281,11 @@ public class DocumentStoreCheck {
return this;
}
+ public Builder withCounter(boolean enable) {
+ this.counter = enable;
+ return this;
+ }
+
public Builder withNumThreads(int numThreads) {
this.numThreads = numThreads;
return this;
@@ -314,7 +328,7 @@ public class DocumentStoreCheck {
public DocumentStoreCheck build() {
return new DocumentStoreCheck(ns, store, closer, progress, silent,
- summary, numThreads, output, orphan, baseVersion,
+ summary, counter, numThreads, output, orphan, baseVersion,
versionHistory, predecessors, successors, uuid);
}
}
diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/check/NodeCounter.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/check/NodeCounter.java
new file mode 100644
index 0000000000..de282e80be
--- /dev/null
+++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/check/NodeCounter.java
@@ -0,0 +1,77 @@
+/*
+ * 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.check;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Consumer;
+
+import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.Path;
+import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Count documents and nodes that exist.
+ */
+public class NodeCounter extends AsyncNodeStateProcessor {
+
+ private final AtomicLong numDocuments = new AtomicLong();
+
+ private final AtomicLong numNodes = new AtomicLong();
+
+ public NodeCounter(DocumentNodeStore ns,
+ RevisionVector headRevision,
+ ExecutorService executorService) {
+ super(ns, headRevision, executorService);
+ }
+
+ @Override
+ protected void runTask(@NotNull Path path,
+ @Nullable NodeState state,
+ @NotNull Consumer<Result> resultConsumer) {
+ numDocuments.incrementAndGet();
+ if (state != null) {
+ numNodes.incrementAndGet();
+ }
+ }
+
+ @Override
+ public void end(@NotNull BlockingQueue<Result> results)
+ throws InterruptedException {
+ JsopBuilder json = new JsopBuilder();
+ json.object();
+ json.key("type").value("counter");
+ json.key("documents").value(numDocuments.get());
+ json.key("nodes").value(numNodes.get());
+ json.key("exist").value(getPercentageExist());
+ json.endObject();
+ results.put(json::toString);
+ }
+
+ private String getPercentageExist() {
+ float p = 0.0f;
+ if (numDocuments.get() != 0) {
+ p = 100f * numNodes.get() / numDocuments.get();
+ }
+ return String.format("%.2f%%", p);
+ }
+}
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 cd39bb6a56..b815561bc1 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
@@ -71,6 +71,7 @@ class DocumentStoreCheckCommand implements Command {
.withProgress(options.withProgress())
.isSilent(options.isSilent())
.withSummary(options.withSummary())
+ .withCounter(options.withCounter())
.withNumThreads(options.getNumThreads())
.build().run();
@@ -91,6 +92,8 @@ class DocumentStoreCheckCommand implements Command {
final OptionSpec<Boolean> summary;
+ final OptionSpec<Boolean> counter;
+
final OptionSpec<Boolean> orphan;
final OptionSpec<Boolean> baseVersion;
@@ -115,6 +118,8 @@ class DocumentStoreCheckCommand implements Command {
.withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE);
summary = parser.accepts("summary", "Write a summary message at the end")
.withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE);
+ counter = parser.accepts("counter", "Count documents and nodes that exist")
+ .withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE);
orphan = parser.accepts("orphan", "Check for orphaned nodes")
.withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE);
baseVersion = parser.accepts("baseVersion", "Check jcr:baseVersion reference")
@@ -153,6 +158,10 @@ class DocumentStoreCheckCommand implements Command {
return summary.value(options);
}
+ public boolean withCounter() {
+ return counter.value(options);
+ }
+
public boolean withOrphan() {
return orphan.value(options);
}