Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,19 @@ public final ConsistencyCheckResult checkConsistency(
Set<String> paths,
boolean binaries,
Integer revisionsCount
) {
return checkConsistency(store, journal, head, checkpoints, paths, binaries, revisionsCount, false);
}

public final ConsistencyCheckResult checkConsistency(
ReadOnlyFileStore store,
Iterator<JournalEntry> journal,
boolean head,
Set<String> checkpoints,
Set<String> paths,
boolean binaries,
Integer revisionsCount,
boolean failFast
) {
List<PathToCheck> headPaths = new ArrayList<>();
Map<String, List<PathToCheck>> checkpointPaths = new HashMap<>();
Expand Down Expand Up @@ -391,6 +404,8 @@ public final ConsistencyCheckResult checkConsistency(

if (overall) {
lastValidJournalEntry = journalEntry;
} else if (failFast) {
break;
}

// If every PathToCheck is assigned to a JournalEntry, stop
Expand All @@ -407,6 +422,9 @@ public final ConsistencyCheckResult checkConsistency(
}
} catch (IllegalArgumentException | SegmentNotFoundException e) {
onCheckRevisionError(revision, e);
if (failFast) {
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static class Builder {

private PrintWriter errWriter;

private boolean failFast;

private Builder() {
// Prevent external instantiation.
}
Expand Down Expand Up @@ -256,6 +258,11 @@ public Builder withErrWriter(PrintWriter errWriter) {

return this;
}

public Builder withFailFast(boolean failFast) {
this.failFast = failFast;
return this;
}

/**
* Create an executable version of the {@link Check} command.
Expand Down Expand Up @@ -325,6 +332,8 @@ public int getHeadPropertyCount() {

private final PrintWriter err;

private final boolean failFast;

private int currentNodeCount;

private int currentPropertyCount;
Expand All @@ -349,6 +358,7 @@ private Check(Builder builder) {
this.err = builder.errWriter;
this.journal = journalPath(builder.path, builder.journal);
this.revisionsCount = revisionsToCheckCount(builder.revisionsCount);
this.failFast = builder.failFast;
}

private static File journalPath(File segmentStore, File journal) {
Expand Down Expand Up @@ -411,12 +421,13 @@ private int run(ReadOnlyFileStore store, JournalReader journal) {
checkpoints,
filterPaths,
checkBinaries,
revisionsCount
revisionsCount,
failFast
);

print("\nSearched through {0} revisions and {1} checkpoints", result.getCheckedRevisionsCount(), checkpoints.size());

if (hasAnyRevision(result)) {
if (isGoodRevisionFound(result)) {
if (checkHead) {
print("\nHead");
for (Entry<String, Revision> e : result.getHeadRevisions().entrySet()) {
Expand All @@ -442,6 +453,10 @@ private int run(ReadOnlyFileStore store, JournalReader journal) {
}
}

private boolean isGoodRevisionFound(ConsistencyCheckResult result) {
return failFast ? hasAllRevision(result) : hasAnyRevision(result);
}

private ConsistencyChecker newConsistencyChecker() {
return new ConsistencyChecker() {

Expand Down Expand Up @@ -570,6 +585,10 @@ private static boolean hasAnyRevision(ConsistencyCheckResult result) {
return hasAnyHeadRevision(result) || hasAnyCheckpointRevision(result);
}

private static boolean hasAllRevision(ConsistencyCheckResult result) {
return hasAnyHeadRevision(result) && hasAnyCheckpointRevision(result);
}

private static boolean hasAnyHeadRevision(ConsistencyCheckResult result) {
return result.getHeadRevisions()
.values()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.segment.file;

import java.io.File;
import java.io.IOException;
import org.apache.jackrabbit.oak.segment.Segment;
import org.apache.jackrabbit.oak.segment.SegmentId;
import org.apache.jackrabbit.oak.segment.SegmentNotFoundException;
import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
import org.jetbrains.annotations.NotNull;

import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;

public class MockReadOnlyFileStore extends ReadOnlyFileStore {
private int failAfterReadSegmentCount;
private int readSegmentCount = 0;

@NotNull
public static MockReadOnlyFileStore buildMock(File path, File journalFile) throws InvalidFileStoreVersionException, IOException {
TarPersistence persistence = new TarPersistence(path, journalFile);
ReadOnlyRevisions revisions = new ReadOnlyRevisions(persistence);
MockReadOnlyFileStore store;
try {
store = new MockReadOnlyFileStore(fileStoreBuilder(path).withCustomPersistence(persistence));
} catch (InvalidFileStoreVersionException | IOException e) {
try {
revisions.close();
} catch (IOException re) {
//ignore
}
throw e;
}
store.bind(revisions);
return store;
}


MockReadOnlyFileStore(FileStoreBuilder builder) throws InvalidFileStoreVersionException, IOException {
super(builder);
}

public void failAfterReadSegmentCount(int count) {
this.failAfterReadSegmentCount = count;
}

@Override
public @NotNull Segment readSegment(SegmentId id) {
readSegmentCount++;
if (readSegmentCount > failAfterReadSegmentCount) {
throw new SegmentNotFoundException(id);
}
return super.readSegment(id);
}
}
Loading