public class MapQueryEngineImpl extends Object implements MapQueryEngine
MapQueryEngine
implementation.Modifier and Type | Class and Description |
---|---|
protected class |
MapQueryEngineImpl.QueryPartitionCallable |
Modifier and Type | Field and Description |
---|---|
protected ClusterService |
clusterService |
protected ManagedExecutorService |
executor |
protected LocalMapStatsProvider |
localMapStatsProvider |
protected ILogger |
logger |
protected MapServiceContext |
mapServiceContext |
protected NodeEngine |
nodeEngine |
protected OperationService |
operationService |
protected boolean |
parallelEvaluation |
protected IPartitionService |
partitionService |
protected static long |
QUERY_EXECUTION_TIMEOUT_MINUTES |
protected QueryOptimizer |
queryOptimizer |
protected QueryResultSizeLimiter |
queryResultSizeLimiter |
protected InternalSerializationService |
serializationService |
Constructor and Description |
---|
MapQueryEngineImpl(MapServiceContext mapServiceContext,
QueryOptimizer optimizer) |
Modifier and Type | Method and Description |
---|---|
protected void |
addResultsOfPagingPredicate(List<Future<QueryResult>> futures,
Collection result,
Collection<Integer> partitionIds)
Adds results of paging predicates to result set and removes queried partition ids.
|
protected void |
addResultsOfPredicate(List<Future<QueryResult>> futures,
QueryResult result,
Collection<Integer> partitionIds)
Adds results of non-paging predicates to result set and removes queried partition ids.
|
protected void |
checkNotPagingPredicate(Predicate predicate) |
protected Set<Integer> |
createSetWithPopulatedPartitionIds(int partitionCount) |
protected Set<Integer> |
getAllPartitionIds() |
protected List<Integer> |
getLocalPartitionIds() |
protected long |
getNow() |
protected static Collection<Collection<QueryableEntry>> |
getResult(List<Future<Collection<QueryableEntry>>> lsFutures) |
protected boolean |
hasOwnerMigrationsInFlight()
Check whether migrations of owner partition are currently executed.
|
protected boolean |
hasPartitionStateVersionChanged(int initialPartitionStateVersion)
Check whether partition state version has changed since
initialPartitionStateVersion . |
protected boolean |
hasPartitionVersion(int expectedVersion,
Predicate predicate) |
QueryResult |
invokeQueryAllPartitions(String mapName,
Predicate predicate,
IterationType iterationType)
Queries all partitions.
|
QueryResult |
invokeQueryLocalPartitions(String mapName,
Predicate predicate,
IterationType iterationType)
Query all local partitions.
|
protected boolean |
isResultSafe(int initialPartitionStateVersion)
Check whether results obtained since partition state version was at
initialPartitionStateVersion are safe to be
returned to the caller. |
protected QueryResult |
newQueryResult(int numberOfPartitions,
IterationType iterationType)
Creates a
QueryResult with configured result limit (according to the number of partitions) if feature is enabled. |
Set |
queryAllPartitionsWithPagingPredicate(String mapName,
PagingPredicate predicate,
IterationType iterationType)
Queries all partitions with a paging predicate.
|
QueryResult |
queryLocalPartition(String mapName,
Predicate predicate,
int partitionId,
IterationType iterationType)
Executes a query on a specific local partition.
|
QueryResult |
queryLocalPartitions(String mapName,
Predicate predicate,
IterationType iterationType)
Executes a query on all the local partitions.
|
Set |
queryLocalPartitionsWithPagingPredicate(String mapName,
PagingPredicate predicate,
IterationType iterationType)
Query all local partitions with a paging predicate.
|
protected Future<QueryResult> |
queryOnLocalMember(String mapName,
Predicate predicate,
IterationType iterationType) |
protected List<Future<QueryResult>> |
queryOnMembers(String mapName,
Predicate predicate,
IterationType iterationType) |
protected QueryResult |
queryParallel(String name,
Predicate predicate,
Collection<Integer> partitions,
IterationType iterationType) |
protected QueryResult |
queryParallelForPaging(String name,
PagingPredicate predicate,
Collection<Integer> partitions,
IterationType iterationType) |
protected List<Future<QueryResult>> |
queryPartitions(String mapName,
Predicate predicate,
Collection<Integer> partitionIds,
IterationType iterationType) |
protected QueryResult |
querySafelyUsingFullTableScan(String name,
Predicate predicate,
Collection<Integer> partitions,
IterationType iterationType,
int initialPartitionStateVersion)
Wraps
queryUsingFullTableScan(String, Predicate, Collection, IterationType) to avoid returning potentially
flawed results. |
protected QueryResult |
querySequential(String name,
Predicate predicate,
Collection<Integer> partitions,
IterationType iterationType) |
protected Collection<QueryableEntry> |
queryTheLocalPartition(String mapName,
Predicate predicate,
int partitionId) |
protected QueryResult |
queryUsingFullTableScan(String name,
Predicate predicate,
Collection<Integer> partitions,
IterationType iterationType) |
protected Object |
toObject(Object obj) |
protected QueryResult |
tryQueryUsingIndexes(Predicate predicate,
Collection<Integer> partitions,
MapContainer mapContainer,
IterationType iterationType,
int initialPartitionStateVersion) |
protected void |
updateStatistics(MapContainer mapContainer) |
protected static final long QUERY_EXECUTION_TIMEOUT_MINUTES
protected final MapServiceContext mapServiceContext
protected final NodeEngine nodeEngine
protected final ILogger logger
protected final QueryResultSizeLimiter queryResultSizeLimiter
protected final InternalSerializationService serializationService
protected final IPartitionService partitionService
protected final QueryOptimizer queryOptimizer
protected final OperationService operationService
protected final ClusterService clusterService
protected final LocalMapStatsProvider localMapStatsProvider
protected final boolean parallelEvaluation
protected final ManagedExecutorService executor
public MapQueryEngineImpl(MapServiceContext mapServiceContext, QueryOptimizer optimizer)
public QueryResult queryLocalPartitions(String mapName, Predicate predicate, IterationType iterationType) throws ExecutionException, InterruptedException
MapQueryEngine
- Uses Indexes
- Accepts PagingPredicate
- Query executed in the calling thread
- predicate evaluation will be parallelized if QUERY_PREDICATE_PARALLEL_EVALUATION is enabled or a PagingPredicate is used.
- may return empty QueryResult (with a properly initialized result limit size) if query is executed during migrations and
migration conditions do not allow for safe retrieval of results (ie. there are migrations in flight or partition state
version is different at the end of query vs the version observed at the beginning of query). In this case, partitionIds
are not set on the QueryResult, so callers will ignore these results and fallback to QueryPartitionOperation
s.
queryLocalPartitions
in interface MapQueryEngine
mapName
- the name of the mappredicate
- the predicateExecutionException
InterruptedException
protected QueryResult tryQueryUsingIndexes(Predicate predicate, Collection<Integer> partitions, MapContainer mapContainer, IterationType iterationType, int initialPartitionStateVersion)
protected void updateStatistics(MapContainer mapContainer)
protected QueryResult querySafelyUsingFullTableScan(String name, Predicate predicate, Collection<Integer> partitions, IterationType iterationType, int initialPartitionStateVersion) throws InterruptedException, ExecutionException
queryUsingFullTableScan(String, Predicate, Collection, IterationType)
to avoid returning potentially
flawed results.
null
, as
results cannot be reliably obtainedname
- predicate
- partitions
- iterationType
- initialPartitionStateVersion
- null
if results are considered potentially flawed.InterruptedException
ExecutionException
protected QueryResult queryUsingFullTableScan(String name, Predicate predicate, Collection<Integer> partitions, IterationType iterationType) throws InterruptedException, ExecutionException
protected QueryResult querySequential(String name, Predicate predicate, Collection<Integer> partitions, IterationType iterationType)
protected QueryResult queryParallel(String name, Predicate predicate, Collection<Integer> partitions, IterationType iterationType) throws InterruptedException, ExecutionException
protected QueryResult queryParallelForPaging(String name, PagingPredicate predicate, Collection<Integer> partitions, IterationType iterationType) throws InterruptedException, ExecutionException
protected static Collection<Collection<QueryableEntry>> getResult(List<Future<Collection<QueryableEntry>>> lsFutures)
protected boolean hasPartitionVersion(int expectedVersion, Predicate predicate)
protected Collection<QueryableEntry> queryTheLocalPartition(String mapName, Predicate predicate, int partitionId)
public QueryResult queryLocalPartition(String mapName, Predicate predicate, int partitionId, IterationType iterationType)
MapQueryEngine
- Does NOT use Indexes - Accepts PagingPredicate - Sequential full table scan - Query executed in the calling thread
todo: what happens when the partition is not local?
queryLocalPartition
in interface MapQueryEngine
mapName
- map name.predicate
- any predicate.partitionId
- partition id.public QueryResult invokeQueryLocalPartitions(String mapName, Predicate predicate, IterationType iterationType)
MapQueryEngine
- Does NOT accept PagingPredicate
- Query executed in an Operation on this member (NOT in the calling thread)
- Calls MapQueryEngine.queryLocalPartitions(String, Predicate, IterationType)
in an operation
invokeQueryLocalPartitions
in interface MapQueryEngine
mapName
- map name.predicate
- except paging predicate.iterationType
- the IterationTypepublic Set queryLocalPartitionsWithPagingPredicate(String mapName, PagingPredicate predicate, IterationType iterationType)
MapQueryEngine
- Query executed in an Operation on this member (or other members if some partitions are not local)
TODO: it would be better to have a single queryLocal... method and let the implementation figure out how to deal with a regular predicate and a paging predicate. No need to have that in the interface. The problem is that currently the signatures don't match up. This implementation detail should not be exposed through the interface.
queryLocalPartitionsWithPagingPredicate
in interface MapQueryEngine
mapName
- map name.predicate
- to queryOnMembers.iterationType
- type of IterationType
SortedQueryResultSet
public Set queryAllPartitionsWithPagingPredicate(String mapName, PagingPredicate predicate, IterationType iterationType)
MapQueryEngine
- Query executed in an Operation on each member (NOT in the calling thread)
TODO:
it would be better to have single queryAll method and let the implementation figure out how to deal
with a paging predicate. See comment in MapQueryEngine.queryLocalPartitionsWithPagingPredicate(java.lang.String, com.hazelcast.query.PagingPredicate, com.hazelcast.util.IterationType)
queryAllPartitionsWithPagingPredicate
in interface MapQueryEngine
mapName
- map name.predicate
- to queryOnMembers.iterationType
- type of IterationType
SortedQueryResultSet
public QueryResult invokeQueryAllPartitions(String mapName, Predicate predicate, IterationType iterationType)
MapQueryEngine
MapQueryEngine.queryLocalPartitions(String, Predicate, IterationType)
in an operationinvokeQueryAllPartitions
in interface MapQueryEngine
mapName
- map name.predicate
- except paging predicate.iterationType
- the IterationTypeprotected QueryResult newQueryResult(int numberOfPartitions, IterationType iterationType)
QueryResult
with configured result limit (according to the number of partitions) if feature is enabled.numberOfPartitions
- number of partitions to calculate result limitQueryResult
protected void checkNotPagingPredicate(Predicate predicate)
protected Future<QueryResult> queryOnLocalMember(String mapName, Predicate predicate, IterationType iterationType)
protected List<Future<QueryResult>> queryOnMembers(String mapName, Predicate predicate, IterationType iterationType)
protected List<Future<QueryResult>> queryPartitions(String mapName, Predicate predicate, Collection<Integer> partitionIds, IterationType iterationType)
protected void addResultsOfPagingPredicate(List<Future<QueryResult>> futures, Collection result, Collection<Integer> partitionIds) throws ExecutionException, InterruptedException
protected void addResultsOfPredicate(List<Future<QueryResult>> futures, QueryResult result, Collection<Integer> partitionIds) throws ExecutionException, InterruptedException
protected Set<Integer> createSetWithPopulatedPartitionIds(int partitionCount)
protected long getNow()
protected boolean hasOwnerMigrationsInFlight()
true
if owner partition migrations are currently being executed, otherwise false.DelegatingMigrationAwareService
protected boolean hasPartitionStateVersionChanged(int initialPartitionStateVersion)
initialPartitionStateVersion
.initialPartitionStateVersion
- the initial partition state version to compare againsttrue
if current partition state version is not equal to initialPartitionStateVersion
protected boolean isResultSafe(int initialPartitionStateVersion)
initialPartitionStateVersion
are safe to be
returned to the caller. Effectively this method checks:
initialPartitionStateVersion
- true
if no owner migrations are currently executing and initialPartitionStateVersion
is the same
as the current partition state version, otherwise false
.Copyright © 2016 Hazelcast, Inc.. All Rights Reserved.