Search in sources :

Example 1 with BranchBlock

use of io.datarouter.filesystem.snapshot.block.branch.BranchBlock 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 BranchBlock

use of io.datarouter.filesystem.snapshot.block.branch.BranchBlock 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 3 with BranchBlock

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

the class SnapshotKeyReader method leafBlock.

public LeafBlock leafBlock(byte[] searchKey) {
    BlockKey rootBranchBlockKey = rootBlock.rootBranchBlockKey(snapshotKey);
    BranchBlock branchBlock = blockLoader.branch(rootBranchBlockKey);
    for (int level = rootBlock.maxBranchLevel() - 1; level >= 0; --level) {
        int childBlockIndex = branchBlock.findChildBlockIndex(searchKey);
        int childBlockId = branchBlock.childBlock(childBlockIndex);
        BlockKey branchBlockKey = branchBlock.childBranchBlockKey(snapshotKey, childBlockId);
        branchBlock = blockLoader.branch(branchBlockKey);
    }
    int leafBlockIndex = branchBlock.findChildBlockIndex(searchKey);
    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)

Aggregations

BlockKey (io.datarouter.filesystem.snapshot.block.BlockKey)3 BranchBlock (io.datarouter.filesystem.snapshot.block.branch.BranchBlock)3 LeafBlock (io.datarouter.filesystem.snapshot.block.leaf.LeafBlock)1 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