Java Code Examples for com.netflix.astyanax.util.RangeBuilder#setStart()

The following examples show how to use com.netflix.astyanax.util.RangeBuilder#setStart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EdgeMetadataSerializationV1Impl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private RangeBuilder createRange( final SearchEdgeType search ) {
    final RangeBuilder builder = new RangeBuilder().setLimit( graphFig.getScanPageSize() );


    //we have a last, it's where we need to start seeking from
    if ( search.getLast().isPresent() ) {
        builder.setStart( search.getLast().get() );
    }

    //no last was set, but we have a prefix, set it
    else if ( search.prefix().isPresent() ) {
        builder.setStart( search.prefix().get() );
    }


    //we have a prefix, so make sure we only seek to prefix + max UTF value
    if ( search.prefix().isPresent() ) {
        builder.setEnd( search.prefix().get() + "\uffff" );
    }


    return builder;
}
 
Example 2
Source File: AstyanaxEventReaderDAO.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the ordered manifest for a channel.  The read can either be weak or strong.  A weak read will use CL1
 * and may use the cached oldest slab from a previous strong call to improve performance.  A strong read will use
 * CL local_quorum and will always read the entire manifest row.  This makes a weak read significantly faster than a
 * strong read but also means the call is not guaranteed to return the entire manifest.  Because of this at least
 * every 10 seconds a weak read for a channel is automatically promoted to a strong read.
 *
 * The vast majority of calls to this method are performed during a "peek" or "poll" operation.  Since these are
 * typically called repeatedly a weak call provides improved performance while guaranteeing that at least every
 * 10 seconds the manifest is strongly read so no slabs are missed over time.  Calls which must guarantee
 * the full manifest should explicitly request strong consistency.
 */
private Iterator<Column<ByteBuffer>> readManifestForChannel(final String channel, final boolean weak) {
    final ByteBuffer oldestSlab = weak ? _oldestSlab.getIfPresent(channel) : null;
    final ConsistencyLevel consistency;

    RangeBuilder range = new RangeBuilder().setLimit(50);
    if (oldestSlab != null) {
        range.setStart(oldestSlab);
        consistency = ConsistencyLevel.CL_LOCAL_ONE;
    } else {
        consistency = ConsistencyLevel.CL_LOCAL_QUORUM;
    }

    final Iterator<Column<ByteBuffer>> manifestColumns = executePaginated(
            _keyspace.prepareQuery(ColumnFamilies.MANIFEST, consistency)
                    .getKey(channel)
                    .withColumnRange(range.build())
                    .autoPaginate(true));

    if (oldestSlab != null) {
        // Query was executed weakly using the cached oldest slab, so don't update the cache with an unreliable oldest value
        return manifestColumns;
    } else {
        PeekingIterator<Column<ByteBuffer>> peekingManifestColumns = Iterators.peekingIterator(manifestColumns);
        if (peekingManifestColumns.hasNext()) {
            // Cache the first slab returned from querying the full manifest column family since it is the oldest.
            cacheOldestSlabForChannel(channel, TimeUUIDSerializer.get().fromByteBuffer(peekingManifestColumns.peek().getName()));
            return peekingManifestColumns;
        } else {
            // Channel was completely empty.  Cache a TimeUUID for the current time.  This will cause future calls
            // to read at most 1 minute of tombstones until the cache expires 10 seconds later.
            cacheOldestSlabForChannel(channel, TimeUUIDs.newUUID());
            return Iterators.emptyIterator();
        }
    }
}
 
Example 3
Source File: AstyanaxThriftDataTableResource.java    From staash with Apache License 2.0 4 votes vote down vote up
@Override
public QueryResult readRow(String key, Integer columnCount, String startColumn, String endColumn, Boolean reversed) throws PaasException {
    invariant();
    
    try {
        // Construct the query
        RowQuery<ByteBuffer, ByteBuffer> query = keyspace
                .prepareQuery(this.columnFamily)
                .getRow(serializers.keyAsByteBuffer(key));
                
        RangeBuilder range = new RangeBuilder();
        if (columnCount != null && columnCount > 0) {
            range.setLimit(columnCount);
        }
        if (startColumn != null && !startColumn.isEmpty()) {
            range.setStart(serializers.columnAsByteBuffer(startColumn));
        }
        if (endColumn != null && !endColumn.isEmpty()) {
            range.setEnd(serializers.columnAsByteBuffer(endColumn));
        }
        range.setReversed(reversed);
        query.withColumnRange(range.build());

        // Execute the query
        ColumnList<ByteBuffer> result = query.execute().getResult();
        
        // Convert raw data into a simple sparse tree
        SchemalessRows.Builder builder = SchemalessRows.builder();
        Map<String, String> columns = Maps.newHashMap();
        if (!result.isEmpty()) {
            for (Column<ByteBuffer> column : result) { 
                columns.put(serializers.columnAsString(column.getRawName()), serializers.valueAsString(column.getRawName(), column.getByteBufferValue()));
            }
            builder.addRow(key, columns);
        }

        QueryResult dr = new QueryResult();
        dr.setSrows(builder.build());
        return dr;
    } catch (ConnectionException e) {
        throw new PaasException(
                String.format("Failed to read row '%s' in column family '%s.%s'" , 
                              key, this.keyspace.getKeyspaceName(), this.columnFamily.getName()),
                e);
    }
}
 
Example 4
Source File: EdgeSearcher.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public void buildRange( final RangeBuilder rangeBuilder ) {

    //set our start range since it was supplied to us
    if ( last.isPresent() ) {
        C sourceEdge = createColumn( last.get() );

        rangeBuilder.setStart( sourceEdge, getSerializer() );
    }else {
        setTimeScan( rangeBuilder );
    }

    setRangeOptions( rangeBuilder );


}
 
Example 5
Source File: EdgeShardSerializationImpl.java    From usergrid with Apache License 2.0 3 votes vote down vote up
@Override
public Iterator<Shard> getShardMetaData( final ApplicationScope scope,
                                         final Optional<Shard> start,   final DirectedEdgeMeta metaData  ) {

    ValidationUtils.validateApplicationScope( scope );
    GraphValidation.validateDirectedEdgeMeta( metaData );


    Preconditions.checkNotNull( metaData, "metadata must be present" );

    /**
     * If the edge is present, we need to being seeking from this
     */

    final RangeBuilder rangeBuilder = new RangeBuilder().setLimit( graphFig.getScanPageSize() );

    if ( start.isPresent() ) {
        final Shard shard = start.get();
        GraphValidation.valiateShard( shard );
        rangeBuilder.setStart( shard.getShardIndex() );
    }


    final ScopedRowKey rowKey = ScopedRowKey.fromKey( scope.getApplication(), metaData );


    final RowQuery<ScopedRowKey<DirectedEdgeMeta>, Long> query =
            keyspace.prepareQuery( EDGE_SHARDS ).setConsistencyLevel( cassandraConfig.getReadCL() ).getKey( rowKey )
                    .autoPaginate( true ).withColumnRange( rangeBuilder.build() );


    return new ColumnNameIterator<>( query, COLUMN_PARSER, false );
}
 
Example 6
Source File: EdgeSearcher.java    From usergrid with Apache License 2.0 3 votes vote down vote up
@Override
public void buildRange(final RangeBuilder rangeBuilder, final T start, T end) {

    final boolean ascending = order == SearchByEdgeType.Order.ASCENDING;


    if ( start != null){

        C sourceEdge = createColumn( start );

        if(ascending && last.isPresent() && comparator.compare(last.get(), start) < 0){

            sourceEdge = createColumn( last.get() );

        }else if (!ascending && last.isPresent() && comparator.compare(last.get(), start) > 0){

            sourceEdge = createColumn( last.get() );
        }

        rangeBuilder.setStart( sourceEdge, getSerializer() );


    }else{

        setTimeScan( rangeBuilder );


    }

    if( end != null){

        C endEdge = createColumn( end );
        rangeBuilder.setEnd( endEdge, getSerializer() );

    }

    setRangeOptions( rangeBuilder );
}