row = iter.next(); LOG.info("ROW: " +
row.getKey()); }
The iterator is implemented by making 'paginated' queries to Cassandra with
each query returning up to a the block size set by setBlockSize (default is
10). The incremental query is hidden from the caller thereby providing a
virtual view into the column family.
There are a few important implementation details that need to be considered.
This implementation assumes the random partitioner is used. Consequently the
KeyRange query is done using tokens and not row keys. This is done because
when using the random partitioner tokens are sorted while keys are not.
However, because multiple keys could potentially map to the same token each
incremental query to Cassandra will repeat the last token from the previous
response. This will ensure that no keys are skipped. This does however have
to very important implications. First, the last and potentially more (if they
have the same token) row keys from the previous response will repeat. Second,
if a range of repeating tokens is larger than the block size then the code
will enter an infinite loop. This can be mitigated by selecting a block size
that is large enough so that the likelyhood of this happening is very low.
Also, if your application can tolerate the potential for skipped row keys
then call setRepeatLastToken(false) to turn off this features.
Method Summary |
void |
executeWithCallback(RowCallback<K,C> callback)
Execute the operation in a separate thread for each token range and
provide the results in a callback. |
AllRowsQuery<K,C> |
forTokenRange(java.math.BigInteger startToken,
java.math.BigInteger endToken)
Execute the operation on a specific token range, instead of the entire range. |
AllRowsQuery<K,C> |
forTokenRange(java.lang.String startToken,
java.lang.String endToken)
|
AllRowsQuery<K,C> |
setBlockSize(int blockSize)
Deprecated. Use setRowLimit instead |
AllRowsQuery<K,C> |
setCheckpointManager(CheckpointManager manager)
Use this checkpoint manager to keep track of progress as all rows are being iterated |
AllRowsQuery<K,C> |
setConcurrencyLevel(int numberOfThreads)
Split the query into N threads with each thread processing an equal size chunk from the token range. |
AllRowsQuery<K,C> |
setExceptionCallback(com.netflix.astyanax.ExceptionCallback cb)
Sets the exception handler to use when handling exceptions inside
Iterator.next(). |
AllRowsQuery<K,C> |
setIncludeEmptyRows(boolean flag)
If set to false all empty rows will be filtered out internally. |
AllRowsQuery<K,C> |
setRepeatLastToken(boolean repeatLastToken)
If true will repeat the last token in the previous block. |
AllRowsQuery<K,C> |
setRowLimit(int rowLimit)
Maximum number of rows to return for each incremental query to Cassandra. |
AllRowsQuery<K,C> |
setThreadCount(int numberOfThreads)
Deprecated. |
AllRowsQuery<K,C> |
withColumnRange(java.nio.ByteBuffer startColumn,
java.nio.ByteBuffer endColumn,
boolean reversed,
int count)
Specify a range and provide pre-constructed start and end columns. |
AllRowsQuery<K,C> |
withColumnRange(ByteBufferRange range)
Specify a range of composite columns. |
AllRowsQuery<K,C> |
withColumnRange(C startColumn,
C endColumn,
boolean reversed,
int count)
Specify a range of columns to return. |
AllRowsQuery<K,C> |
withColumnSlice(C... columns)
Specify a non-contiguous set of columns to retrieve. |
AllRowsQuery<K,C> |
withColumnSlice(java.util.Collection<C> columns)
Specify a non-contiguous set of columns to retrieve. |
AllRowsQuery<K,C> |
withColumnSlice(ColumnSlice<C> columns)
Use this when your application caches the column slice. |
Methods inherited from interface com.netflix.astyanax.Execution |
execute, executeAsync |
setBlockSize
AllRowsQuery<K,C> setBlockSize(int blockSize)
- Deprecated. Use setRowLimit instead
setRowLimit
AllRowsQuery<K,C> setRowLimit(int rowLimit)
- Maximum number of rows to return for each incremental query to Cassandra.
This limit also represents the page size when paginating.
- Parameters:
blockSize
-
setExceptionCallback
AllRowsQuery<K,C> setExceptionCallback(com.netflix.astyanax.ExceptionCallback cb)
- Sets the exception handler to use when handling exceptions inside
Iterator.next(). This gives the caller a chance to implement a backoff
strategy or stop the iteration.
- Parameters:
cb
-
setCheckpointManager
AllRowsQuery<K,C> setCheckpointManager(CheckpointManager manager)
- Use this checkpoint manager to keep track of progress as all rows are being iterated
- Parameters:
manager
-
setRepeatLastToken
AllRowsQuery<K,C> setRepeatLastToken(boolean repeatLastToken)
- If true will repeat the last token in the previous block.
- Parameters:
repeatLastToken
-
setIncludeEmptyRows
AllRowsQuery<K,C> setIncludeEmptyRows(boolean flag)
- If set to false all empty rows will be filtered out internally.
Default is false
- Parameters:
flag
-
withColumnSlice
AllRowsQuery<K,C> withColumnSlice(C... columns)
- Specify a non-contiguous set of columns to retrieve.
- Parameters:
columns
-
withColumnSlice
AllRowsQuery<K,C> withColumnSlice(java.util.Collection<C> columns)
- Specify a non-contiguous set of columns to retrieve.
- Parameters:
columns
-
withColumnSlice
AllRowsQuery<K,C> withColumnSlice(ColumnSlice<C> columns)
- Use this when your application caches the column slice.
- Parameters:
slice
-
withColumnRange
AllRowsQuery<K,C> withColumnRange(C startColumn,
C endColumn,
boolean reversed,
int count)
- Specify a range of columns to return.
- Parameters:
startColumn
- First column in the rangeendColumn
- Last column in the rangereversed
- True if the order should be reversed. Note that for reversed,
startColumn should be greater than endColumn.count
- Maximum number of columns to return (similar to SQL LIMIT)
withColumnRange
AllRowsQuery<K,C> withColumnRange(java.nio.ByteBuffer startColumn,
java.nio.ByteBuffer endColumn,
boolean reversed,
int count)
- Specify a range and provide pre-constructed start and end columns. Use
this with Composite columns
- Parameters:
startColumn
- endColumn
- reversed
- count
-
withColumnRange
AllRowsQuery<K,C> withColumnRange(ByteBufferRange range)
- Specify a range of composite columns. Use this in conjunction with the
AnnotatedCompositeSerializer.buildRange().
- Parameters:
range
-
setConcurrencyLevel
AllRowsQuery<K,C> setConcurrencyLevel(int numberOfThreads)
- Split the query into N threads with each thread processing an equal size chunk from the token range.
Note that the actual number of threads is still limited by the available threads in the thread
pool that was set with the AstyanaxConfiguration.
- Parameters:
numberOfThreads
-
setThreadCount
@Deprecated
AllRowsQuery<K,C> setThreadCount(int numberOfThreads)
- Deprecated.
executeWithCallback
void executeWithCallback(RowCallback<K,C> callback)
throws com.netflix.astyanax.connectionpool.exceptions.ConnectionException
- Execute the operation in a separate thread for each token range and
provide the results in a callback.
- Parameters:
predicate
-
- Throws:
com.netflix.astyanax.connectionpool.exceptions.ConnectionException
forTokenRange
AllRowsQuery<K,C> forTokenRange(java.math.BigInteger startToken,
java.math.BigInteger endToken)
- Execute the operation on a specific token range, instead of the entire range.
Use this only is combination with setConcurrencyLevel being called otherwise
it currently will not have any effect on the query. When using forTokenRange
the specified token range will still be split into the number of threads
specified by setConcurrencyLevel
- Parameters:
startToken
- endToken
-
forTokenRange
AllRowsQuery<K,C> forTokenRange(java.lang.String startToken,
java.lang.String endToken)