Search in sources :

Example 6 with IPartition

use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.

the class MultiMapService method localKeySet.

public Set<Data> localKeySet(String name) {
    Set<Data> keySet = new HashSet<Data>();
    for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
        IPartition partition = nodeEngine.getPartitionService().getPartition(i);
        MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
        MultiMapContainer multiMapContainer = partitionContainer.getCollectionContainer(name);
        if (multiMapContainer == null) {
            continue;
        }
        if (partition.isLocal()) {
            keySet.addAll(multiMapContainer.keySet());
        }
    }
    getLocalMultiMapStatsImpl(name).incrementOtherOperations();
    return keySet;
}
Also used : EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.nio.serialization.Data) IPartition(com.hazelcast.spi.partition.IPartition) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint) HashSet(java.util.HashSet)

Example 7 with IPartition

use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.

the class MultiMapService method createStats.

public LocalMultiMapStats createStats(String name) {
    LocalMultiMapStatsImpl stats = getLocalMultiMapStatsImpl(name);
    long ownedEntryCount = 0;
    long backupEntryCount = 0;
    long hits = 0;
    long lockedEntryCount = 0;
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
    Address thisAddress = clusterService.getThisAddress();
    for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
        IPartition partition = nodeEngine.getPartitionService().getPartition(i);
        MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
        MultiMapContainer multiMapContainer = partitionContainer.getCollectionContainer(name);
        if (multiMapContainer == null) {
            continue;
        }
        Address owner = partition.getOwnerOrNull();
        if (owner != null) {
            if (owner.equals(thisAddress)) {
                lockedEntryCount += multiMapContainer.getLockedCount();
                for (MultiMapValue multiMapValue : multiMapContainer.getMultiMapValues().values()) {
                    hits += multiMapValue.getHits();
                    ownedEntryCount += multiMapValue.getCollection(false).size();
                }
            } else {
                int backupCount = multiMapContainer.getConfig().getTotalBackupCount();
                for (int j = 1; j <= backupCount; j++) {
                    Address replicaAddress = partition.getReplicaAddress(j);
                    int memberSize = nodeEngine.getClusterService().getMembers().size();
                    int tryCount = REPLICA_ADDRESS_TRY_COUNT;
                    // wait if the partition table is not updated yet
                    while (memberSize > backupCount && replicaAddress == null && tryCount-- > 0) {
                        try {
                            Thread.sleep(REPLICA_ADDRESS_SLEEP_WAIT_MILLIS);
                        } catch (InterruptedException e) {
                            throw ExceptionUtil.rethrow(e);
                        }
                        replicaAddress = partition.getReplicaAddress(j);
                    }
                    if (replicaAddress != null && replicaAddress.equals(thisAddress)) {
                        for (MultiMapValue multiMapValue : multiMapContainer.getMultiMapValues().values()) {
                            backupEntryCount += multiMapValue.getCollection(false).size();
                        }
                    }
                }
            }
        }
    }
    stats.setOwnedEntryCount(ownedEntryCount);
    stats.setBackupEntryCount(backupEntryCount);
    stats.setHits(hits);
    stats.setLockedEntryCount(lockedEntryCount);
    return stats;
}
Also used : Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) LocalMultiMapStatsImpl(com.hazelcast.monitor.impl.LocalMultiMapStatsImpl) IPartition(com.hazelcast.spi.partition.IPartition) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 8 with IPartition

use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.

the class CachePartitionLostListenerTest method test_partitionLostListenerInvoked_whenNodeCrashed.

@Test
public void test_partitionLostListenerInvoked_whenNodeCrashed() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(2);
    HazelcastInstance survivingInstance = instances.get(0);
    HazelcastInstance terminatingInstance = instances.get(1);
    HazelcastServerCachingProvider cachingProvider = createCachingProvider(survivingInstance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    config.setBackupCount(0);
    Cache<Integer, String> cache = cacheManager.createCache(getIthCacheName(0), config);
    ICache iCache = cache.unwrap(ICache.class);
    final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
    iCache.addPartitionLostListener(listener);
    final Set<Integer> survivingPartitionIds = new HashSet<Integer>();
    Node survivingNode = getNode(survivingInstance);
    Address survivingAddress = survivingNode.getThisAddress();
    for (IPartition partition : survivingNode.getPartitionService().getPartitions()) {
        if (survivingAddress.equals(partition.getReplicaAddress(0))) {
            survivingPartitionIds.add(partition.getPartitionId());
        }
    }
    terminatingInstance.getLifecycleService().terminate();
    waitAllForSafeState(survivingInstance);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final List<CachePartitionLostEvent> events = listener.getEvents();
            assertFalse(events.isEmpty());
            for (CachePartitionLostEvent event : events) {
                assertFalse(survivingPartitionIds.contains(event.getPartitionId()));
            }
        }
    });
    cacheManager.destroyCache(getIthCacheName(0));
    cacheManager.close();
    cachingProvider.close();
}
Also used : Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheConfig(com.hazelcast.config.CacheConfig) IPartition(com.hazelcast.spi.partition.IPartition) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with IPartition

use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.

the class GetPartitionsMessageTask method call.

protected Object call() {
    InternalPartitionService service = getService(InternalPartitionService.SERVICE_NAME);
    service.firstArrangement();
    Map<Address, List<Integer>> partitionsMap = new HashMap<Address, List<Integer>>();
    for (IPartition partition : service.getPartitions()) {
        Address owner = partition.getOwnerOrNull();
        if (owner == null) {
            partitionsMap.clear();
            return ClientGetPartitionsCodec.encodeResponse(partitionsMap.entrySet());
        }
        List<Integer> indexes = partitionsMap.get(owner);
        if (indexes == null) {
            indexes = new LinkedList<Integer>();
            partitionsMap.put(owner, indexes);
        }
        indexes.add(partition.getPartitionId());
    }
    return ClientGetPartitionsCodec.encodeResponse(partitionsMap.entrySet());
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) IPartition(com.hazelcast.spi.partition.IPartition)

Example 10 with IPartition

use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.

the class SemaphoreDetachMemberOperation method shouldBackup.

@Override
public boolean shouldBackup() {
    final NodeEngine nodeEngine = getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    IPartition partition = partitionService.getPartition(getPartitionId());
    return partition.isLocal() && Boolean.TRUE.equals(response);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) IPartitionService(com.hazelcast.spi.partition.IPartitionService) IPartition(com.hazelcast.spi.partition.IPartition)

Aggregations

IPartition (com.hazelcast.spi.partition.IPartition)22 Address (com.hazelcast.nio.Address)13 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)6 NodeEngine (com.hazelcast.spi.NodeEngine)6 IPartitionService (com.hazelcast.spi.partition.IPartitionService)5 Node (com.hazelcast.instance.Node)4 HashSet (java.util.HashSet)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HashMap (java.util.HashMap)3 List (java.util.List)3 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)2 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)2 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)2 AssertTask (com.hazelcast.test.AssertTask)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1