Search in sources :

Example 11 with SegmentNodeState

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

the class SegmentTarCheckpoints method removeUnreferenced.

@Override
public long removeUnreferenced() {
    SegmentNodeState head = store.getHead();
    Set<String> refs = getReferencedCheckpoints(head.getChildNode("root"));
    NodeBuilder builder = head.builder();
    NodeBuilder cps = builder.getChildNode("checkpoints");
    long cnt = 0;
    for (String c : cps.getChildNodeNames()) {
        if (refs.contains(c)) {
            continue;
        }
        cps.getChildNode(c).remove();
        cnt++;
    }
    if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
        return cnt;
    } else {
        return -1;
    }
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 12 with SegmentNodeState

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

the class SegmentTarCheckpoints method setInfoProperty.

@Override
public int setInfoProperty(String cp, String name, String value) {
    SegmentNodeState head = store.getHead();
    NodeBuilder builder = head.builder();
    NodeBuilder props = builder.getChildNode("checkpoints").getChildNode(cp).getChildNode("properties");
    if (props.exists()) {
        if (value == null) {
            props.removeProperty(name);
        } else {
            props.setProperty(name, value, Type.STRING);
        }
        if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
            return 1;
        } else {
            return -1;
        }
    } else {
        return 0;
    }
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 13 with SegmentNodeState

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

the class SegmentTarCheckpoints method remove.

@Override
public int remove(String cp) {
    SegmentNodeState head = store.getHead();
    NodeBuilder builder = head.builder();
    NodeBuilder cpn = builder.getChildNode("checkpoints").getChildNode(cp);
    if (cpn.exists()) {
        cpn.remove();
        if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
            return 1;
        } else {
            return -1;
        }
    } else {
        return 0;
    }
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 14 with SegmentNodeState

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

the class FileStoreBackupImpl method backup.

@Override
public void backup(@Nonnull SegmentReader reader, @Nonnull Revisions revisions, @Nonnull File destination) throws IOException, InvalidFileStoreVersionException {
    Stopwatch watch = Stopwatch.createStarted();
    SegmentGCOptions gcOptions = SegmentGCOptions.defaultGCOptions().setOffline();
    FileStoreBuilder builder = fileStoreBuilder(destination).withDefaultMemoryMapping();
    if (USE_FAKE_BLOBSTORE) {
        builder.withBlobStore(new BasicReadOnlyBlobStore());
    }
    builder.withGCOptions(gcOptions);
    FileStore backup = builder.build();
    SegmentNodeState current = reader.readHeadState(revisions);
    try {
        int gen = current.getRecordId().getSegmentId().getGcGeneration();
        SegmentBufferWriter bufferWriter = new SegmentBufferWriter(backup.getSegmentIdProvider(), backup.getReader(), "b", gen);
        SegmentWriter writer = new SegmentWriter(backup, backup.getReader(), backup.getSegmentIdProvider(), backup.getBlobStore(), new WriterCacheManager.Default(), bufferWriter);
        Compactor compactor = new Compactor(backup.getReader(), writer, backup.getBlobStore(), Suppliers.ofInstance(false), gcOptions);
        compactor.setContentEqualityCheck(true);
        SegmentNodeState head = backup.getHead();
        SegmentNodeState after = compactor.compact(head, current, head);
        if (after != null) {
            backup.getRevisions().setHead(head.getRecordId(), after.getRecordId());
        }
    } finally {
        backup.close();
    }
    backup = fileStoreBuilder(destination).withDefaultMemoryMapping().withGCOptions(gcOptions).build();
    try {
        cleanup(backup);
    } finally {
        backup.close();
    }
    watch.stop();
    log.info("Backup finished in {}.", watch);
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Compactor(org.apache.jackrabbit.oak.segment.Compactor) SegmentGCOptions(org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) SegmentBufferWriter(org.apache.jackrabbit.oak.segment.SegmentBufferWriter) Stopwatch(com.google.common.base.Stopwatch) WriterCacheManager(org.apache.jackrabbit.oak.segment.WriterCacheManager) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) BasicReadOnlyBlobStore(org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore)

Example 15 with SegmentNodeState

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

the class LockBasedScheduler method execute.

private NodeState execute(Commit commit) throws CommitFailedException, InterruptedException {
    // only do the merge if there are some changes to commit
    if (commit.hasChanges()) {
        refreshHead(true);
        SegmentNodeState before = head.get();
        SegmentNodeState after = commit.apply(before);
        if (revisions.setHead(before.getRecordId(), after.getRecordId())) {
            head.set(after);
            contentChanged(after.getChildNode(ROOT), commit.info());
            refreshHead(true);
        }
    }
    return head.get().getChildNode(ROOT);
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

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