diff --git oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java index aecd81a727..a23012fac8 100644 --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java @@ -103,11 +103,11 @@ public class ConsistencyChecker { // Do nothing. } - protected void onCheckTree(String path) { + protected void onCheckTree(String path, boolean head) { // Do nothing. } - protected void onCheckTreeEnd() { + protected void onCheckTreeEnd(boolean head) { // Do nothing. } @@ -215,25 +215,25 @@ public class ConsistencyChecker { return checkNodeAndDescendants(node, path, binaries); } - private String checkTreeConsistency(NodeState root, String path, Set corruptedPaths, boolean binaries) { + private String checkTreeConsistency(NodeState root, String path, Set corruptedPaths, boolean binaries, boolean head) { String corruptedPath = findFirstCorruptedPathInSet(root, corruptedPaths, binaries); if (corruptedPath != null) { return corruptedPath; } - onCheckTree(path); + onCheckTree(path, head); corruptedPath = findFirstCorruptedPathInTree(root, path, binaries); - onCheckTreeEnd(); + onCheckTreeEnd(head); return corruptedPath; } - private boolean checkPathConsistency(NodeState root, PathToCheck ptc, JournalEntry entry, boolean binaries) { + private boolean checkPathConsistency(NodeState root, PathToCheck ptc, JournalEntry entry, boolean binaries, boolean head) { if (ptc.journalEntry != null) { return true; } - String corruptPath = checkTreeConsistency(root, ptc.path, ptc.corruptPaths, binaries); + String corruptPath = checkTreeConsistency(root, ptc.path, ptc.corruptPaths, binaries, head); if (corruptPath != null) { ptc.corruptPaths.add(corruptPath); @@ -245,11 +245,11 @@ public class ConsistencyChecker { return true; } - private boolean checkAllPathsConsistency(NodeState root, List paths, JournalEntry entry, boolean binaries) { + private boolean checkAllPathsConsistency(NodeState root, List paths, JournalEntry entry, boolean binaries, boolean head) { boolean result = true; for (PathToCheck ptc : paths) { - if (!checkPathConsistency(root, ptc, entry, binaries)) { + if (!checkPathConsistency(root, ptc, entry, binaries, head)) { result = false; } } @@ -265,7 +265,7 @@ public class ConsistencyChecker { } onCheckHead(); - return checkAllPathsConsistency(store.getRoot(), paths, entry, binaries); + return checkAllPathsConsistency(store.getRoot(), paths, entry, binaries, true); } private boolean checkCheckpointConsistency(SegmentNodeStore store, String checkpoint, List paths, JournalEntry entry, boolean binaries) { @@ -284,7 +284,7 @@ public class ConsistencyChecker { return false; } - return checkAllPathsConsistency(root, paths, entry, binaries); + return checkAllPathsConsistency(root, paths, entry, binaries, false); } private boolean checkCheckpointsConsistency(SegmentNodeStore store, Map> paths, JournalEntry entry, boolean binaries) { @@ -336,7 +336,7 @@ public class ConsistencyChecker { * during a full traversal of the tree. */ public String checkTreeConsistency(NodeState root, Set corruptedPaths, boolean binaries) { - return checkTreeConsistency(root, "/", corruptedPaths, binaries); + return checkTreeConsistency(root, "/", corruptedPaths, binaries, true); } public final ConsistencyCheckResult checkConsistency( diff --git oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java index d1ea7cf8a5..8adf5a979d 100644 --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java @@ -84,6 +84,8 @@ public class Check { private boolean ioStatistics; + private RepositoryStatistics repoStatistics; + private PrintWriter outWriter; private PrintWriter errWriter; @@ -208,6 +210,18 @@ public class Check { return this; } + /** + * Attach a repository statistics instance to collect info on nodes + * and properties checked on head. + * + * @param repoStatistics instance to collect statistics + * @return this builder. + */ + public Builder withRepositoryStatistics(RepositoryStatistics repoStatistics) { + this.repoStatistics = repoStatistics; + return this; + } + /** * The text output stream writer used to print normal output. * @param outWriter the output writer. @@ -259,6 +273,19 @@ public class Check { } + public static class RepositoryStatistics { + int headNodeCount; + int headPropertyCount; + + public int getHeadNodeCount() { + return headNodeCount; + } + + public int getHeadPropertyCount() { + return headPropertyCount; + } + } + private final File path; private final boolean mmap; @@ -277,13 +304,19 @@ public class Check { private final boolean ioStatistics; + private RepositoryStatistics repoStatistics; + private final PrintWriter out; private final PrintWriter err; - private int nodeCount; + private int currentNodeCount; + + private int currentPropertyCount; - private int propertyCount; + private int headNodeCount; + + private int headPropertyCount; private long lastDebugEvent; @@ -296,6 +329,7 @@ public class Check { this.requestedCheckpoints = builder.checkpoints; this.filterPaths = builder.filterPaths; this.ioStatistics = builder.ioStatistics; + this.repoStatistics = builder.repoStatistics; this.out = builder.outWriter; this.err = builder.errWriter; this.journal = journalPath(builder.path, builder.journal); @@ -331,6 +365,11 @@ public class Check { print("[I/O] Segment read: Total time: {0} ns", ioMonitor.time.get()); } + if (repoStatistics != null) { + repoStatistics.headNodeCount = headNodeCount; + repoStatistics.headPropertyCount = headPropertyCount; + } + return 0; } catch (Exception e) { e.printStackTrace(err); @@ -390,6 +429,8 @@ public class Check { @Override protected void onCheckHead() { + headNodeCount = 0; + headPropertyCount = 0; print("\nChecking head\n"); } @@ -424,26 +465,31 @@ public class Check { } @Override - protected void onCheckTree(String path) { - nodeCount = 0; - propertyCount = 0; + protected void onCheckTree(String path, boolean head) { + currentNodeCount = 0; + currentPropertyCount = 0; print("Checking {0}", path); } @Override - protected void onCheckTreeEnd() { - print("Checked {0} nodes and {1} properties", nodeCount, propertyCount); + protected void onCheckTreeEnd(boolean head) { + if (head) { + headNodeCount += currentNodeCount; + headPropertyCount += currentPropertyCount; + } + + print("Checked {0} nodes and {1} properties", currentNodeCount, currentPropertyCount); } @Override protected void onCheckNode(String path) { debug("Traversing {0}", path); - nodeCount++; + currentNodeCount++; } @Override protected void onCheckProperty() { - propertyCount++; + currentPropertyCount++; } @Override