Search in sources :

Example 1 with ExceptionCallback

use of com.netflix.astyanax.ExceptionCallback in project titan by thinkaurelius.

the class AstyanaxKeyColumnValueStore method getKeys.

@Override
public KeyIterator getKeys(@Nullable SliceQuery sliceQuery, StoreTransaction txh) throws BackendException {
    if (storeManager.getPartitioner() != Partitioner.RANDOM)
        throw new PermanentBackendException("This operation is only allowed when random partitioner (md5 or murmur3) is used.");
    AllRowsQuery allRowsQuery = keyspace.prepareQuery(columnFamily).getAllRows();
    if (sliceQuery != null) {
        allRowsQuery.withColumnRange(sliceQuery.getSliceStart().asByteBuffer(), sliceQuery.getSliceEnd().asByteBuffer(), false, sliceQuery.getLimit());
    }
    Rows<ByteBuffer, ByteBuffer> result;
    try {
        /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
        OperationResult op = // pre-fetch that many rows at a time
        allRowsQuery.setRowLimit(storeManager.getPageSize()).setConcurrencyLevel(// one execution thread for fetching portion of rows
        1).setExceptionCallback(new ExceptionCallback() {

            private int retries = 0;

            @Override
            public boolean onException(ConnectionException e) {
                try {
                    // make 3 re-tries
                    return retries > 2;
                } finally {
                    retries++;
                }
            }
        }).execute();
        result = ((OperationResult<Rows<ByteBuffer, ByteBuffer>>) op).getResult();
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
    return new RowIterator(result.iterator(), sliceQuery);
}
Also used : AllRowsQuery(com.netflix.astyanax.query.AllRowsQuery) OperationResult(com.netflix.astyanax.connectionpool.OperationResult) ExceptionCallback(com.netflix.astyanax.ExceptionCallback) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 2 with ExceptionCallback

use of com.netflix.astyanax.ExceptionCallback in project janusgraph by JanusGraph.

the class AstyanaxKeyColumnValueStore method getKeys.

@Override
public KeyIterator getKeys(@Nullable SliceQuery sliceQuery, StoreTransaction txh) throws BackendException {
    if (storeManager.getPartitioner() != Partitioner.RANDOM)
        throw new PermanentBackendException("This operation is only allowed when random partitioner (md5 or murmur3) is used.");
    AllRowsQuery allRowsQuery = keyspace.prepareQuery(columnFamily).getAllRows();
    if (sliceQuery != null) {
        allRowsQuery.withColumnRange(sliceQuery.getSliceStart().asByteBuffer(), sliceQuery.getSliceEnd().asByteBuffer(), false, sliceQuery.getLimit());
    }
    Rows<ByteBuffer, ByteBuffer> result;
    try {
        /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
        OperationResult op = // pre-fetch that many rows at a time
        allRowsQuery.setRowLimit(storeManager.getPageSize()).setConcurrencyLevel(// one execution thread for fetching portion of rows
        1).setExceptionCallback(new ExceptionCallback() {

            private int retries = 0;

            @Override
            public boolean onException(ConnectionException e) {
                try {
                    // make 3 re-tries
                    return retries > 2;
                } finally {
                    retries++;
                }
            }
        }).execute();
        result = ((OperationResult<Rows<ByteBuffer, ByteBuffer>>) op).getResult();
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
    return new RowIterator(result.iterator(), sliceQuery);
}
Also used : AllRowsQuery(com.netflix.astyanax.query.AllRowsQuery) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) OperationResult(com.netflix.astyanax.connectionpool.OperationResult) ExceptionCallback(com.netflix.astyanax.ExceptionCallback) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) Rows(com.netflix.astyanax.model.Rows)

Aggregations

ExceptionCallback (com.netflix.astyanax.ExceptionCallback)2 OperationResult (com.netflix.astyanax.connectionpool.OperationResult)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 AllRowsQuery (com.netflix.astyanax.query.AllRowsQuery)2 ByteBuffer (java.nio.ByteBuffer)2 Rows (com.netflix.astyanax.model.Rows)1 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)1