Class MultiPartitionPager<T extends SinglePartitionReadQuery>
java.lang.Object
org.apache.cassandra.service.pager.MultiPartitionPager<T>
- All Implemented Interfaces:
QueryPager
public class MultiPartitionPager<T extends SinglePartitionReadQuery>
extends Object
implements QueryPager
Pager over a list of SinglePartitionReadQuery.
Note that this is not easy to make efficient. Indeed, we need to page the first query fully before
returning results from the next one, but if the result returned by each query is small (compared to pageSize),
paging the queries one at a time under-performs compared to parallelizing. On the other, if we parallelize
and each query raised pageSize results, we'll end up with queries.size() * pageSize results in memory, which
defeats the purpose of paging.
For now, we keep it simple (somewhat) and just do one query at a time. Provided that we make sure to not
create a pager unless we need to, this is probably fine. Though if we later want to get fancy, we could use the
cfs meanPartitionSize to decide if parallelizing some of the query might be worth it while being confident we don't
blow out memory.
-
Field Summary
Fields inherited from interface org.apache.cassandra.service.pager.QueryPager
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionMultiPartitionPager(SinglePartitionReadQuery.Group<T> group, PagingState state, ProtocolVersion protocolVersion) -
Method Summary
Modifier and TypeMethodDescriptionStarts a new read operation.fetchPage(int pageSize, ConsistencyLevel consistency, ClientState clientState, Dispatcher.RequestTime requestTime) Fetches the next page.fetchPageInternal(int pageSize, ReadExecutionController executionController) Fetches the next page internally (in other, this does a local query).booleanWhether or not this pager is exhausted, i.e.intThe maximum number of cells/CQL3 row that we may still have to return.state()Get the current state of the pager.withUpdatedLimit(DataLimits newLimits) Creates a newQueryPagerthat use the new limits.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cassandra.service.pager.QueryPager
isTopK
-
Constructor Details
-
MultiPartitionPager
public MultiPartitionPager(SinglePartitionReadQuery.Group<T> group, PagingState state, ProtocolVersion protocolVersion)
-
-
Method Details
-
withUpdatedLimit
Description copied from interface:QueryPagerCreates a newQueryPagerthat use the new limits.- Specified by:
withUpdatedLimitin interfaceQueryPager- Parameters:
newLimits- the new limits- Returns:
- a new
QueryPagerthat use the new limits
-
state
Description copied from interface:QueryPagerGet the current state of the pager. The state can allow to restart the paging on another host from where we are at this point.- Specified by:
statein interfaceQueryPager- Returns:
- the current paging state. Will return null if paging is at the beginning. If the pager is exhausted, the result is undefined.
-
isExhausted
public boolean isExhausted()Description copied from interface:QueryPagerWhether or not this pager is exhausted, i.e. whether or not a call to fetchPage may return more result.- Specified by:
isExhaustedin interfaceQueryPager- Returns:
- whether the pager is exhausted.
-
executionController
Description copied from interface:QueryPagerStarts a new read operation.This must be called before
QueryPager.fetchPageInternal(int,org.apache.cassandra.db.ReadExecutionController)and passed to it to protect the read. The returned object must be closed on all path and it is thus strongly advised to use it in a try-with-ressource construction.- Specified by:
executionControllerin interfaceQueryPager- Returns:
- a newly started order group for this
QueryPager.
-
fetchPage
public PartitionIterator fetchPage(int pageSize, ConsistencyLevel consistency, ClientState clientState, Dispatcher.RequestTime requestTime) throws RequestValidationException, RequestExecutionException Description copied from interface:QueryPagerFetches the next page.- Specified by:
fetchPagein interfaceQueryPager- Parameters:
pageSize- the maximum number of elements to return in the next page.consistency- the consistency level to achieve for the query.clientState- theClientStatefor the query. In practice, this can be null unlessconsistencyis a serial consistency.- Returns:
- the page of result.
- Throws:
RequestValidationExceptionRequestExecutionException
-
fetchPageInternal
public PartitionIterator fetchPageInternal(int pageSize, ReadExecutionController executionController) throws RequestValidationException, RequestExecutionException Description copied from interface:QueryPagerFetches the next page internally (in other, this does a local query).- Specified by:
fetchPageInternalin interfaceQueryPager- Parameters:
pageSize- the maximum number of elements to return in the next page.executionController- theReadExecutionControllerprotecting the read.- Returns:
- the page of result.
- Throws:
RequestValidationExceptionRequestExecutionException
-
maxRemaining
public int maxRemaining()Description copied from interface:QueryPagerThe maximum number of cells/CQL3 row that we may still have to return. In other words, that's the initial user limit minus what we've already returned (note that it's not how many we *will* return, just the upper limit on it).- Specified by:
maxRemainingin interfaceQueryPager
-