Search in sources :

Example 41 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class PlanCacheChecker method check.

public void check() {
    if (planCache.size() == 0) {
        return;
    }
    // Collect object IDs
    SqlCatalog catalog = new SqlCatalog(tableResolvers);
    Set<PlanObjectKey> objectKeys = new HashSet<>();
    for (Map<String, Table> tableMap : catalog.getSchemas().values()) {
        for (Table table : tableMap.values()) {
            PlanObjectKey objectKey = table.getObjectKey();
            if (objectKey != null) {
                objectKeys.add(objectKey);
            }
        }
    }
    // Prepare partition distribution
    Map<UUID, PartitionIdSet> partitions = QueryUtils.createPartitionMap(nodeEngine, null, false);
    // Do check
    planCache.check(new PlanCheckContext(objectKeys, partitions));
}
Also used : SqlCatalog(com.hazelcast.sql.impl.schema.SqlCatalog) PlanCheckContext(com.hazelcast.sql.impl.optimizer.PlanCheckContext) Table(com.hazelcast.sql.impl.schema.Table) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 42 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class MapIndexScanP method splitOnMigration.

/**
 * Perform splitting of a {@link Split} after receiving {@link MissingPartitionException}
 * or various cluster state exceptions like {@link MemberLeftException}.
 * <p>
 * Method gets current partition table and proceeds with following procedure:
 * <p>
 * It splits the partitions assigned to the split according to the new
 * partition owner into disjoint sets, one for each owner.
 *
 * @param split the split to split
 * @return collection of new split units
 */
private List<Split> splitOnMigration(Split split) {
    IndexIterationPointer[] lastPointers = split.pointers;
    InternalPartitionService partitionService = getNodeEngine(hazelcastInstance).getPartitionService();
    Map<Address, Split> newSplits = new HashMap<>();
    PrimitiveIterator.OfInt partitionIterator = split.partitions.intIterator();
    while (partitionIterator.hasNext()) {
        int partitionId = partitionIterator.nextInt();
        // If at least one partition owner is not assigned -- assign current member.
        // Later, a WrongTargetException will be thrown
        // and it causes this method to be called again.
        // Occasionally prediction with current member would be correct.
        Address potentialOwner = partitionService.getPartition(partitionId).getOwnerOrNull();
        Address owner = potentialOwner == null ? split.owner : partitionService.getPartition(partitionId).getOwnerOrNull();
        newSplits.computeIfAbsent(owner, x -> new Split(new PartitionIdSet(partitionService.getPartitionCount()), owner, lastPointers)).partitions.add(partitionId);
    }
    return new ArrayList<>(newSplits.values());
}
Also used : Address(com.hazelcast.cluster.Address) PrimitiveIterator(java.util.PrimitiveIterator) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) HashMap(java.util.HashMap) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) ArrayList(java.util.ArrayList)

Example 43 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class MapExecuteOnKeysMessageTask method getPartitions.

@Override
public PartitionIdSet getPartitions() {
    IPartitionService partitionService = nodeEngine.getPartitionService();
    int partitions = partitionService.getPartitionCount();
    PartitionIdSet partitionIds = new PartitionIdSet(partitions);
    Iterator<Data> iterator = parameters.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 44 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class AbstractMapQueryMessageTask method createInvocationsForMissingPartitions.

private void createInvocationsForMissingPartitions(PartitionIdSet missingPartitionsList, List<Future> futures, Predicate predicate) {
    final OperationServiceImpl operationService = nodeEngine.getOperationService();
    MapService mapService = nodeEngine.getService(getServiceName());
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    Query query = buildQuery(predicate);
    PrimitiveIterator.OfInt missingPartitionIterator = missingPartitionsList.intIterator();
    missingPartitionIterator.forEachRemaining((IntConsumer) partitionId -> {
        MapOperation queryPartitionOperation = createQueryPartitionOperation(query, mapServiceContext);
        queryPartitionOperation.setPartitionId(partitionId);
        try {
            Future future = operationService.invokeOnPartition(SERVICE_NAME, queryPartitionOperation, partitionId);
            futures.add(future);
        } catch (Throwable t) {
            throw rethrow(t);
        }
    });
}
Also used : Query(com.hazelcast.map.impl.query.Query) PartitionPredicate(com.hazelcast.query.PartitionPredicate) Member(com.hazelcast.cluster.Member) IntConsumer(java.util.function.IntConsumer) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) Aggregator(com.hazelcast.aggregation.Aggregator) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) AbstractCallableMessageTask(com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask) DATA_MEMBER_SELECTOR(com.hazelcast.cluster.memberselector.MemberSelectors.DATA_MEMBER_SELECTOR) Operation(com.hazelcast.spi.impl.operationservice.Operation) ActionConstants(com.hazelcast.security.permission.ActionConstants) LinkedList(java.util.LinkedList) Predicate(com.hazelcast.query.Predicate) QueryException(com.hazelcast.query.QueryException) HazelcastException(com.hazelcast.core.HazelcastException) MapOperation(com.hazelcast.map.impl.operation.MapOperation) Connection(com.hazelcast.internal.nio.Connection) SetUtil(com.hazelcast.internal.util.SetUtil) Collection(java.util.Collection) MapService(com.hazelcast.map.impl.MapService) Result(com.hazelcast.map.impl.query.Result) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) Node(com.hazelcast.instance.impl.Node) PrimitiveIterator(java.util.PrimitiveIterator) ExecutionException(java.util.concurrent.ExecutionException) SERVICE_NAME(com.hazelcast.map.impl.MapService.SERVICE_NAME) List(java.util.List) Permission(java.security.Permission) IterationType(com.hazelcast.internal.util.IterationType) Projection(com.hazelcast.projection.Projection) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapPermission(com.hazelcast.security.permission.MapPermission) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Query(com.hazelcast.map.impl.query.Query) PrimitiveIterator(java.util.PrimitiveIterator) Future(java.util.concurrent.Future) MapService(com.hazelcast.map.impl.MapService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 45 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class SetUtil method singletonPartitionIdSet.

public static PartitionIdSet singletonPartitionIdSet(int partitionCount, int partitionId) {
    PartitionIdSet set = new PartitionIdSet(partitionCount);
    set.add(partitionId);
    return set;
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) ImmutablePartitionIdSet(com.hazelcast.internal.util.collection.ImmutablePartitionIdSet)

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