use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.
the class SegmentTarUtils method checkFileStoreVersionOrFail.
private static File checkFileStoreVersionOrFail(String path, boolean force) throws IOException, InvalidFileStoreVersionException {
File directory = new File(path);
if (!directory.exists()) {
return directory;
}
ReadOnlyFileStore store = openReadOnlyFileStore(directory, false);
try {
SegmentVersion segmentVersion = getSegmentVersion(store);
if (segmentVersion != LATEST_VERSION) {
if (force) {
System.out.printf("Segment version mismatch. Found %s, expected %s. Forcing execution.\n", segmentVersion, LATEST_VERSION);
} else {
throw new RuntimeException(String.format("Segment version mismatch. Found %s, expected %s. Aborting.", segmentVersion, LATEST_VERSION));
}
}
} finally {
store.close();
}
return directory;
}
use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.
the class SegmentGraphTest method testGCGraph.
@Test
public void testGCGraph() throws Exception {
// TODO Improve test coverage to non trivial cases with more than a single generation
// This is quite tricky as there is no easy way to construct a file store with
// a segment graphs having edges between generations (OAK-3348)
ReadOnlyFileStore store = fileStoreBuilder(getStoreFolder()).buildReadOnly();
try {
Graph<String> gcGraph = SegmentGraph.parseGCGraph(store);
assertEquals(ImmutableSet.of("0"), newHashSet(gcGraph.vertices()));
Map<String, Set<String>> map = newHashMap();
for (Entry<String, Multiset<String>> entry : gcGraph.edges()) {
map.put(entry.getKey(), entry.getValue().elementSet());
}
assertEquals(ImmutableMap.of("0", singleton("0")), map);
} finally {
store.close();
}
}
use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.
the class SegmentTarFactory method hasExternalBlobReferences.
@Override
public boolean hasExternalBlobReferences() throws IOException {
final FileStoreBuilder builder = fileStoreBuilder(new File(dir, "segmentstore"));
builder.withMaxFileSize(256);
builder.withMemoryMapping(false);
ReadOnlyFileStore fs;
try {
fs = builder.buildReadOnly();
} catch (InvalidFileStoreVersionException e) {
throw new IOException(e);
}
try {
for (SegmentId id : fs.getSegmentIds()) {
if (!id.isDataSegmentId()) {
continue;
}
id.getSegment().forEachRecord(new Segment.RecordConsumer() {
@Override
public void consume(int number, RecordType type, int offset) {
// see java.nio.file.FileVisitor
if (type == RecordType.BLOB_ID) {
throw new ExternalBlobFound();
}
}
});
}
return false;
} catch (ExternalBlobFound e) {
return true;
} finally {
fs.close();
}
}
use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.
the class SegmentBufferWriterTest method nonDirtyBuffersShouldNotBeFlushed.
@Test
public void nonDirtyBuffersShouldNotBeFlushed() throws Exception {
List<SegmentId> before;
try (FileStore store = openFileStore()) {
// init
}
try (ReadOnlyFileStore store = openReadOnlyFileStore()) {
before = newArrayList(store.getSegmentIds());
}
try (FileStore store = openFileStore()) {
defaultSegmentWriterBuilder("t").build(store).flush();
}
List<SegmentId> after;
try (ReadOnlyFileStore store = openReadOnlyFileStore()) {
after = newArrayList(store.getSegmentIds());
}
assertEquals(before, after);
}
use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.
the class Diff method diff.
private void diff() throws Exception {
System.out.println("Store " + path);
System.out.println("Writing diff to " + out);
String[] tokens = interval.trim().split("\\.\\.");
if (tokens.length != 2) {
System.out.println("Error parsing revision interval '" + interval + "'.");
return;
}
try (ReadOnlyFileStore store = fileStoreBuilder(path).withBlobStore(newBasicReadOnlyBlobStore()).buildReadOnly()) {
SegmentIdProvider idProvider = store.getSegmentIdProvider();
RecordId idL;
try {
if (tokens[0].equalsIgnoreCase("head")) {
idL = store.getRevisions().getHead();
} else {
idL = fromString(idProvider, tokens[0]);
}
} catch (IllegalArgumentException e) {
System.out.println("Invalid left endpoint for interval " + interval);
return;
}
RecordId idR;
try {
if (tokens[1].equalsIgnoreCase("head")) {
idR = store.getRevisions().getHead();
} else {
idR = fromString(idProvider, tokens[1]);
}
} catch (IllegalArgumentException e) {
System.out.println("Invalid left endpoint for interval " + interval);
return;
}
long start = System.currentTimeMillis();
try (PrintWriter pw = new PrintWriter(out)) {
if (incremental) {
List<String> revs = readRevisions(path);
System.out.println("Generating diff between " + idL + " and " + idR + " incrementally. Found " + revs.size() + " revisions.");
int s = revs.indexOf(idL.toString10());
int e = revs.indexOf(idR.toString10());
if (s == -1 || e == -1) {
System.out.println("Unable to match input revisions with FileStore.");
return;
}
List<String> revDiffs = revs.subList(Math.min(s, e), Math.max(s, e) + 1);
if (s > e) {
// reverse list
revDiffs = reverse(revDiffs);
}
if (revDiffs.size() < 2) {
System.out.println("Nothing to diff: " + revDiffs);
return;
}
Iterator<String> revDiffsIt = revDiffs.iterator();
RecordId idLt = fromString(idProvider, revDiffsIt.next());
while (revDiffsIt.hasNext()) {
RecordId idRt = fromString(idProvider, revDiffsIt.next());
boolean good = diff(store, idLt, idRt, pw);
idLt = idRt;
if (!good && !ignoreMissingSegments) {
break;
}
}
} else {
System.out.println("Generating diff between " + idL + " and " + idR);
diff(store, idL, idR, pw);
}
}
long dur = System.currentTimeMillis() - start;
System.out.println("Finished in " + dur + " ms.");
}
}
Aggregations