Search in sources :

Example 1 with SegmentIdProvider

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

the class StandbyTestUtils method mockSegment.

public static Segment mockSegment(UUID uuid, byte[] buffer) {
    SegmentStore store = mock(SegmentStore.class);
    SegmentIdProvider idProvider = mock(SegmentIdProvider.class);
    SegmentReader reader = mock(SegmentReader.class);
    long msb = uuid.getMostSignificantBits();
    long lsb = uuid.getLeastSignificantBits();
    SegmentId id = new SegmentId(store, msb, lsb);
    ByteBuffer data = ByteBuffer.wrap(buffer);
    return new Segment(idProvider, reader, id, data);
}
Also used : SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) SegmentIdProvider(org.apache.jackrabbit.oak.segment.SegmentIdProvider) ByteBuffer(java.nio.ByteBuffer) SegmentReader(org.apache.jackrabbit.oak.segment.SegmentReader) Segment(org.apache.jackrabbit.oak.segment.Segment) SegmentStore(org.apache.jackrabbit.oak.segment.SegmentStore)

Example 2 with SegmentIdProvider

use of org.apache.jackrabbit.oak.segment.SegmentIdProvider 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

SegmentIdProvider (org.apache.jackrabbit.oak.segment.SegmentIdProvider)2 PrintWriter (java.io.PrintWriter)1 ByteBuffer (java.nio.ByteBuffer)1 RecordId (org.apache.jackrabbit.oak.segment.RecordId)1 RecordId.fromString (org.apache.jackrabbit.oak.segment.RecordId.fromString)1 Segment (org.apache.jackrabbit.oak.segment.Segment)1 SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)1 SegmentReader (org.apache.jackrabbit.oak.segment.SegmentReader)1 SegmentStore (org.apache.jackrabbit.oak.segment.SegmentStore)1 ReadOnlyFileStore (org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore)1