Search in sources :

Example 1 with BasicReadOnlyBlobStore

use of org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore 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).withStrictVersionCheck(true).withDefaultMemoryMapping();
    if (USE_FAKE_BLOBSTORE) {
        builder.withBlobStore(new BasicReadOnlyBlobStore());
    }
    builder.withGCOptions(gcOptions);
    FileStore backup = builder.build();
    SegmentNodeState current = reader.readHeadState(revisions);
    try {
        GCGeneration gen = current.getRecordId().getSegmentId().getGcGeneration();
        SegmentBufferWriter bufferWriter = new SegmentBufferWriter(backup.getSegmentIdProvider(), backup.getReader(), "b", gen);
        SegmentWriter writer = new DefaultSegmentWriter(backup, backup.getReader(), backup.getSegmentIdProvider(), backup.getBlobStore(), new WriterCacheManager.Default(), bufferWriter);
        Compactor compactor = new Compactor(backup.getReader(), writer, backup.getBlobStore(), Suppliers.ofInstance(false), GCNodeWriteMonitor.EMPTY);
        SegmentNodeState head = backup.getHead();
        SegmentNodeState after = compactor.compact(head, current, head);
        writer.flush();
        if (after != null) {
            backup.getRevisions().setHead(head.getRecordId(), after.getRecordId());
        }
    } finally {
        backup.close();
    }
    backup = fileStoreBuilder(destination).withDefaultMemoryMapping().withGCOptions(gcOptions).withStrictVersionCheck(true).build();
    try {
        cleanup(backup);
    } finally {
        backup.close();
    }
    watch.stop();
    log.info("Backup finished in {}.", watch);
}
Also used : SegmentGCOptions(org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions) SegmentBufferWriter(org.apache.jackrabbit.oak.segment.SegmentBufferWriter) Stopwatch(com.google.common.base.Stopwatch) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) DefaultSegmentWriter(org.apache.jackrabbit.oak.segment.DefaultSegmentWriter) BasicReadOnlyBlobStore(org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Compactor(org.apache.jackrabbit.oak.segment.Compactor) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) WriterCacheManager(org.apache.jackrabbit.oak.segment.WriterCacheManager) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) DefaultSegmentWriter(org.apache.jackrabbit.oak.segment.DefaultSegmentWriter) GCGeneration(org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 Compactor (org.apache.jackrabbit.oak.segment.Compactor)1 DefaultSegmentWriter (org.apache.jackrabbit.oak.segment.DefaultSegmentWriter)1 SegmentBufferWriter (org.apache.jackrabbit.oak.segment.SegmentBufferWriter)1 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)1 SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)1 WriterCacheManager (org.apache.jackrabbit.oak.segment.WriterCacheManager)1 SegmentGCOptions (org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions)1 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)1 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)1 GCGeneration (org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)1 BasicReadOnlyBlobStore (org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore)1