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();
}
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()));
}
}
});
}
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;
}
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);
}
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);
}
Aggregations