Search in sources :

Example 6 with IPartition

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

the class MultiMapService method localKeySet.

public Set<Data> localKeySet(String name) {
    Set<Data> keySet = new HashSet<>();
    for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
        IPartition partition = nodeEngine.getPartitionService().getPartition(i);
        boolean isLocalPartition = partition.isLocal();
        MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
        // we should not treat retrieving the container on backups an access
        MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(name, isLocalPartition);
        if (multiMapContainer == null) {
            continue;
        }
        if (isLocalPartition) {
            keySet.addAll(multiMapContainer.keySet());
        }
    }
    return keySet;
}
Also used : EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.internal.serialization.Data) IPartition(com.hazelcast.internal.partition.IPartition) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) HashSet(java.util.HashSet)

Example 7 with IPartition

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

the class MultiMapService method createStats.

LocalMultiMapStats createStats(String name) {
    LocalMultiMapStatsImpl stats = getLocalMultiMapStatsImpl(name);
    long ownedEntryCount = 0;
    long backupEntryCount = 0;
    long hits = 0;
    long lockedEntryCount = 0;
    long lastAccessTime = 0;
    long lastUpdateTime = 0;
    ClusterService clusterService = nodeEngine.getClusterService();
    MultiMapConfig config = nodeEngine.getConfig().findMultiMapConfig(name);
    int backupCount = config.getTotalBackupCount();
    Address thisAddress = clusterService.getThisAddress();
    for (int partitionId = 0; partitionId < nodeEngine.getPartitionService().getPartitionCount(); partitionId++) {
        IPartition partition = nodeEngine.getPartitionService().getPartition(partitionId, false);
        MultiMapPartitionContainer partitionContainer = getPartitionContainer(partitionId);
        MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(name, false);
        if (multiMapContainer == null) {
            continue;
        }
        Address owner = partition.getOwnerOrNull();
        if (owner != null) {
            if (owner.equals(thisAddress)) {
                lockedEntryCount += multiMapContainer.getLockedCount();
                lastAccessTime = max(lastAccessTime, multiMapContainer.getLastAccessTime());
                lastUpdateTime = max(lastUpdateTime, multiMapContainer.getLastUpdateTime());
                for (MultiMapValue multiMapValue : multiMapContainer.getMultiMapValues().values()) {
                    hits += multiMapValue.getHits();
                    ownedEntryCount += multiMapValue.getCollection(false).size();
                }
            } else {
                for (int j = 1; j <= backupCount; j++) {
                    // wait if the partition table is not updated yet
                    Address replicaAddress = getReplicaAddress(partition, backupCount, 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);
    stats.setBackupCount(backupCount);
    stats.setLastAccessTime(lastAccessTime);
    stats.setLastUpdateTime(lastUpdateTime);
    return stats;
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.cluster.Address) MultiMapConfig(com.hazelcast.config.MultiMapConfig) ConfigValidator.checkMultiMapConfig(com.hazelcast.internal.config.ConfigValidator.checkMultiMapConfig) LocalMultiMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalMultiMapStatsImpl) IPartition(com.hazelcast.internal.partition.IPartition) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint)

Example 8 with IPartition

use of com.hazelcast.internal.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 = createServerCachingProvider(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.cluster.Address) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.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.internal.partition.IPartition) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test)

Example 9 with IPartition

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

the class Invocation_RetryTest method getRandomPartitionId.

private static int getRandomPartitionId(HazelcastInstance hz) {
    warmUpPartitions(hz);
    InternalPartitionService partitionService = getPartitionService(hz);
    IPartition[] partitions = partitionService.getPartitions();
    Collections.shuffle(Arrays.asList(partitions));
    for (IPartition p : partitions) {
        if (p.isLocal()) {
            return p.getPartitionId();
        }
    }
    throw new RuntimeException("No local partitions are found for hz: " + hz.getName());
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) IPartition(com.hazelcast.internal.partition.IPartition)

Example 10 with IPartition

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

the class CacheBackupAccessor method size.

@Override
public int size() {
    InternalPartitionService partitionService = getNode(cluster[0]).getPartitionService();
    IPartition[] partitions = partitionService.getPartitions();
    int count = 0;
    for (IPartition partition : partitions) {
        Address replicaAddress = partition.getReplicaAddress(replicaIndex);
        if (replicaAddress == null) {
            continue;
        }
        HazelcastInstance hz = getInstanceWithAddress(replicaAddress);
        HazelcastInstanceImpl hazelcastInstanceImpl = getHazelcastInstanceImpl(hz);
        CachingProvider provider = createServerCachingProvider(hazelcastInstanceImpl);
        HazelcastCacheManager cacheManager = (HazelcastServerCacheManager) provider.getCacheManager();
        NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
        CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
        String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(cacheName);
        int partitionId = partition.getPartitionId();
        count += runOnPartitionThread(hz, new SizeCallable(cacheService, cacheNameWithPrefix, partitionId), partitionId);
    }
    return count;
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) Accessors.getHazelcastInstanceImpl(com.hazelcast.test.Accessors.getHazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) Address(com.hazelcast.cluster.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IPartition(com.hazelcast.internal.partition.IPartition) CachingProvider(javax.cache.spi.CachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CacheService(com.hazelcast.cache.impl.CacheService)

Aggregations

IPartition (com.hazelcast.internal.partition.IPartition)28 Address (com.hazelcast.cluster.Address)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 Node (com.hazelcast.instance.impl.Node)7 Accessors.getNode (com.hazelcast.test.Accessors.getNode)6 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)5 IPartitionService (com.hazelcast.internal.partition.IPartitionService)4 MapService (com.hazelcast.map.impl.MapService)4 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 CacheService (com.hazelcast.cache.impl.CacheService)2 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)2 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)2