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);
}
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);
}
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));
});
}
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);
}
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));
}
Aggregations