use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class QueryUtilsTest method testUnassignedPartition_ignore.
@Test
public void testUnassignedPartition_ignore() {
HazelcastInstance member = factory.newHazelcastInstance();
member.getCluster().changeClusterState(ClusterState.FROZEN);
Map<UUID, PartitionIdSet> map = QueryUtils.createPartitionMap(Accessors.getNodeEngineImpl(member), null, false);
assertTrue(map.isEmpty());
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class CacheProxySupport method getPartitionsForKeys.
protected PartitionIdSet getPartitionsForKeys(Set<Data> keys) {
IPartitionService partitionService = getNodeEngine().getPartitionService();
int partitions = partitionService.getPartitionCount();
PartitionIdSet partitionIds = new PartitionIdSet(partitions);
Iterator<Data> iterator = keys.iterator();
int addedPartitions = 0;
while (iterator.hasNext() && addedPartitions < partitions) {
Data key = iterator.next();
if (partitionIds.add(partitionService.getPartitionId(key))) {
addedPartitions++;
}
}
return partitionIds;
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class QueryRunner method runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition.
// MIGRATION UNSAFE QUERYING - MIGRATION STAMPS ARE NOT VALIDATED, so assumes a run on partition-thread
// for a single partition. If the index is global it won't be asked
public Result runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition(Query query, int partitionId) {
MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
PartitionIdSet partitions = singletonPartitionIdSet(partitionCount, partitionId);
// first we optimize the query
Predicate predicate = queryOptimizer.optimize(query.getPredicate(), mapContainer.getIndexes(partitionId));
Iterable<QueryableEntry> entries = null;
Indexes indexes = mapContainer.getIndexes(partitionId);
if (indexes != null && !indexes.isGlobal()) {
entries = indexes.query(predicate, partitions.size());
}
Result result;
if (entries == null) {
result = createResult(query, partitions);
partitionScanExecutor.execute(query.getMapName(), predicate, partitions, result);
result.completeConstruction(partitions);
} else {
result = populateNonEmptyResult(query, entries, partitions);
}
return result;
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class QueryRunner method runIndexOrPartitionScanQueryOnOwnedPartitions.
/**
* MIGRATION SAFE QUERYING -> MIGRATION STAMPS ARE VALIDATED (does not have to run on a partition thread)
* full query = index query (if possible), then partition-scan query
*
* @param query the query to execute
* @param doPartitionScan whether to run full scan ion partitions if the global index run failed.
* @return the query result. {@code null} if the {@code doPartitionScan} is set and the execution on the
* global index failed.
*/
public Result runIndexOrPartitionScanQueryOnOwnedPartitions(Query query, boolean doPartitionScan) {
int migrationStamp = getMigrationStamp();
PartitionIdSet initialPartitions = mapServiceContext.getOrInitCachedMemberPartitions();
PartitionIdSet actualPartitions = query.getPartitionIdSet() != null ? initialPartitions.intersectCopy(query.getPartitionIdSet()) : initialPartitions;
MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
// to optimize the query we need to get any index instance
Indexes indexes = mapContainer.getIndexes();
if (indexes == null) {
indexes = mapContainer.getIndexes(initialPartitions.iterator().next());
}
// first we optimize the query
Predicate predicate = queryOptimizer.optimize(query.getPredicate(), indexes);
// then we try to run using an index, but if that doesn't work, we'll try a full table scan
Iterable<QueryableEntry> entries = runUsingGlobalIndexSafely(predicate, mapContainer, migrationStamp, initialPartitions.size());
if (entries != null && !initialPartitions.equals(actualPartitions)) {
assert indexes.isGlobal();
// if the query runs on a subset of partitions, filter the results from a global index
entries = IterableUtil.filter(entries, e -> {
int partitionId = HashUtil.hashToIndex(e.getKeyData().getPartitionHash(), partitionCount);
return actualPartitions.contains(partitionId);
});
}
if (entries == null && !doPartitionScan) {
return null;
}
Result result;
if (entries == null) {
result = runUsingPartitionScanSafely(query, predicate, actualPartitions, migrationStamp);
if (result == null) {
// full scan didn't work, returning empty result
result = populateEmptyResult(query, actualPartitions);
}
} else {
result = populateNonEmptyResult(query, entries, actualPartitions);
}
return result;
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class AggregationResult method combine.
@Override
public void combine(AggregationResult result) {
PartitionIdSet otherPartitionIds = result.getPartitionIds();
if (otherPartitionIds == null) {
return;
}
if (partitionIds == null) {
partitionIds = new PartitionIdSet(otherPartitionIds);
} else {
partitionIds.addAll(otherPartitionIds);
}
aggregator.combine(result.aggregator);
}
Aggregations