Search in sources :

Example 1 with RootBlock

use of io.datarouter.filesystem.snapshot.block.root.RootBlock in project datarouter by hotpads.

the class SnapshotWriter method complete.

public Optional<RootBlock> complete() {
    LinkedBlockingDequeTool.put(messages, Message.last());
    CountDownLatchTool.await(writerThreadCompletionLatch);
    // finish value blocks
    IntStream.range(0, valueBlockEncoders.size()).forEach(column -> {
        ValueBlockEncoder valueBlockEncoder = valueBlockEncoders.get(column);
        if (valueBlockEncoder.numRecords() > 0) {
            blockWriter.submitValueBlock(column, numValueBlocksByColumn.get(column), valueBlockEncoder);
            numValueBlocksByColumn.set(column, numValueBlocksByColumn.get(column) + 1);
        }
    });
    // finish leaf blocks
    if (leafBlockEncoder.numRecords() > 0) {
        addBranchEntry(0, numKeys, lastEntry, numLeafBlocks);
        blockWriter.submitLeaf(leafBlockEncoder);
        ++numLeafBlocks;
    }
    // finish branch blocks
    IntStream.range(0, branchBlockEncoders.size()).forEach(level -> {
        BranchBlockEncoder branchEncoder = branchBlockEncoders.get(level);
        if (branchEncoder.numRecords() > 0) {
            if (level != branchBlockEncoders.size() - 1) {
                // avoid creating a root block with only one entry
                addBranchEntry(level + 1, numKeys, lastEntry, numBranchBlocksByLevel.get(level));
            }
            blockWriter.submitBranch(branchEncoder);
            branchBlockEncoders.set(level, config.branchBlockEncoderFactory.apply(level));
            numBranchBlocksByLevel.set(level, numBranchBlocksByLevel.get(level) + 1);
        }
    });
    // complete file uploads (could parallelize this?)
    blockWriter.complete();
    // write root block
    if (numKeys == 0) {
        return Optional.empty();
    }
    // TODO write to cache if config.updateCache
    RootBlock root = blockWriter.flushRootBlock(startTimeMs, numBranchBlocksByLevel, numValueBlocksByColumn, branchBlockEncoders.size(), numKeys, numLeafBlocks);
    // log completion
    logStatus();
    String logTokens = Scanner.of(root.toKeyValueStrings().entrySet()).map(kv -> kv.getKey() + "=" + kv.getValue()).collect(Collectors.joining(", "));
    logger.warn("Completed group={}, id={}, {}", snapshotKey.groupId, snapshotKey.snapshotId, logTokens);
    return Optional.of(root);
}
Also used : IntStream(java.util.stream.IntStream) CountDownLatchTool(io.datarouter.util.concurrent.CountDownLatchTool) Scanner(io.datarouter.scanner.Scanner) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) CsvIntByteStringCodec(io.datarouter.bytes.codec.bytestringcodec.CsvIntByteStringCodec) LoggerFactory(org.slf4j.LoggerFactory) SnapshotEntry(io.datarouter.filesystem.snapshot.entry.SnapshotEntry) LinkedBlockingDequeTool(io.datarouter.util.concurrent.LinkedBlockingDequeTool) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) EmptyArray(io.datarouter.bytes.EmptyArray) List(java.util.List) BranchBlockEncoder(io.datarouter.filesystem.snapshot.encode.BranchBlockEncoder) SnapshotFileStorage(io.datarouter.filesystem.snapshot.storage.file.SnapshotFileStorage) LeafBlockEncoder(io.datarouter.filesystem.snapshot.encode.LeafBlockEncoder) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock) Optional(java.util.Optional) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) SnapshotBlockStorage(io.datarouter.filesystem.snapshot.storage.block.SnapshotBlockStorage) ValueBlockEncoder(io.datarouter.filesystem.snapshot.encode.ValueBlockEncoder) ExecutorService(java.util.concurrent.ExecutorService) RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock) ValueBlockEncoder(io.datarouter.filesystem.snapshot.encode.ValueBlockEncoder) BranchBlockEncoder(io.datarouter.filesystem.snapshot.encode.BranchBlockEncoder)

Example 2 with RootBlock

use of io.datarouter.filesystem.snapshot.block.root.RootBlock in project datarouter by hotpads.

the class DatarouterSnapshotHandler method summary.

@Handler
public Mav summary(@Param(P_groupId) String groupId, @Param(P_snapshotId) String snapshotId) {
    var snapshotKey = new SnapshotKey(groupId, snapshotId);
    RootBlock rootBlock = groups.getGroup(groupId).root(BlockKey.root(snapshotKey));
    return pageFactory.startBuilder(request).withTitle("Datarouter Filesystem - Snapshot Groups").withRequires(DatarouterWebRequireJsV2.SORTTABLE).withContent(buildSummary(rootBlock)).buildMav();
}
Also used : RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 3 with RootBlock

use of io.datarouter.filesystem.snapshot.block.root.RootBlock 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)

Example 4 with RootBlock

use of io.datarouter.filesystem.snapshot.block.root.RootBlock in project datarouter by hotpads.

the class SnapshotGroup method makeDecodingBlockLoader.

private DecodingBlockLoader makeDecodingBlockLoader(SnapshotKey snapshotKey) {
    SnapshotBlockStorageReader blockStorageReader = makeStorageReader(snapshotKey.snapshotId);
    byte[] rootBytes = blockStorageReader.getRootBlock();
    RootBlock rootBlock = rootBlockDecoder.decode(rootBytes);
    return decodingBlockLoaderFactory.create(rootBlock, blockStorageReader);
}
Also used : RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock) SnapshotBlockStorageReader(io.datarouter.filesystem.snapshot.storage.block.SnapshotBlockStorageReader)

Example 5 with RootBlock

use of io.datarouter.filesystem.snapshot.block.root.RootBlock 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)

Aggregations

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