Search in sources :

Example 16 with RecordId

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

the class PersistingDiff method updated.

private void updated() throws IOException {
    if (modCount % UPDATE_LIMIT == 0) {
        RecordId newBaseId = writer.writeNode(builder.getNodeState(), null);
        SegmentNodeState newBase = new SegmentNodeState(reader, writer, blobStore, newBaseId);
        builder = new MemoryNodeBuilder(newBase);
    }
    modCount++;
}
Also used : MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 17 with RecordId

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

the class DebugSegments method debugSegment.

private static void debugSegment(ReadOnlyFileStore store, String segment) {
    Matcher matcher = SEGMENT_REGEX.matcher(segment);
    if (!matcher.matches()) {
        System.err.println("Unknown argument: " + segment);
        return;
    }
    if (matcher.group(1) != null) {
        UUID uuid = UUID.fromString(matcher.group(1));
        SegmentId id = store.getSegmentIdProvider().newSegmentId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
        System.out.println(id.getSegment());
        return;
    }
    RecordId id1 = store.getRevisions().getHead();
    RecordId id2 = null;
    if (matcher.group(2) != null) {
        id1 = fromString(store.getSegmentIdProvider(), matcher.group(3));
        if (matcher.group(4) != null) {
            id2 = fromString(store.getSegmentIdProvider(), matcher.group(5));
        }
    }
    String path = "/";
    if (matcher.group(6) != null) {
        path = matcher.group(6);
    }
    if (id2 == null) {
        NodeState node = store.getReader().readNode(id1);
        System.out.println("/ (" + id1 + ") -> " + node);
        for (String name : PathUtils.elements(path)) {
            node = node.getChildNode(name);
            RecordId nid = null;
            if (node instanceof SegmentNodeState) {
                nid = ((SegmentNodeState) node).getRecordId();
            }
            System.out.println("  " + name + " (" + nid + ") -> " + node);
        }
        return;
    }
    NodeState node1 = store.getReader().readNode(id1);
    NodeState node2 = store.getReader().readNode(id2);
    for (String name : PathUtils.elements(path)) {
        node1 = node1.getChildNode(name);
        node2 = node2.getChildNode(name);
    }
    System.out.println(JsopBuilder.prettyPrint(JsopDiff.diffToJsop(node1, node2)));
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Matcher(java.util.regex.Matcher) SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) RecordId(org.apache.jackrabbit.oak.segment.RecordId) RecordId.fromString(org.apache.jackrabbit.oak.segment.RecordId.fromString) UUID(java.util.UUID) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 18 with RecordId

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

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

the class StandbyDiff method process.

private boolean process(String name, String op, NodeState before, NodeState after) {
    if (stop()) {
        return false;
    }
    if (after instanceof SegmentNodeState) {
        if (log.isTraceEnabled()) {
            log.trace("{} {}, readonly binary check {}", op, path + name, logOnly);
        }
        if (!logOnly) {
            RecordId id = ((SegmentNodeState) after).getRecordId();
            builder.setChildNode(name, store.getReader().readNode(id));
        }
        if ("checkpoints".equals(name)) {
            // traversal to verify binaries
            return true;
        }
        if (!hasDataStore) {
            return true;
        }
        // traversal to verify binaries
        return after.compareAgainstBaseState(before, new StandbyDiff(builder.getChildNode(name), store, client, path + name + "/", true, running));
    }
    return false;
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 20 with RecordId

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

the class TarRevisionsTest method setHeadFromFunction.

@Test
public void setHeadFromFunction() throws IOException, InterruptedException {
    RecordId headId = revisions.getHead();
    SegmentNodeState root = reader.readNode(headId);
    final SegmentNodeState newRoot = addChild(root, "a");
    assertNotNull(revisions.setHead(new Function<RecordId, RecordId>() {

        @Nullable
        @Override
        public RecordId apply(RecordId headId) {
            return newRoot.getRecordId();
        }
    }));
    store.flush();
    try (JournalReader reader = createJournalReader()) {
        assertTrue(reader.hasNext());
        assertEquals(newRoot.getRecordId().toString10(), reader.next().getRevision());
    }
}
Also used : Function(com.google.common.base.Function) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) Test(org.junit.Test)

Aggregations

RecordId (org.apache.jackrabbit.oak.segment.RecordId)28 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)14 Test (org.junit.Test)9 FileStoreUtil.findPersistedRecordId (org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId)7 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 SegmentNodeBuilder (org.apache.jackrabbit.oak.segment.SegmentNodeBuilder)3 SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 RecordId.fromString (org.apache.jackrabbit.oak.segment.RecordId.fromString)2 SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)2 SegmentNodeStore (org.apache.jackrabbit.oak.segment.SegmentNodeStore)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Function (com.google.common.base.Function)1 Stopwatch (com.google.common.base.Stopwatch)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 PrintWriter (java.io.PrintWriter)1 Random (java.util.Random)1