use of org.apache.jackrabbit.oak.segment.DefaultSegmentWriter 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);
}
use of org.apache.jackrabbit.oak.segment.DefaultSegmentWriter 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).withStrictVersionCheck(true).build();
SegmentNodeState current = store.getHead();
try {
SegmentNodeState head = restore.getHead();
GCGeneration gen = head.getRecordId().getSegmentId().getGcGeneration();
SegmentBufferWriter bufferWriter = new SegmentBufferWriter(store.getSegmentIdProvider(), store.getReader(), "r", gen);
SegmentWriter writer = new DefaultSegmentWriter(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), GCNodeWriteMonitor.EMPTY);
SegmentNodeState after = compactor.compact(current, head, current);
writer.flush();
store.getRevisions().setHead(current.getRecordId(), after.getRecordId());
} finally {
restore.close();
store.close();
}
watch.stop();
log.info("Restore finished in {}.", watch);
}
Aggregations