Search in sources :

Example 21 with SegmentNodeState

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

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

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

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

the class FileStoreIT method testRestartAndGC.

public void testRestartAndGC(boolean memoryMapping) throws Exception {
    FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(memoryMapping).build();
    store.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(memoryMapping).build();
    SegmentNodeState base = store.getHead();
    SegmentNodeBuilder builder = base.builder();
    byte[] data = new byte[10 * 1024 * 1024];
    new Random().nextBytes(data);
    Blob blob = builder.createBlob(new ByteArrayInputStream(data));
    builder.setProperty("foo", blob);
    store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
    store.flush();
    store.getRevisions().setHead(store.getRevisions().getHead(), base.getRecordId());
    store.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(memoryMapping).build();
    store.gc();
    store.flush();
    store.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(memoryMapping).build();
    store.close();
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 25 with SegmentNodeState

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

the class FileStore method initialNode.

@Nonnull
private Supplier<RecordId> initialNode() {
    return new Supplier<RecordId>() {

        @Override
        public RecordId get() {
            try {
                SegmentWriter writer = segmentWriterBuilder("init").build(FileStore.this);
                NodeBuilder builder = EMPTY_NODE.builder();
                builder.setChildNode("root", EMPTY_NODE);
                SegmentNodeState node = writer.writeNode(builder.getNodeState());
                writer.flush();
                return node.getRecordId();
            } catch (IOException e) {
                String msg = "Failed to write initial node";
                log.error(msg, e);
                throw new IllegalStateException(msg, e);
            }
        }
    };
}
Also used : Supplier(com.google.common.base.Supplier) IOException(java.io.IOException) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) Nonnull(javax.annotation.Nonnull)

Aggregations

SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)25 RecordId (org.apache.jackrabbit.oak.segment.RecordId)9 SegmentNodeBuilder (org.apache.jackrabbit.oak.segment.SegmentNodeBuilder)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 Test (org.junit.Test)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)5 IOException (java.io.IOException)3 SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)3 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)3 Stopwatch (com.google.common.base.Stopwatch)2 UUID (java.util.UUID)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 Compactor (org.apache.jackrabbit.oak.segment.Compactor)2 SegmentBufferWriter (org.apache.jackrabbit.oak.segment.SegmentBufferWriter)2 SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)2 WriterCacheManager (org.apache.jackrabbit.oak.segment.WriterCacheManager)2 SegmentGCOptions (org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions)2 Function (com.google.common.base.Function)1 Supplier (com.google.common.base.Supplier)1