Search in sources :

Example 21 with IPartition

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

the class HazelcastTestSupport method getPartitionId.

// ##################################
// ########## partition id ##########
// ##################################
/**
     * Gets a partition id owned by this particular member.
     */
public static int getPartitionId(HazelcastInstance hz) {
    warmUpPartitions(hz);
    InternalPartitionService partitionService = getPartitionService(hz);
    for (IPartition partition : partitionService.getPartitions()) {
        if (partition.isLocal()) {
            return partition.getPartitionId();
        }
    }
    throw new RuntimeException("No local partitions are found for hz: " + hz.getName());
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) IPartition(com.hazelcast.spi.partition.IPartition)

Example 22 with IPartition

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

the class AbstractPartitionLostListenerTest method getMinReplicaIndicesByPartitionId.

protected final Map<Integer, Integer> getMinReplicaIndicesByPartitionId(List<HazelcastInstance> instances) {
    Map<Integer, Integer> survivingPartitions = new HashMap<Integer, Integer>();
    for (HazelcastInstance instance : instances) {
        Node survivingNode = getNode(instance);
        Address survivingNodeAddress = survivingNode.getThisAddress();
        for (IPartition partition : survivingNode.getPartitionService().getPartitions()) {
            if (partition.isOwnerOrBackup(survivingNodeAddress)) {
                for (int replicaIndex = 0; replicaIndex < getNodeCount(); replicaIndex++) {
                    if (survivingNodeAddress.equals(partition.getReplicaAddress(replicaIndex))) {
                        Integer replicaIndexOfOtherInstance = survivingPartitions.get(partition.getPartitionId());
                        if (replicaIndexOfOtherInstance != null) {
                            survivingPartitions.put(partition.getPartitionId(), Math.min(replicaIndex, replicaIndexOfOtherInstance));
                        } else {
                            survivingPartitions.put(partition.getPartitionId(), replicaIndex);
                        }
                        break;
                    }
                }
            }
        }
    }
    return survivingPartitions;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) Node(com.hazelcast.instance.Node) 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