Search in sources :

Example 1 with ReadOnlyFileStore

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;
}
Also used : ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) File(java.io.File) SegmentVersion(org.apache.jackrabbit.oak.segment.SegmentVersion)

Example 2 with ReadOnlyFileStore

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();
    }
}
Also used : Sets.newHashSet(com.google.common.collect.Sets.newHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) Multiset(com.google.common.collect.Multiset) Test(org.junit.Test)

Example 3 with ReadOnlyFileStore

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();
    }
}
Also used : FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) RecordType(org.apache.jackrabbit.oak.segment.RecordType) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) IOException(java.io.IOException) File(java.io.File) Segment(org.apache.jackrabbit.oak.segment.Segment)

Example 4 with ReadOnlyFileStore

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);
}
Also used : ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) Test(org.junit.Test)

Example 5 with ReadOnlyFileStore

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.");
    }
}
Also used : ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) SegmentIdProvider(org.apache.jackrabbit.oak.segment.SegmentIdProvider) RecordId.fromString(org.apache.jackrabbit.oak.segment.RecordId.fromString) RecordId(org.apache.jackrabbit.oak.segment.RecordId) PrintWriter(java.io.PrintWriter)

Aggregations

ReadOnlyFileStore (org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore)12 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)6 File (java.io.File)5 Test (org.junit.Test)5 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Multiset (com.google.common.collect.Multiset)3 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)3 Set (java.util.Set)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 InvalidFileStoreVersionException (org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException)2 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)2 Stopwatch (com.google.common.base.Stopwatch)1 PrintWriter (java.io.PrintWriter)1 Compactor (org.apache.jackrabbit.oak.segment.Compactor)1 DefaultSegmentWriter (org.apache.jackrabbit.oak.segment.DefaultSegmentWriter)1 RecordId (org.apache.jackrabbit.oak.segment.RecordId)1 RecordId.fromString (org.apache.jackrabbit.oak.segment.RecordId.fromString)1 RecordType (org.apache.jackrabbit.oak.segment.RecordType)1