Search in sources :

Example 1 with ValueLocation

use of io.datarouter.filesystem.snapshot.block.leaf.LeafBlock.ValueLocation 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 2 with ValueLocation

use of io.datarouter.filesystem.snapshot.block.leaf.LeafBlock.ValueLocation 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

Bytes (io.datarouter.bytes.Bytes)2 BlockKey (io.datarouter.filesystem.snapshot.block.BlockKey)2 LeafBlock (io.datarouter.filesystem.snapshot.block.leaf.LeafBlock)2 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