Search in sources :

Example 1 with KeySlice

use of org.apache.cassandra.thrift.KeySlice in project atlasdb by palantir.

the class GetCellTimestamps method getRows.

private List<byte[]> getRows(byte[] rangeStart) {
    KeyRange keyRange = new KeyRange().setStart_key(rangeStart).setEnd_key(new byte[0]).setCount(batchHint);
    SlicePredicate slicePredicate = SlicePredicates.create(SlicePredicates.Range.ALL, SlicePredicates.Limit.ZERO);
    List<KeySlice> rows = rowGetter.getRows("getCandidateCellsForSweeping", keyRange, slicePredicate);
    return rows.stream().map(KeySlice::getKey).collect(Collectors.toList());
}
Also used : KeyRange(org.apache.cassandra.thrift.KeyRange) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) KeySlice(org.apache.cassandra.thrift.KeySlice)

Example 2 with KeySlice

use of org.apache.cassandra.thrift.KeySlice in project atlasdb by palantir.

the class ThriftObjectSizeUtilsTest method getKeySlicesSize.

@Test
public void getKeySlicesSize() {
    List<KeySlice> slices = ImmutableList.of(new KeySlice().setKey(TEST_NAME_BYTES).setColumns(ImmutableList.of(EMPTY_COLUMN_OR_SUPERCOLUMN)));
    long expectedSize = TEST_NAME_BYTES_SIZE + EMPTY_COLUMN_OR_SUPERCOLUMN_SIZE;
    assertThat(ThriftObjectSizeUtils.getApproximateSizeOfKeySlices(slices)).isEqualTo(expectedSize);
}
Also used : KeySlice(org.apache.cassandra.thrift.KeySlice) Test(org.junit.Test)

Example 3 with KeySlice

use of org.apache.cassandra.thrift.KeySlice in project titan by thinkaurelius.

the class CassandraThriftKeyColumnValueStore method getRangeSlices.

private List<KeySlice> getRangeSlices(KeyRange keyRange, @Nullable SliceQuery sliceQuery) throws StorageException {
    SliceRange sliceRange = new SliceRange();
    if (sliceQuery == null) {
        sliceRange.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5);
    } else {
        sliceRange.setStart(sliceQuery.getSliceStart().asByteBuffer()).setFinish(sliceQuery.getSliceEnd().asByteBuffer()).setCount((sliceQuery.hasLimit()) ? sliceQuery.getLimit() : Integer.MAX_VALUE);
    }
    CTConnection connection = null;
    try {
        connection = pool.borrowObject(keyspace);
        List<KeySlice> slices = connection.getClient().get_range_slices(new ColumnParent(columnFamily), new SlicePredicate().setSlice_range(sliceRange), keyRange, ConsistencyLevel.QUORUM);
        for (KeySlice s : slices) {
            logger.debug("Key {}", ByteBufferUtil.toString(s.key, "-"));
        }
        /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
        List<KeySlice> result = new ArrayList<KeySlice>(slices.size());
        KeyIterationPredicate pred = new KeyIterationPredicate();
        for (KeySlice ks : slices) if (pred.apply(ks))
            result.add(ks);
        return result;
    } catch (Exception e) {
        throw convertException(e);
    } finally {
        if (connection != null)
            pool.returnObjectUnsafe(keyspace, connection);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) SliceRange(org.apache.cassandra.thrift.SliceRange) ColumnParent(org.apache.cassandra.thrift.ColumnParent) ArrayList(java.util.ArrayList) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TimedOutException(org.apache.cassandra.thrift.TimedOutException) NoSuchElementException(java.util.NoSuchElementException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) KeySlice(org.apache.cassandra.thrift.KeySlice)

Aggregations

KeySlice (org.apache.cassandra.thrift.KeySlice)3 SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)1 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)1 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)1 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 ColumnParent (org.apache.cassandra.thrift.ColumnParent)1 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)1 KeyRange (org.apache.cassandra.thrift.KeyRange)1 SliceRange (org.apache.cassandra.thrift.SliceRange)1 TimedOutException (org.apache.cassandra.thrift.TimedOutException)1 UnavailableException (org.apache.cassandra.thrift.UnavailableException)1 TException (org.apache.thrift.TException)1 Test (org.junit.Test)1