use of io.datarouter.filesystem.snapshot.storage.file.SnapshotFileStorage in project datarouter by hotpads.
the class SnapshotGroupWriteOps method writeWithId.
// could be public if something like back-dating snapshotIds is necessary
private SnapshotWriteResult writeWithId(SnapshotWriterConfig config, Scanner<List<SnapshotEntry>> entries, String snapshotId, ExecutorService exec, Supplier<Boolean> shouldStop) {
var snapshotKey = new SnapshotKey(groupId, snapshotId);
SnapshotFileStorage snapshotFileStorage = group.makeSnapshotFileStorage(snapshotKey.snapshotId);
SnapshotBlockStorage snapshotBlockStorage = cacheStorage == null ? null : group.makeCacheStorage(snapshotKey.snapshotId);
try (var writer = new SnapshotWriter(snapshotKey, snapshotFileStorage, snapshotBlockStorage, config, exec)) {
entries.advanceUntil($ -> shouldStop.get()).forEach(writer::addBatch);
if (shouldStop.get()) {
return SnapshotWriteResult.failure(snapshotKey);
}
return writer.complete().map(rootBlock -> {
writeIdFile(snapshotKey.snapshotId);
decodingBlockLoaderBySnapshotKey.put(snapshotKey, decodingBlockLoaderFactory.create(rootBlock, group.makeStorageReader(snapshotKey.snapshotId)));
return SnapshotWriteResult.success(snapshotKey, rootBlock);
}).orElseGet(() -> {
logger.warn("snapshot {} had no entries and was not written", snapshotKey);
return SnapshotWriteResult.empty(snapshotKey);
});
}
}
use of io.datarouter.filesystem.snapshot.storage.file.SnapshotFileStorage in project datarouter by hotpads.
the class SnapshotGroupDeleteOps method deleteSnapshot.
public void deleteSnapshot(SnapshotKey snapshotKey, ExecutorService exec, int numThreads) {
deleteIdFile(snapshotKey.snapshotId);
RootBlock rootBlock = group.root(BlockKey.root(snapshotKey));
// TODO delete from cache
SnapshotFileStorage snapshotFileStorage = group.makeSnapshotFileStorage(snapshotKey.snapshotId);
new SnapshotFileDeleter(rootBlock, pathsRegistry, snapshotKey, snapshotFileStorage, exec, numThreads).delete();
}
Aggregations