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);
}
}
}
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.");
}
}
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();
}
}
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);
}
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;
}
Aggregations