Search in sources :

Example 6 with PartitionIdSet

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

the class QueryResult method combine.

@Override
public void combine(QueryResult result) {
    PartitionIdSet otherPartitionIds = result.getPartitionIds();
    if (otherPartitionIds == null) {
        return;
    }
    if (partitionIds == null) {
        partitionIds = new PartitionIdSet(otherPartitionIds);
    } else {
        partitionIds.addAll(otherPartitionIds);
    }
    rows.addAll(result.rows);
}
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)

Example 7 with PartitionIdSet

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

the class QueryRunner method runIndexQueryOnOwnedPartitions.

/**
 * Performs the given query using indexes.
 * <p>
 * The method may return a special failure result, which has {@code null}
 * {@link Result#getPartitionIds() partition IDs}, in the following
 * situations:
 * <ul>
 * <li>If a partition migration is detected during the query execution.
 * <li>If it's impossible to perform the given query using indexes.
 * </ul>
 * <p>
 * The method may be invoked on any thread.
 *
 * @param query the query to perform.
 * @return the result of the query; if the result has {@code null} {@link
 * Result#getPartitionIds() partition IDs} this indicates a failure.
 */
public Result runIndexQueryOnOwnedPartitions(Query query) {
    int migrationStamp = getMigrationStamp();
    PartitionIdSet initialPartitions = mapServiceContext.getOrInitCachedMemberPartitions();
    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
    Iterable<QueryableEntry> entries = runUsingGlobalIndexSafely(predicate, mapContainer, migrationStamp, initialPartitions.size());
    Result result;
    if (entries == null) {
        // failed with index query because of ongoing migrations
        result = populateEmptyResult(query, initialPartitions);
    } else {
        // success
        result = populateNonEmptyResult(query, entries, initialPartitions);
    }
    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 8 with PartitionIdSet

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

the class GlobalIndexPartitionTracker method clear.

public void clear() {
    lock.lock();
    try {
        State oldState = state.get();
        State newState = new State(oldState.stamp + 1, new PartitionIdSet(partitionCount), 0);
        state.set(newState);
    } finally {
        lock.unlock();
    }
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet)

Example 9 with PartitionIdSet

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

the class MapTableUtils method estimatePartitionedMapRowCount.

public static long estimatePartitionedMapRowCount(NodeEngine nodeEngine, MapServiceContext context, String mapName) {
    long entryCount = 0L;
    PartitionIdSet ownerPartitions = context.getOrInitCachedMemberPartitions();
    for (PartitionContainer partitionContainer : context.getPartitionContainers()) {
        if (!ownerPartitions.contains(partitionContainer.getPartitionId())) {
            continue;
        }
        RecordStore<?> recordStore = partitionContainer.getExistingRecordStore(mapName);
        if (recordStore == null) {
            continue;
        }
        entryCount += recordStore.size();
    }
    int memberCount = nodeEngine.getClusterService().getMembers(MemberSelectors.DATA_MEMBER_SELECTOR).size();
    return entryCount * memberCount;
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet)

Example 10 with PartitionIdSet

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

the class SerializationUtil method readNullablePartitionIdSet.

public static PartitionIdSet readNullablePartitionIdSet(ObjectDataInput in) throws IOException {
    int partitionCount = in.readInt();
    if (partitionCount == -1) {
        return null;
    }
    PartitionIdSet result = new PartitionIdSet(partitionCount);
    int setSize = in.readInt();
    for (int i = 0; i < setSize; i++) {
        result.add(in.readInt());
    }
    return result;
}
Also used : 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