Search in sources :

Example 1 with SnapshotWriterConfig

use of io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig 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 SnapshotWriterConfig

use of io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig in project datarouter by hotpads.

the class FilesystemSnapshotSortingTests method writeOutputSnapshot.

private RootBlock writeOutputSnapshot(Scanner<SnapshotRecord> records) {
    var timer = new PhaseTimer("writeOutputSnapshot");
    SnapshotWriterConfig config = makeSnapshotWriterConfig(true);
    SnapshotWriteResult result = records.map(SnapshotRecord::entry).batch(1000).apply(entries -> outputGroup.writeOps().write(config, entries, exec, () -> false));
    outputSnapshotKey = result.key;
    timer.add("wrote " + NumberFormatter.addCommas(result.optRoot.get().numItems()));
    logger.warn("{}", timer);
    return result.optRoot.get();
}
Also used : PhaseTimer(io.datarouter.util.timer.PhaseTimer) SnapshotWriterConfig(io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig) SnapshotWriteResult(io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult) SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord)

Example 3 with SnapshotWriterConfig

use of io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig in project datarouter by hotpads.

the class FilesystemSnapshotSortingTests method writeInputSnapshot.

private RootBlock writeInputSnapshot() {
    var timer = new PhaseTimer("writeInputSnapshot");
    SnapshotWriterConfig config = makeSnapshotWriterConfig(false);
    SnapshotWriteResult result = Scanner.iterate(0, i -> i + 1).limit(NUM_ENTRIES).shuffle().map(FilesystemSnapshotSortingTests::makeEntry).batch(1000).apply(entries -> inputGroup.writeOps().write(config, entries, exec, () -> false));
    inputSnapshotKey = result.key;
    timer.add("wrote " + NumberFormatter.addCommas(result.optRoot.get().numItems()));
    logger.warn("{}", timer);
    return result.optRoot.get();
}
Also used : SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord) ScalingThreadPoolExecutor(io.datarouter.util.concurrent.ScalingThreadPoolExecutor) Scanner(io.datarouter.scanner.Scanner) RawIntCodec(io.datarouter.bytes.codec.intcodec.RawIntCodec) ByteTool(io.datarouter.bytes.ByteTool) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey) ParallelScannerContext(io.datarouter.scanner.ParallelScannerContext) LoggerFactory(org.slf4j.LoggerFactory) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SnapshotWriterConfig(io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig) NumberFormatter(io.datarouter.util.number.NumberFormatter) EmptyArray(io.datarouter.bytes.EmptyArray) SnapshotWriteResult(io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult) Assert(org.testng.Assert) ScanningSnapshotReader(io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatarouterFilesystemModuleFactory(io.datarouter.filesystem.DatarouterFilesystemModuleFactory) RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock) SnapshotWriterConfigBuilder(io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfigBuilder) ExecutorService(java.util.concurrent.ExecutorService) PhaseTimer(io.datarouter.util.timer.PhaseTimer) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) PassthroughBlockCompressor(io.datarouter.filesystem.snapshot.compress.PassthroughBlockCompressor) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) SnapshotEntry(io.datarouter.filesystem.snapshot.entry.SnapshotEntry) Count(io.datarouter.util.Count) Guice(org.testng.annotations.Guice) List(java.util.List) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) Collections(java.util.Collections) PhaseTimer(io.datarouter.util.timer.PhaseTimer) SnapshotWriterConfig(io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig) SnapshotWriteResult(io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult)

Example 4 with SnapshotWriterConfig

use of io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig in project datarouter by hotpads.

the class FilesystemSnapshotSortingTests method writeChunkSnapshot.

private SnapshotKey writeChunkSnapshot(int chunkId, List<SnapshotRecord> records) {
    var timer = new PhaseTimer("writeChunkSnapshot " + chunkId);
    SnapshotWriterConfig config = makeSnapshotWriterConfig(true);
    SnapshotWriteResult result = Scanner.of(records).map(SnapshotRecord::entry).batch(1000).apply(entries -> chunkGroup.writeOps().write(config, entries, exec, () -> false));
    timer.add("wrote " + NumberFormatter.addCommas(result.optRoot.get().numItems()));
    logger.warn("{}", timer);
    return result.key;
}
Also used : PhaseTimer(io.datarouter.util.timer.PhaseTimer) SnapshotWriterConfig(io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig) SnapshotWriteResult(io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult) SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord)

Aggregations

SnapshotWriteResult (io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult)4 SnapshotWriterConfig (io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig)4 SnapshotRecord (io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord)3 PhaseTimer (io.datarouter.util.timer.PhaseTimer)3 EmptyArray (io.datarouter.bytes.EmptyArray)2 SnapshotEntry (io.datarouter.filesystem.snapshot.entry.SnapshotEntry)2 SnapshotGroup (io.datarouter.filesystem.snapshot.group.SnapshotGroup)2 SnapshotKey (io.datarouter.filesystem.snapshot.key.SnapshotKey)2 Scanner (io.datarouter.scanner.Scanner)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ByteTool (io.datarouter.bytes.ByteTool)1 RawIntCodec (io.datarouter.bytes.codec.intcodec.RawIntCodec)1 DatarouterFilesystemModuleFactory (io.datarouter.filesystem.DatarouterFilesystemModuleFactory)1 BlockKey (io.datarouter.filesystem.snapshot.block.BlockKey)1 RootBlock (io.datarouter.filesystem.snapshot.block.root.RootBlock)1 PassthroughBlockCompressor (io.datarouter.filesystem.snapshot.compress.PassthroughBlockCompressor)1 ScanningSnapshotReader (io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader)1