Search in sources :

Example 11 with PartitionIdSet

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

the class MapServiceContextImpl method getOrInitCachedMemberPartitions.

@Override
public PartitionIdSet getOrInitCachedMemberPartitions() {
    PartitionIdSet ownedPartitionIdSet = ownedPartitions;
    if (ownedPartitionIdSet != null) {
        return ownedPartitionIdSet;
    }
    synchronized (this) {
        ownedPartitionIdSet = ownedPartitions;
        if (ownedPartitionIdSet != null) {
            return ownedPartitionIdSet;
        }
        IPartitionService partitionService = nodeEngine.getPartitionService();
        Collection<Integer> partitions = partitionService.getMemberPartitions(nodeEngine.getThisAddress());
        ownedPartitionIdSet = immutablePartitionIdSet(partitionService.getPartitionCount(), partitions);
        ownedPartitions = ownedPartitionIdSet;
    }
    return ownedPartitionIdSet;
}
Also used : IPartitionService(com.hazelcast.internal.partition.IPartitionService) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) SetUtil.immutablePartitionIdSet(com.hazelcast.internal.util.SetUtil.immutablePartitionIdSet)

Example 12 with PartitionIdSet

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

the class MapProxySupport method waitAllTrue.

private void waitAllTrue(Map<Integer, Object> results, OperationFactory operationFactory) throws InterruptedException {
    Iterator<Entry<Integer, Object>> iterator = results.entrySet().iterator();
    boolean isFinished = false;
    PartitionIdSet retrySet = new PartitionIdSet(partitionService.getPartitionCount());
    while (!isFinished) {
        while (iterator.hasNext()) {
            Entry<Integer, Object> entry = iterator.next();
            if (Boolean.TRUE.equals(entry.getValue())) {
                iterator.remove();
            } else {
                retrySet.add(entry.getKey());
            }
        }
        if (!retrySet.isEmpty()) {
            results = retryPartitions(retrySet, operationFactory);
            iterator = results.entrySet().iterator();
            TimeUnit.SECONDS.sleep(1);
            retrySet.clear();
        } else {
            isFinished = true;
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject)

Example 13 with PartitionIdSet

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

the class CacheProxy method getAll.

@Override
public Map<K, V> getAll(Set<? extends K> keys, ExpiryPolicy expiryPolicy) {
    ensureOpen();
    validateNotNull(keys);
    if (keys.isEmpty()) {
        return emptyMap();
    }
    final int keyCount = keys.size();
    final Set<Data> ks = createHashSet(keyCount);
    for (K key : keys) {
        validateNotNull(key);
        Data dataKey = serializationService.toData(key);
        ks.add(dataKey);
    }
    Map<K, V> result = createHashMap(keyCount);
    PartitionIdSet partitions = getPartitionsForKeys(ks);
    try {
        OperationFactory factory = operationProvider.createGetAllOperationFactory(ks, expiryPolicy);
        OperationService operationService = getNodeEngine().getOperationService();
        Map<Integer, Object> responses = operationService.invokeOnPartitions(getServiceName(), factory, partitions);
        for (Object response : responses.values()) {
            MapEntries mapEntries = serializationService.toObject(response);
            mapEntries.putAllToMap(serializationService, result);
        }
    } catch (Throwable e) {
        throw rethrowAllowedTypeFirst(e, CacheException.class);
    }
    return result;
}
Also used : CacheException(javax.cache.CacheException) Data(com.hazelcast.internal.serialization.Data) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapEntries(com.hazelcast.map.impl.MapEntries) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 14 with PartitionIdSet

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

the class CacheProxyLoadAllTask method run.

@Override
public void run() {
    try {
        completionListener = injectDependencies(completionListener);
        OperationService operationService = nodeEngine.getOperationService();
        OperationFactory operationFactory;
        IPartitionService partitionService = nodeEngine.getPartitionService();
        Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
        int partitionCount = partitionService.getPartitionCount();
        Map<Integer, Object> results = createHashMap(partitionCount);
        for (Map.Entry<Address, List<Integer>> memberPartitions : memberPartitionsMap.entrySet()) {
            Set<Integer> partitions = new PartitionIdSet(partitionCount, memberPartitions.getValue());
            Set<Data> ownerKeys = filterOwnerKeys(partitionService, partitions);
            operationFactory = operationProvider.createLoadAllOperationFactory(ownerKeys, replaceExistingValues);
            Map<Integer, Object> memberResults;
            memberResults = operationService.invokeOnPartitions(serviceName, operationFactory, partitions);
            results.putAll(memberResults);
        }
        validateResults(results);
        if (completionListener != null) {
            completionListener.onCompletion();
        }
    } catch (Exception e) {
        if (completionListener != null) {
            completionListener.onException(e);
        }
    } catch (Throwable t) {
        if (t instanceof OutOfMemoryError) {
            throw rethrow(t);
        } else {
            if (completionListener != null) {
                completionListener.onException(new CacheException(t));
            }
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) CacheException(javax.cache.CacheException) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Data(com.hazelcast.internal.serialization.Data) CacheException(javax.cache.CacheException) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) List(java.util.List) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 15 with PartitionIdSet

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

the class QueryEngineImplTest method runQueryOnGivenPartition.

@Test
public void runQueryOnGivenPartition() {
    Predicate predicate = Predicates.equal("this", value);
    Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(ENTRY).build();
    QueryResult result = queryEngine.execute(query, createPartitionTarget(new PartitionIdSet(271, partitionId)));
    assertEquals(1, result.size());
    assertEquals(key, toObject(((Map.Entry) result.iterator().next()).getKey()));
    assertEquals(map.get(key), toObject(((Map.Entry) result.iterator().next()).getValue()));
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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