Search in sources :

Example 6 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)

Example 7 with ReadOnlyFileStore

use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.

the class FileStoreRestoreImpl method restore.

@Override
public void restore(File source, File destination) throws IOException, InvalidFileStoreVersionException {
    if (!validFileStore(source)) {
        throw new IOException("Folder " + source + " is not a valid FileStore directory");
    }
    ReadOnlyFileStore restore = fileStoreBuilder(source).buildReadOnly();
    Stopwatch watch = Stopwatch.createStarted();
    FileStore store = fileStoreBuilder(destination).build();
    SegmentNodeState current = store.getHead();
    try {
        SegmentNodeState head = restore.getHead();
        int gen = head.getRecordId().getSegmentId().getGcGeneration();
        SegmentBufferWriter bufferWriter = new SegmentBufferWriter(store.getSegmentIdProvider(), store.getReader(), "r", gen);
        SegmentWriter writer = new SegmentWriter(store, store.getReader(), store.getSegmentIdProvider(), store.getBlobStore(), new WriterCacheManager.Default(), bufferWriter);
        SegmentGCOptions gcOptions = defaultGCOptions().setOffline();
        Compactor compactor = new Compactor(store.getReader(), writer, store.getBlobStore(), Suppliers.ofInstance(false), gcOptions);
        compactor.setContentEqualityCheck(true);
        SegmentNodeState after = compactor.compact(current, head, current);
        store.getRevisions().setHead(current.getRecordId(), after.getRecordId());
    } finally {
        restore.close();
        store.close();
    }
    watch.stop();
    log.info("Restore finished in {}.", watch);
}
Also used : ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Compactor(org.apache.jackrabbit.oak.segment.Compactor) SegmentGCOptions(org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) SegmentBufferWriter(org.apache.jackrabbit.oak.segment.SegmentBufferWriter) Stopwatch(com.google.common.base.Stopwatch) WriterCacheManager(org.apache.jackrabbit.oak.segment.WriterCacheManager) IOException(java.io.IOException) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter)

Example 8 with ReadOnlyFileStore

use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.

the class NodeStoreFixtureProvider method configureSegment.

private static NodeStore configureSegment(Options options, BlobStore blobStore, StatisticsProvider statisticsProvider, Closer closer, boolean readOnly) throws IOException, InvalidFileStoreVersionException {
    String path = options.getOptionBean(CommonOptions.class).getStoreArg();
    FileStoreBuilder builder = fileStoreBuilder(new File(path)).withMaxFileSize(256);
    if (blobStore != null) {
        builder.withBlobStore(blobStore);
    }
    NodeStore nodeStore;
    if (readOnly) {
        ReadOnlyFileStore fileStore = builder.withStatisticsProvider(statisticsProvider).buildReadOnly();
        closer.register(fileStore);
        nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    } else {
        FileStore fileStore = builder.withStatisticsProvider(statisticsProvider).build();
        closer.register(fileStore);
        nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    }
    return nodeStore;
}
Also used : ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) File(java.io.File)

Example 9 with ReadOnlyFileStore

use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.

the class SegmentGraphTest method testSegmentGraph.

@Test
public void testSegmentGraph() throws Exception {
    ReadOnlyFileStore store = fileStoreBuilder(getStoreFolder()).buildReadOnly();
    try {
        Graph<UUID> segmentGraph = parseSegmentGraph(store, Predicates.<UUID>alwaysTrue());
        assertEquals(segments, newHashSet(segmentGraph.vertices()));
        Map<UUID, Set<UUID>> map = newHashMap();
        for (Entry<UUID, Multiset<UUID>> entry : segmentGraph.edges()) {
            map.put(entry.getKey(), entry.getValue().elementSet());
        }
        assertEquals(references, 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) UUID(java.util.UUID) Test(org.junit.Test)

Example 10 with ReadOnlyFileStore

use of org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore in project jackrabbit-oak by apache.

the class SegmentGraphTest method testSegmentGraphWithFilter.

@Test
public void testSegmentGraphWithFilter() throws Exception {
    ReadOnlyFileStore store = fileStoreBuilder(getStoreFolder()).buildReadOnly();
    try {
        Predicate<UUID> filter = createRegExpFilter(".*(writer2|writer3).*", store.getSegmentIdProvider());
        Graph<UUID> segmentGraph = parseSegmentGraph(store, filter);
        assertEquals(filteredSegments, newHashSet(segmentGraph.vertices()));
        Map<UUID, Set<UUID>> map = newHashMap();
        for (Entry<UUID, Multiset<UUID>> entry : segmentGraph.edges()) {
            map.put(entry.getKey(), entry.getValue().elementSet());
        }
        assertEquals(filteredReferences, 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) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ReadOnlyFileStore (org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore)11 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)5 Test (org.junit.Test)5 File (java.io.File)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 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 InvalidFileStoreVersionException (org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException)2 Stopwatch (com.google.common.base.Stopwatch)1 PrintWriter (java.io.PrintWriter)1 Compactor (org.apache.jackrabbit.oak.segment.Compactor)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 Segment (org.apache.jackrabbit.oak.segment.Segment)1 SegmentBufferWriter (org.apache.jackrabbit.oak.segment.SegmentBufferWriter)1