Search in sources :

Example 21 with IPartition

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

the class UnlockIfLeaseExpiredOperation method shouldBackup.

/**
 * This operation runs on both primary and backup
 * If it is running on backup we should not send a backup operation
 *
 * @return
 */
@Override
public boolean shouldBackup() {
    NodeEngine nodeEngine = getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    Address thisAddress = nodeEngine.getThisAddress();
    IPartition partition = partitionService.getPartition(getPartitionId());
    if (!thisAddress.equals(partition.getOwnerOrNull())) {
        return false;
    }
    return super.shouldBackup();
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address) IPartitionService(com.hazelcast.internal.partition.IPartitionService) IPartition(com.hazelcast.internal.partition.IPartition)

Example 22 with IPartition

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

the class MapPartitionLostListenerTest method test_partitionLostListenerInvoked_whenNodeCrashed.

@Test
public void test_partitionLostListenerInvoked_whenNodeCrashed() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp();
    HazelcastInstance survivingInstance = instances.get(0);
    HazelcastInstance terminatingInstance = instances.get(1);
    final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
    survivingInstance.getMap(getIthMapName(0)).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 {
            List<MapPartitionLostEvent> events = listener.getEvents();
            assertFalse(events.isEmpty());
            for (MapPartitionLostEvent event : events) {
                assertFalse(survivingPartitionIds.contains(event.getPartitionId()));
            }
        }
    });
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) List(java.util.List) 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 23 with IPartition

use of com.hazelcast.internal.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.cluster.Address) HashMap(java.util.HashMap) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) IPartition(com.hazelcast.internal.partition.IPartition)

Example 24 with IPartition

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

the class CacheBackupAccessor method get.

@Override
public V get(K key) {
    IPartition partition = getPartitionForKey(key);
    HazelcastInstance hz = getHazelcastInstance(partition);
    Node node = getNode(hz);
    SerializationService serializationService = node.getSerializationService();
    CacheService cacheService = node.getNodeEngine().getService(CacheService.SERVICE_NAME);
    String cacheNameWithPrefix = getCacheNameWithPrefix(hz, cacheName);
    int partitionId = partition.getPartitionId();
    return runOnPartitionThread(hz, new GetValueCallable(serializationService, cacheService, cacheNameWithPrefix, partitionId, key), partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) SerializationService(com.hazelcast.internal.serialization.SerializationService) IPartition(com.hazelcast.internal.partition.IPartition) CacheService(com.hazelcast.cache.impl.CacheService)

Example 25 with IPartition

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

the class MapBackupAccessor method get.

@Override
public V get(K key) {
    IPartition partition = getPartitionForKey(key);
    HazelcastInstance hz = getHazelcastInstance(partition);
    Node node = getNode(hz);
    SerializationService serializationService = node.getSerializationService();
    MapService mapService = node.getNodeEngine().getService(MapService.SERVICE_NAME);
    MapServiceContext context = mapService.getMapServiceContext();
    int partitionId = partition.getPartitionId();
    PartitionContainer partitionContainer = context.getPartitionContainer(partitionId);
    return runOnPartitionThread(hz, new GetValueCallable(serializationService, partitionContainer, key), partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) SerializationService(com.hazelcast.internal.serialization.SerializationService) MapService(com.hazelcast.map.impl.MapService) IPartition(com.hazelcast.internal.partition.IPartition) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

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