Search in sources :

Example 36 with PartitionIdSet

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

the class QueryEngineImpl method addResultsOfPredicate.

@SuppressWarnings("unchecked")
private // modifies partitionIds list! Optimization not to allocate an extra collection with collected partitionIds
void addResultsOfPredicate(List<Future<Result>> futures, Result result, PartitionIdSet unfinishedPartitionIds, boolean rethrowAll) {
    for (Future<Result> future : futures) {
        Result queryResult = null;
        try {
            queryResult = future.get();
        } catch (Throwable t) {
            if (t.getCause() instanceof QueryResultSizeExceededException || rethrowAll) {
                throw rethrow(t);
            }
            logger.fine("Could not get query results", t);
        }
        if (queryResult == null) {
            continue;
        }
        PartitionIdSet queriedPartitionIds = queryResult.getPartitionIds();
        if (queriedPartitionIds != null) {
            if (!unfinishedPartitionIds.containsAll(queriedPartitionIds)) {
                // see also https://github.com/hazelcast/hazelcast/issues/6471
                continue;
            }
            unfinishedPartitionIds.removeAll(queriedPartitionIds);
            result.combine(queryResult);
        }
    }
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException)

Example 37 with PartitionIdSet

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

the class QueryResultSizeLimiter method precheckMaxResultLimitOnLocalPartitions.

void precheckMaxResultLimitOnLocalPartitions(String mapName) {
    // check if feature is enabled
    if (!isPreCheckEnabled) {
        return;
    }
    // limit number of local partitions to check to keep runtime constant
    PartitionIdSet localPartitions = mapServiceContext.getOrInitCachedMemberPartitions();
    int partitionsToCheck = min(localPartitions.size(), maxLocalPartitionsLimitForPreCheck);
    if (partitionsToCheck == 0) {
        return;
    }
    // calculate size of local partitions
    int localPartitionSize = getLocalPartitionSize(mapName, localPartitions, partitionsToCheck);
    if (localPartitionSize == 0) {
        return;
    }
    // check local result size
    long localResultLimit = getNodeResultLimit(partitionsToCheck);
    if (localPartitionSize > localResultLimit * MAX_RESULT_LIMIT_FACTOR_FOR_PRECHECK) {
        throw new QueryResultSizeExceededException(maxResultLimit, " Result size exceeded in local pre-check.");
    }
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException)

Example 38 with PartitionIdSet

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

the class GlobalIndexPartitionTracker method complete.

private void complete(int partition, boolean indexed) {
    lock.lock();
    try {
        State oldState = state.get();
        assert oldState.pending > 0;
        PartitionIdSet newIndexedPartitions = oldState.indexedPartitions.copy();
        if (indexed) {
            newIndexedPartitions.add(partition);
        } else {
            newIndexedPartitions.remove(partition);
        }
        State newState = new State(oldState.stamp + 1, newIndexedPartitions, oldState.pending - 1);
        state.set(newState);
    } finally {
        lock.unlock();
    }
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet)

Example 39 with PartitionIdSet

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

the class MapProxySupport method executeQueryInternal.

protected <T extends Result> T executeQueryInternal(Predicate predicate, Aggregator aggregator, Projection projection, IterationType iterationType, Target target) {
    QueryEngine queryEngine = getMapQueryEngine();
    final Predicate userPredicate;
    if (predicate instanceof PartitionPredicate) {
        PartitionPredicate partitionPredicate = (PartitionPredicate) predicate;
        Data key = toData(partitionPredicate.getPartitionKey());
        int partitionId = partitionService.getPartitionId(key);
        if (target.mode() == TargetMode.LOCAL_NODE && !partitionService.isPartitionOwner(partitionId) || target.mode() == TargetMode.PARTITION_OWNER && !target.partitions().contains(partitionId)) {
            userPredicate = alwaysFalse();
        } else {
            target = createPartitionTarget(new PartitionIdSet(partitionService.getPartitionCount(), partitionId));
            userPredicate = partitionPredicate.getTarget();
        }
    } else {
        userPredicate = predicate;
    }
    handleHazelcastInstanceAwareParams(userPredicate);
    Query query = Query.of().mapName(getName()).predicate(userPredicate).iterationType(iterationType).aggregator(aggregator).projection(projection).build();
    return queryEngine.execute(query, target);
}
Also used : PartitionPredicate(com.hazelcast.query.PartitionPredicate) Query(com.hazelcast.map.impl.query.Query) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) Data(com.hazelcast.internal.serialization.Data) QueryEngine(com.hazelcast.map.impl.query.QueryEngine) PartitionPredicate(com.hazelcast.query.PartitionPredicate) TruePredicate(com.hazelcast.query.impl.predicates.TruePredicate) Predicate(com.hazelcast.query.Predicate)

Example 40 with PartitionIdSet

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

the class QueryUtils method createPartitionMap.

/**
 * Create map from member ID to owned partitions.
 *
 * @param nodeEngine node engine
 * @param localMemberVersion version of the local member. If any of partition owners have a different version, an exception
 *                           is thrown. The check is ignored if passed version is {@code null}
 * @param failOnUnassignedPartition whether the call should fail in case an unassigned partition is found; when set to
 *                                  {@code false} the missing partitions will not be included in the result
 * @return partition mapping
 */
public static Map<UUID, PartitionIdSet> createPartitionMap(NodeEngine nodeEngine, @Nullable MemberVersion localMemberVersion, boolean failOnUnassignedPartition) {
    Collection<Partition> parts = nodeEngine.getHazelcastInstance().getPartitionService().getPartitions();
    int partCnt = parts.size();
    Map<UUID, PartitionIdSet> partMap = new LinkedHashMap<>();
    for (Partition part : parts) {
        Member owner = part.getOwner();
        if (owner == null) {
            if (failOnUnassignedPartition) {
                throw QueryException.error(SqlErrorCode.PARTITION_DISTRIBUTION, "Partition is not assigned to any member: " + part.getPartitionId());
            } else {
                continue;
            }
        }
        if (localMemberVersion != null) {
            if (!localMemberVersion.equals(owner.getVersion())) {
                UUID localMemberId = nodeEngine.getLocalMember().getUuid();
                throw QueryException.error("Cannot execute SQL query when members have different versions " + "(make sure that all members have the same version) {localMemberId=" + localMemberId + ", localMemberVersion=" + localMemberVersion + ", remoteMemberId=" + owner.getUuid() + ", remoteMemberVersion=" + owner.getVersion() + "}");
            }
        }
        partMap.computeIfAbsent(owner.getUuid(), (key) -> new PartitionIdSet(partCnt)).add(part.getPartitionId());
    }
    return partMap;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) Member(com.hazelcast.cluster.Member) Partition(com.hazelcast.partition.Partition) Collection(java.util.Collection) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) UUID(java.util.UUID) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TableResolver(com.hazelcast.sql.impl.schema.TableResolver) List(java.util.List) MemberVersion(com.hazelcast.version.MemberVersion) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) Version(com.hazelcast.version.Version) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) Partition(com.hazelcast.partition.Partition) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) LinkedHashMap(java.util.LinkedHashMap)

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