Search in sources :

Example 1 with SnapshotFileStorage

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);
        });
    }
}
Also used : SnapshotFileStorage(io.datarouter.filesystem.snapshot.storage.file.SnapshotFileStorage) Scanner(io.datarouter.scanner.Scanner) Logger(org.slf4j.Logger) UlidTool(io.datarouter.util.UlidTool) LoggerFactory(org.slf4j.LoggerFactory) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) SnapshotEntry(io.datarouter.filesystem.snapshot.entry.SnapshotEntry) Supplier(java.util.function.Supplier) Directory(io.datarouter.storage.file.Directory) SnapshotWriter(io.datarouter.filesystem.snapshot.writer.SnapshotWriter) DecodingBlockLoaderFactory(io.datarouter.filesystem.snapshot.reader.block.DecodingBlockLoaderFactory) SnapshotWriterConfig(io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig) EmptyArray(io.datarouter.bytes.EmptyArray) DecodingBlockLoader(io.datarouter.filesystem.snapshot.reader.block.DecodingBlockLoader) List(java.util.List) SnapshotWriteResult(io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult) SnapshotFileStorage(io.datarouter.filesystem.snapshot.storage.file.SnapshotFileStorage) Map(java.util.Map) PathbeanKey(io.datarouter.storage.file.PathbeanKey) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) SnapshotBlockStorage(io.datarouter.filesystem.snapshot.storage.block.SnapshotBlockStorage) ExecutorService(java.util.concurrent.ExecutorService) SnapshotBlockStorage(io.datarouter.filesystem.snapshot.storage.block.SnapshotBlockStorage) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) SnapshotWriter(io.datarouter.filesystem.snapshot.writer.SnapshotWriter)

Example 2 with SnapshotFileStorage

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();
}
Also used : SnapshotFileStorage(io.datarouter.filesystem.snapshot.storage.file.SnapshotFileStorage) SnapshotFileDeleter(io.datarouter.filesystem.snapshot.storage.file.SnapshotFileDeleter) RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock)

Aggregations

SnapshotFileStorage (io.datarouter.filesystem.snapshot.storage.file.SnapshotFileStorage)2 EmptyArray (io.datarouter.bytes.EmptyArray)1 RootBlock (io.datarouter.filesystem.snapshot.block.root.RootBlock)1 SnapshotEntry (io.datarouter.filesystem.snapshot.entry.SnapshotEntry)1 SnapshotGroup (io.datarouter.filesystem.snapshot.group.SnapshotGroup)1 SnapshotWriteResult (io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult)1 SnapshotKey (io.datarouter.filesystem.snapshot.key.SnapshotKey)1 DecodingBlockLoader (io.datarouter.filesystem.snapshot.reader.block.DecodingBlockLoader)1 DecodingBlockLoaderFactory (io.datarouter.filesystem.snapshot.reader.block.DecodingBlockLoaderFactory)1 SnapshotBlockStorage (io.datarouter.filesystem.snapshot.storage.block.SnapshotBlockStorage)1 SnapshotFileDeleter (io.datarouter.filesystem.snapshot.storage.file.SnapshotFileDeleter)1 SnapshotWriter (io.datarouter.filesystem.snapshot.writer.SnapshotWriter)1 SnapshotWriterConfig (io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig)1 Scanner (io.datarouter.scanner.Scanner)1 Directory (io.datarouter.storage.file.Directory)1 PathbeanKey (io.datarouter.storage.file.PathbeanKey)1 UlidTool (io.datarouter.util.UlidTool)1 List (java.util.List)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1