Search in sources :

Example 1 with Compactor

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

use of org.apache.jackrabbit.oak.segment.Compactor 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)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)2 Compactor (org.apache.jackrabbit.oak.segment.Compactor)2 SegmentBufferWriter (org.apache.jackrabbit.oak.segment.SegmentBufferWriter)2 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)2 SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)2 WriterCacheManager (org.apache.jackrabbit.oak.segment.WriterCacheManager)2 SegmentGCOptions (org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions)2 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)2 IOException (java.io.IOException)1 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)1 ReadOnlyFileStore (org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore)1 BasicReadOnlyBlobStore (org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore)1