diff --git oak-doc/src/site/markdown/nodestore/segment/overview.md oak-doc/src/site/markdown/nodestore/segment/overview.md index 9a168a563f..aaf8040842 100644 --- oak-doc/src/site/markdown/nodestore/segment/overview.md +++ oak-doc/src/site/markdown/nodestore/segment/overview.md @@ -735,6 +735,11 @@ The algorithm implemented by this tool traverses every revision in the journal, For every revision, the actual nodes and properties are traversed, verifying that every piece of data is reachable and undamaged. Moreover, if `--head` and `--checkpoints` options are used, the scope of the traversal can be limited to head state and/or a subset of checkpoints. A deep scan of the content tree, traversing every node and every property will be performed by default. The default scope includes head state and all checkpoints. +The optional `--last [Integer]` argument can be used to control the number of revisions to be verified. +If argument is not specified all revisions will be checked. +If specified with no value will check only the last revision. +If specified with a value will check up to the first valid revision but not more then the value provided. + The optional `--mmap [Boolean]` argument can be used to control the file access mode. Set to `true` for memory mapped access and `false` for file access (default is `true`). diff --git oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java index 8542eb1940..49a64b00c4 100644 --- oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java +++ oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java @@ -45,6 +45,9 @@ class CheckCommand implements Command { .withRequiredArg() .ofType(Long.class) .defaultsTo(Long.MAX_VALUE); + OptionSpec last = parser.accepts("last", "define the number of last revisions to be checked") + .withOptionalArg() + .ofType(Integer.class); OptionSpec bin = parser.accepts("bin", "read the content of binary properties"); OptionSpec filter = parser.accepts("filter", "comma separated content paths to be checked") .withRequiredArg() @@ -71,6 +74,17 @@ class CheckCommand implements Command { printUsageAndExit(parser, "Too many Segment Store paths specified"); } + Integer lastValue = last.value(options); + + // if the --last option is present and has no value => 1 + // else if the --last option is NOT present => max value (all revisions must be checked) + if(options.has(last) && options.valueOf(last) == null){ + lastValue = 1; + }else if(!options.has(last)){ + lastValue = Integer.MAX_VALUE; + } + + Check.Builder builder = Check.builder() .withPath(options.valueOf(dir)) .withMmap(mmapArg.value(options)) @@ -78,6 +92,7 @@ class CheckCommand implements Command { .withCheckBinaries(options.has(bin)) .withCheckHead(shouldCheckHead(options, head, cp)) .withCheckpoints(toCheckpointsSet(options, head, cp)) + .withOnlyLast(lastValue) .withFilterPaths(toSet(options, filter)) .withIOStatistics(options.has(ioStatistics)) .withOutWriter(new PrintWriter(System.out, true)) 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 a23012fac8..d473285c3b 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 @@ -345,7 +345,8 @@ public class ConsistencyChecker { boolean head, Set checkpoints, Set paths, - boolean binaries + boolean binaries, + int onlyLast ) { List headPaths = new ArrayList<>(); Map> checkpointPaths = new HashMap<>(); @@ -398,6 +399,11 @@ public class ConsistencyChecker { if (allPathsConsistent(headPaths, checkpointPaths)) { break; } + + //limit the number of revisions to be checked + if(onlyLast == revisionCount){ + break; + } } catch (IllegalArgumentException | SegmentNotFoundException e) { onCheckRevisionError(revision, e); } 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 8adf5a979d..4b288a3302 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 @@ -78,6 +78,8 @@ public class Check { private boolean checkHead; + private int onlyLast; + private Set checkpoints; private Set filterPaths; @@ -170,6 +172,19 @@ public class Check { return this; } + /** + * Instruct the command to check only the last {@code onlyLast} + * This parameter is not required. + * @param onlyLast If argument is not specified all revisions will be checked. + * If specified with a value will check up to the first valid revision but not more then the value provided. + * + * @return this builder. + */ + public Builder withOnlyLast(Integer onlyLast){ + this.onlyLast = onlyLast; + return this; + } + /** * Instruct the command to check specified checkpoints. * This parameter is not required and defaults to "/checkpoints", @@ -298,6 +313,8 @@ public class Check { private final boolean checkHead; + private final int onlyLast; + private final Set requestedCheckpoints; private final Set filterPaths; @@ -333,6 +350,7 @@ public class Check { this.out = builder.outWriter; this.err = builder.errWriter; this.journal = journalPath(builder.path, builder.journal); + this.onlyLast = builder.onlyLast; } private static File journalPath(File segmentStore, File journal) { @@ -390,7 +408,8 @@ public class Check { checkHead, checkpoints, filterPaths, - checkBinaries + checkBinaries, + onlyLast ); print("\nSearched through {0} revisions and {1} checkpoints", result.getCheckedRevisionsCount(), checkpoints.size());