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