Search in sources :

Example 1 with BlockKey

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

the class SnapshotIdReader method leafBlock.

private LeafBlock leafBlock(long recordId) {
    BlockKey rootBranchBlockKey = rootBlock.rootBranchBlockKey(snapshotKey);
    BranchBlock branchBlock = blockLoader.branch(rootBranchBlockKey);
    for (int level = rootBlock.maxBranchLevel() - 1; level >= 0; --level) {
        int childBlockIndex = branchBlock.findChildBlockIndex(recordId);
        int childBlockId = branchBlock.childBlock(childBlockIndex);
        BlockKey branchBlockKey = branchBlock.childBranchBlockKey(snapshotKey, childBlockId);
        branchBlock = blockLoader.branch(branchBlockKey);
    }
    int leafBlockIndex = branchBlock.findChildBlockIndex(recordId);
    int leafBlockId = branchBlock.childBlock(leafBlockIndex);
    BlockKey leafBlockKey = branchBlock.leafBlockKey(snapshotKey, leafBlockId);
    return blockLoader.leaf(leafBlockKey);
}
Also used : BranchBlock(io.datarouter.filesystem.snapshot.block.branch.BranchBlock) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey)

Example 2 with BlockKey

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

the class DecodingBlockLoader method leafRange.

@Override
public Scanner<LeafBlock> leafRange(LeafBlockRange range) {
    BlockKey rangeBlockKey = range.rangeBlockKey();
    byte[] compressedRangeBytes = snapshotBlockStorageReader.getLeafBlock(paths, rangeBlockKey);
    return range.parse(compressedRangeBytes).map(// TODO let decompressors accept Bytes to avoid this mem copy?
    Bytes::toArray).map(blockDecompressor::leaf).map(blockDecoder::leaf);
}
Also used : Bytes(io.datarouter.bytes.Bytes) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey)

Example 3 with BlockKey

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

the class ScanningBlockReader method scanLeafBlockKeys.

private Scanner<BlockKey> scanLeafBlockKeys(long fromRecordIdInclusive) {
    BlockKey topBranchBlockKey = rootBlock.rootBranchBlockKey(snapshotKey);
    BranchBlock topBranchBlock = blockLoader.branch(topBranchBlockKey);
    return scanDescendantBranchBlocks(topBranchBlock, fromRecordIdInclusive).include(branchBlock -> branchBlock.level() == 0).concat(branchBlock -> {
        return Scanner.iterate(0, i -> i + 1).limit(branchBlock.numRecords()).include(index -> branchBlock.recordId(index) >= fromRecordIdInclusive).map(branchBlock::childBlock).map(leafBlockId -> branchBlock.leafBlockKey(snapshotKey, leafBlockId));
    });
}
Also used : Scanner(io.datarouter.scanner.Scanner) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey) BranchBlock(io.datarouter.filesystem.snapshot.block.branch.BranchBlock) ParallelScannerContext(io.datarouter.scanner.ParallelScannerContext) RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) Function(java.util.function.Function) LeafBlock(io.datarouter.filesystem.snapshot.block.leaf.LeafBlock) ExecutorService(java.util.concurrent.ExecutorService) BranchBlock(io.datarouter.filesystem.snapshot.block.branch.BranchBlock) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey)

Example 4 with BlockKey

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

the class SnapshotIdReader method getRecord.

public SnapshotRecord getRecord(long recordId) {
    LeafBlock leafBlock = leafBlock(recordId);
    Bytes key = leafBlock.snapshotKey(recordId);
    Bytes value = leafBlock.snapshotValue(recordId);
    int numColumns = rootBlock.numColumns();
    byte[][] columnValues = new byte[numColumns][];
    for (int column = 0; column < numColumns; ++column) {
        ValueLocation valueLocation = leafBlock.getValueBlock(column, recordId);
        BlockKey valueBlockKey = leafBlock.valueBlockKey(snapshotKey, column, valueLocation.valueBlockId);
        ValueBlock valueBlock = blockLoader.value(valueBlockKey);
        Bytes columnValue = valueBlock.value(valueLocation.valueIndex);
        columnValues[column] = columnValue.toArray();
    }
    return new SnapshotRecord(recordId, key.toArray(), value.toArray(), columnValues);
}
Also used : Bytes(io.datarouter.bytes.Bytes) LeafBlock(io.datarouter.filesystem.snapshot.block.leaf.LeafBlock) SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord) ValueBlock(io.datarouter.filesystem.snapshot.block.value.ValueBlock) ValueLocation(io.datarouter.filesystem.snapshot.block.leaf.LeafBlock.ValueLocation) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey)

Example 5 with BlockKey

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

the class SnapshotKeyReader method findRecord.

public Optional<SnapshotRecord> findRecord(byte[] searchKey) {
    LeafBlock leafBlock = leafBlock(searchKey);
    Optional<Long> optRecordId = leafBlock.findRecordId(searchKey);
    if (optRecordId.isEmpty()) {
        return Optional.empty();
    }
    long recordId = optRecordId.get();
    byte[] value = leafBlock.snapshotValue(recordId).toArray();
    int numColumns = rootBlock.numColumns();
    byte[][] columnValues = new byte[numColumns][];
    for (int column = 0; column < numColumns; ++column) {
        // TODO lookup value blocks using already-found keyId
        Optional<ValueLocation> optValueLocation = leafBlock.findValueBlock(column, searchKey);
        if (optValueLocation.isEmpty()) {
            return Optional.empty();
        }
        ValueLocation valueLocation = optValueLocation.get();
        BlockKey valueBlockKey = leafBlock.valueBlockKey(snapshotKey, column, valueLocation.valueBlockId);
        ValueBlock valueBlock = blockLoader.value(valueBlockKey);
        Bytes columnValue = valueBlock.value(valueLocation.valueIndex);
        columnValues[column] = columnValue.toArray();
    }
    return Optional.of(new SnapshotRecord(recordId, searchKey, value, columnValues));
}
Also used : LeafBlock(io.datarouter.filesystem.snapshot.block.leaf.LeafBlock) SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord) ValueLocation(io.datarouter.filesystem.snapshot.block.leaf.LeafBlock.ValueLocation) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey) Bytes(io.datarouter.bytes.Bytes) ValueBlock(io.datarouter.filesystem.snapshot.block.value.ValueBlock)

Aggregations

BlockKey (io.datarouter.filesystem.snapshot.block.BlockKey)6 Bytes (io.datarouter.bytes.Bytes)3 BranchBlock (io.datarouter.filesystem.snapshot.block.branch.BranchBlock)3 LeafBlock (io.datarouter.filesystem.snapshot.block.leaf.LeafBlock)3 ValueLocation (io.datarouter.filesystem.snapshot.block.leaf.LeafBlock.ValueLocation)2 ValueBlock (io.datarouter.filesystem.snapshot.block.value.ValueBlock)2 SnapshotRecord (io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord)2 RootBlock (io.datarouter.filesystem.snapshot.block.root.RootBlock)1 SnapshotKey (io.datarouter.filesystem.snapshot.key.SnapshotKey)1 ParallelScannerContext (io.datarouter.scanner.ParallelScannerContext)1 Scanner (io.datarouter.scanner.Scanner)1 ExecutorService (java.util.concurrent.ExecutorService)1 Function (java.util.function.Function)1