Examples of SegmentNodeBuilder


Examples of org.apache.jackrabbit.oak.plugins.segment.SegmentNodeBuilder

    public void testRecovery() throws IOException {
        FileStore store = new FileStore(directory, 1, false);
        store.flush(); // first 1kB

        SegmentNodeState base = store.getHead();
        SegmentNodeBuilder builder = base.builder();
        builder.setProperty("step", "a");
        store.setHead(base, builder.getNodeState());
        store.flush(); // second 1kB

        base = store.getHead();
        builder = base.builder();
        builder.setProperty("step", "b");
        store.setHead(base, builder.getNodeState());
        store.close(); // third 1kB

        store = new FileStore(directory, 1, false);
        assertEquals("b", store.getHead().getString("step"));
        store.close();
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.segment.SegmentNodeBuilder

    private static void restore(NodeState source, NodeStore store,
            SegmentWriter writer) throws CommitFailedException {
        long s = System.currentTimeMillis();
        NodeState current = store.getRoot();
        RestoreCompactor compactor = new RestoreCompactor(writer);
        SegmentNodeBuilder builder = compactor.process(current, source);
        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
        log.debug("Restore finished in {} ms.", System.currentTimeMillis() - s);
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.segment.SegmentNodeBuilder

        long t = System.currentTimeMillis();

        try {
            store.setLoader(this);
            SegmentNodeState before = store.getHead();
            SegmentNodeBuilder builder = before.builder();

            SegmentNodeState current = new SegmentNodeState(head);
            do {
                try {
                    current.compareAgainstBaseState(before, new ApplyDiff(builder));
                    break;
                }
                catch (SegmentNotFoundException e) {
                    // the segment is locally damaged or not present anymore
                    // lets try to read this from the primary again
                    String id = e.getSegmentId();
                    Segment s = readSegment(e.getSegmentId());
                    if (s == null) {
                        log.warn("can't read locally corrupt segment " + id + " from primary");
                        throw e;
                    }

                    log.debug("did reread locally corrupt segment " + id + " with size " + s.size());
                    ByteArrayOutputStream bout = new ByteArrayOutputStream(s.size());
                    try {
                        s.writeTo(bout);
                    }
                    catch (IOException f) {
                        log.error("can't wrap segment to output stream", f);
                        throw e;
                    }
                    store.writeSegment(s.getSegmentId(), bout.toByteArray(), 0, s.size());
                }
            } while(true);
            boolean ok = store.setHead(before, builder.getNodeState());
            log.debug("updated head state successfully: {} in {}ms.", ok,
                    System.currentTimeMillis() - t);
        } finally {
            close();
        }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.segment.SegmentNodeBuilder

        // 2. init filestore
        FileStore backup = new FileStore(destination, MAX_FILE_SIZE, false);
        try {
            SegmentNodeState state = backup.getHead();
            SegmentNodeBuilder builder = state.builder();

            String beforeCheckpoint = state.getString("checkpoint");
            if (beforeCheckpoint == null) {
                // 3.1 no stored checkpoint, so do the initial full backup
                builder.setChildNode("root", current);
            } else {
                // 3.2 try to retrieve the previously backed up checkpoint
                NodeState before = store.retrieve(beforeCheckpoint);
                if (before == null) {
                    // the previous checkpoint is no longer available,
                    // so use the backed up state as the basis of the
                    // incremental backup diff
                    before = state.getChildNode("root");
                }
                current.compareAgainstBaseState(
                        before, new ApplyDiff(builder.child("root")));
            }
            builder.setProperty("checkpoint", checkpoint);

            // 4. commit the backup
            backup.setHead(state, builder.getNodeState());
        } finally {
            backup.close();
        }

        log.debug("Backup finished in {} ms.", System.currentTimeMillis() - s);
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.segment.SegmentNodeBuilder

        try {
            Journal journal = backup.getJournal("root");

            SegmentNodeState state = new SegmentNodeState(
                    backup.getWriter().getDummySegment(), journal.getHead());
            SegmentNodeBuilder builder = state.builder();

            String beforeCheckpoint = state.getString("checkpoint");
            if (beforeCheckpoint == null) {
                // 3.1 no stored checkpoint, so do the initial full backup
                builder.setChildNode("root", current);
            } else {
                // 3.2 try to retrieve the previously backed up checkpoint
                NodeState before = store.retrieve(beforeCheckpoint);
                if (before == null) {
                    // the previous checkpoint is no longer available,
                    // so use the backed up state as the basis of the
                    // incremental backup diff
                    before = state.getChildNode("root");
                }
                current.compareAgainstBaseState(
                        before, new ApplyDiff(builder.child("root")));
            }
            builder.setProperty("checkpoint", checkpoint);

            // 4. commit the backup
            journal.setHead(
                    state.getRecordId(), builder.getNodeState().getRecordId());
        } finally {
            backup.close();
        }

        log.debug("Backup finished in {} ms.", System.currentTimeMillis() - s);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.