Search in sources :

Example 31 with PartitionIdSet

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with PartitionIdSet

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;
}
Also used : IPartitionService(com.hazelcast.internal.partition.IPartitionService) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) Data(com.hazelcast.internal.serialization.Data)

Example 33 with PartitionIdSet

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;
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) SetUtil.singletonPartitionIdSet(com.hazelcast.internal.util.SetUtil.singletonPartitionIdSet) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Predicate(com.hazelcast.query.Predicate)

Example 34 with PartitionIdSet

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;
}
Also used : IterationPointer(com.hazelcast.internal.iteration.IterationPointer) IterableUtil(com.hazelcast.internal.util.IterableUtil) Indexes(com.hazelcast.query.impl.Indexes) NodeEngine(com.hazelcast.spi.impl.NodeEngine) MapContainer(com.hazelcast.map.impl.MapContainer) Collection(java.util.Collection) HashUtil(com.hazelcast.internal.util.HashUtil) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) ClusterService(com.hazelcast.internal.cluster.ClusterService) ILogger(com.hazelcast.logging.ILogger) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QueryableEntriesSegment(com.hazelcast.query.impl.QueryableEntriesSegment) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) QueryOptimizer(com.hazelcast.query.impl.predicates.QueryOptimizer) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) SetUtil.singletonPartitionIdSet(com.hazelcast.internal.util.SetUtil.singletonPartitionIdSet) Predicate(com.hazelcast.query.Predicate) LocalMapStatsProvider(com.hazelcast.map.impl.LocalMapStatsProvider) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) SetUtil.singletonPartitionIdSet(com.hazelcast.internal.util.SetUtil.singletonPartitionIdSet) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Predicate(com.hazelcast.query.Predicate)

Example 35 with PartitionIdSet

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);
}
Also used : SerializationUtil.readNullablePartitionIdSet(com.hazelcast.internal.serialization.impl.SerializationUtil.readNullablePartitionIdSet) SerializationUtil.writeNullablePartitionIdSet(com.hazelcast.internal.serialization.impl.SerializationUtil.writeNullablePartitionIdSet) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet)

Aggregations

PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)55 QuickTest (com.hazelcast.test.annotation.QuickTest)24 Test (org.junit.Test)24 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)23 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)13 Address (com.hazelcast.cluster.Address)12 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)11 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)11 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)10 HashSet (java.util.HashSet)10 Predicate (com.hazelcast.query.Predicate)7 ArrayList (java.util.ArrayList)7 Data (com.hazelcast.internal.serialization.Data)5 UUID (java.util.UUID)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 IPartitionService (com.hazelcast.internal.partition.IPartitionService)4 Indexes (com.hazelcast.query.impl.Indexes)4 List (java.util.List)4 SetUtil.singletonPartitionIdSet (com.hazelcast.internal.util.SetUtil.singletonPartitionIdSet)3 QueryResultSizeExceededException (com.hazelcast.map.QueryResultSizeExceededException)3