diff --git oak-doc/src/site/markdown/nodestore/segment/overview.md oak-doc/src/site/markdown/nodestore/segment/overview.md index 9a168a563f..121dccbd57 100644 --- oak-doc/src/site/markdown/nodestore/segment/overview.md +++ oak-doc/src/site/markdown/nodestore/segment/overview.md @@ -731,10 +731,18 @@ java -jar oak-run.jar check PATH [--mmap] [--journal JOURNAL] [--notify SECS] [- ``` The `check` tool inspects an existing Segment Store at `PATH` for eventual inconsistencies. -The algorithm implemented by this tool traverses every revision in the journal, from the most recent to the oldest. -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 algorithm implemented by this tool traverses the last revision in the journal. The actual +nodes and properties are traversed, verifying that every piece of data is reachable and undamaged. +The tool will start with the most recent entry and will go back in the history at most `--last` revisions. +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 maximum number of revisions to be verified. +Default value is `1`. If the first revision is not consistent configure the argument to `2`. +This will verify the last 2 revisions. However if the first revision is consistent the verification of the second + revision is skipped. + 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..7f0d7ddac8 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,10 @@ 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") + .withRequiredArg() + .ofType(Integer.class) + .defaultsTo(1); OptionSpec bin = parser.accepts("bin", "read the content of binary properties"); OptionSpec filter = parser.accepts("filter", "comma separated content paths to be checked") .withRequiredArg() @@ -78,6 +82,7 @@ class CheckCommand implements Command { .withCheckBinaries(options.has(bin)) .withCheckHead(shouldCheckHead(options, head, cp)) .withCheckpoints(toCheckpointsSet(options, head, cp)) + .withLast(last.value(options)) .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..d500462d3d 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 last ) { 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(last == 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..c3e0b97c9f 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 last; + private Set checkpoints; private Set filterPaths; @@ -170,6 +172,18 @@ public class Check { return this; } + /** + * Instruct the command to check only the last {@code last} + * This parameter is not required and defaults to {@code 1}. + * @param last if {@code 1} will check only the last revision. if 2 wil check up to 2 revisions. if the first revision is + * consistent will skip the second revision. + * @return this builder. + */ + public Builder withLast(Integer last){ + this.last = last; + return this; + } + /** * Instruct the command to check specified checkpoints. * This parameter is not required and defaults to "/checkpoints", @@ -298,6 +312,8 @@ public class Check { private final boolean checkHead; + private final int last; + private final Set requestedCheckpoints; private final Set filterPaths; @@ -333,6 +349,7 @@ public class Check { this.out = builder.outWriter; this.err = builder.errWriter; this.journal = journalPath(builder.path, builder.journal); + this.last = builder.last; } private static File journalPath(File segmentStore, File journal) { @@ -390,7 +407,8 @@ public class Check { checkHead, checkpoints, filterPaths, - checkBinaries + checkBinaries, + last ); print("\nSearched through {0} revisions and {1} checkpoints", result.getCheckedRevisionsCount(), checkpoints.size());