Search in sources :

Example 1 with Slice

use of org.rocksdb.Slice in project alluxio by Alluxio.

the class RocksBlockStore method getLocations.

@Override
public List<BlockLocation> getLocations(long id) {
    byte[] startKey = RocksUtils.toByteArray(id, 0);
    byte[] endKey = RocksUtils.toByteArray(id, Long.MAX_VALUE);
    // Ref: https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
    try (final Slice slice = new Slice(endKey);
        final ReadOptions readOptions = new ReadOptions().setIterateUpperBound(slice);
        final RocksIterator iter = db().newIterator(mBlockLocationsColumn.get(), readOptions)) {
        iter.seek(startKey);
        List<BlockLocation> locations = new ArrayList<>();
        for (; iter.isValid(); iter.next()) {
            try {
                locations.add(BlockLocation.parseFrom(iter.value()));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return locations;
    }
}
Also used : ReadOptions(org.rocksdb.ReadOptions) Slice(org.rocksdb.Slice) ArrayList(java.util.ArrayList) RocksIterator(org.rocksdb.RocksIterator) BlockLocation(alluxio.proto.meta.Block.BlockLocation) RocksDBException(org.rocksdb.RocksDBException) IOException(java.io.IOException)

Aggregations

BlockLocation (alluxio.proto.meta.Block.BlockLocation)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ReadOptions (org.rocksdb.ReadOptions)1 RocksDBException (org.rocksdb.RocksDBException)1 RocksIterator (org.rocksdb.RocksIterator)1 Slice (org.rocksdb.Slice)1