Search in sources :

Example 1 with IDiskAtomFilter

use of org.apache.cassandra.db.filter.IDiskAtomFilter in project janusgraph by JanusGraph.

the class CassandraEmbeddedKeyColumnValueStore method getKeySlice.

/**
 * Create a RangeSliceCommand and run it against the StorageProxy.
 * <p>
 * To match the behavior of the standard Cassandra thrift API endpoint, the
 * {@code nowMillis} argument should be the number of milliseconds since the
 * UNIX Epoch (e.g. System.currentTimeMillis() or equivalent obtained
 * through a {@link TimestampProvider}). This is per
 * {@link org.apache.cassandra.thrift.CassandraServer#get_range_slices(ColumnParent, SlicePredicate, KeyRange, ConsistencyLevel)},
 * which passes the server's System.currentTimeMillis() to the
 * {@code RangeSliceCommand} constructor.
 */
private List<Row> getKeySlice(Token start, Token end, @Nullable SliceQuery sliceQuery, int pageSize, long nowMillis) throws BackendException {
    IPartitioner partitioner = StorageService.getPartitioner();
    SliceRange columnSlice = new SliceRange();
    if (sliceQuery == null) {
        columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5);
    } else {
        columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer()).setFinish(sliceQuery.getSliceEnd().asByteBuffer()).setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE);
    }
    /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
    SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
    RowPosition startPosition = start.minKeyBound(partitioner);
    RowPosition endPosition = end.minKeyBound(partitioner);
    List<Row> rows;
    try {
        CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily);
        IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null);
        final RangeSliceCommand cmd = new RangeSliceCommand(keyspace, columnFamily, nowMillis, filter, new Bounds<>(startPosition, endPosition), pageSize);
        rows = StorageProxy.getRangeSlice(cmd, ConsistencyLevel.QUORUM);
    } catch (Exception e) {
        throw new PermanentBackendException(e);
    }
    return rows;
}
Also used : IDiskAtomFilter(org.apache.cassandra.db.filter.IDiskAtomFilter) SliceRange(org.apache.cassandra.thrift.SliceRange) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) CFMetaData(org.apache.cassandra.config.CFMetaData) IsBootstrappingException(org.apache.cassandra.exceptions.IsBootstrappingException) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) RequestTimeoutException(org.apache.cassandra.exceptions.RequestTimeoutException) UnavailableException(org.apache.cassandra.exceptions.UnavailableException)

Example 2 with IDiskAtomFilter

use of org.apache.cassandra.db.filter.IDiskAtomFilter in project titan by thinkaurelius.

the class CassandraEmbeddedKeyColumnValueStore method getKeySlice.

/**
     * Create a RangeSliceCommand and run it against the StorageProxy.
     * <p>
     * To match the behavior of the standard Cassandra thrift API endpoint, the
     * {@code nowMillis} argument should be the number of milliseconds since the
     * UNIX Epoch (e.g. System.currentTimeMillis() or equivalent obtained
     * through a {@link TimestampProvider}). This is per
     * {@link org.apache.cassandra.thrift.CassandraServer#get_range_slices(ColumnParent, SlicePredicate, KeyRange, ConsistencyLevel)},
     * which passes the server's System.currentTimeMillis() to the
     * {@code RangeSliceCommand} constructor.
     */
private List<Row> getKeySlice(Token start, Token end, @Nullable SliceQuery sliceQuery, int pageSize, long nowMillis) throws BackendException {
    IPartitioner partitioner = StorageService.getPartitioner();
    SliceRange columnSlice = new SliceRange();
    if (sliceQuery == null) {
        columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5);
    } else {
        columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer()).setFinish(sliceQuery.getSliceEnd().asByteBuffer()).setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE);
    }
    /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
    SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
    RowPosition startPosition = start.minKeyBound(partitioner);
    RowPosition endPosition = end.minKeyBound(partitioner);
    List<Row> rows;
    try {
        CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily);
        IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null);
        RangeSliceCommand cmd = new RangeSliceCommand(keyspace, columnFamily, nowMillis, filter, new Bounds<RowPosition>(startPosition, endPosition), pageSize);
        rows = StorageProxy.getRangeSlice(cmd, ConsistencyLevel.QUORUM);
    } catch (Exception e) {
        throw new PermanentBackendException(e);
    }
    return rows;
}
Also used : IDiskAtomFilter(org.apache.cassandra.db.filter.IDiskAtomFilter) SliceRange(org.apache.cassandra.thrift.SliceRange) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) CFMetaData(org.apache.cassandra.config.CFMetaData) IsBootstrappingException(org.apache.cassandra.exceptions.IsBootstrappingException) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) RequestTimeoutException(org.apache.cassandra.exceptions.RequestTimeoutException) UnavailableException(org.apache.cassandra.exceptions.UnavailableException)

Example 3 with IDiskAtomFilter

use of org.apache.cassandra.db.filter.IDiskAtomFilter in project titan by thinkaurelius.

the class CassandraEmbeddedKeyColumnValueStore method getKeySlice.

private List<Row> getKeySlice(Token start, Token end, @Nullable SliceQuery sliceQuery, int pageSize) throws StorageException {
    IPartitioner<?> partitioner = StorageService.getPartitioner();
    SliceRange columnSlice = new SliceRange();
    if (sliceQuery == null) {
        columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5);
    } else {
        columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer()).setFinish(sliceQuery.getSliceEnd().asByteBuffer()).setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE);
    }
    /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
    SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
    RowPosition startPosition = start.minKeyBound(partitioner);
    RowPosition endPosition = end.minKeyBound(partitioner);
    List<Row> rows;
    try {
        IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, Schema.instance.getComparator(keyspace, columnFamily));
        rows = StorageProxy.getRangeSlice(new RangeSliceCommand(keyspace, new ColumnParent(columnFamily), filter, new Bounds<RowPosition>(startPosition, endPosition), null, pageSize), ConsistencyLevel.QUORUM);
    } catch (Exception e) {
        throw new PermanentStorageException(e);
    }
    return rows;
}
Also used : IDiskAtomFilter(org.apache.cassandra.db.filter.IDiskAtomFilter) SliceRange(org.apache.cassandra.thrift.SliceRange) ColumnParent(org.apache.cassandra.thrift.ColumnParent) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) IsBootstrappingException(org.apache.cassandra.exceptions.IsBootstrappingException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) RequestTimeoutException(org.apache.cassandra.exceptions.RequestTimeoutException) UnavailableException(org.apache.cassandra.exceptions.UnavailableException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) IOException(java.io.IOException)

Aggregations

IDiskAtomFilter (org.apache.cassandra.db.filter.IDiskAtomFilter)3 IsBootstrappingException (org.apache.cassandra.exceptions.IsBootstrappingException)3 RequestTimeoutException (org.apache.cassandra.exceptions.RequestTimeoutException)3 UnavailableException (org.apache.cassandra.exceptions.UnavailableException)3 SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)3 SliceRange (org.apache.cassandra.thrift.SliceRange)3 CFMetaData (org.apache.cassandra.config.CFMetaData)2 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)1 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)1 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)1 IOException (java.io.IOException)1 ColumnParent (org.apache.cassandra.thrift.ColumnParent)1