use of com.hazelcast.spi.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.spi.partition.IPartition in project hazelcast by hazelcast.
the class MapKeyLoader method calculateRole.
private Role calculateRole() {
boolean isPartitionOwner = partitionService.isPartitionOwner(partitionId);
boolean isMapNamePartition = partitionId == mapNamePartition;
boolean isMapNamePartitionFirstReplica = false;
if (hasBackup && isMapNamePartition) {
IPartition partition = partitionService.getPartition(partitionId);
Address firstReplicaAddress = partition.getReplicaAddress(1);
Member member = clusterService.getMember(firstReplicaAddress);
if (member != null) {
isMapNamePartitionFirstReplica = member.localMember();
}
}
return assignRole(isPartitionOwner, isMapNamePartition, isMapNamePartitionFirstReplica);
}
use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class LocalMapStatsProvider method createAllLocalMapStats.
public Map<String, LocalMapStats> createAllLocalMapStats() {
Map statsPerMap = new HashMap();
PartitionContainer[] partitionContainers = mapServiceContext.getPartitionContainers();
for (PartitionContainer partitionContainer : partitionContainers) {
IPartition partition = partitionService.getPartition(partitionContainer.getPartitionId());
Collection<RecordStore> allRecordStores = partitionContainer.getAllRecordStores();
for (RecordStore recordStore : allRecordStores) {
if (!isStatsCalculationEnabledFor(recordStore)) {
continue;
}
if (partition.isLocal()) {
addPrimaryStatsOf(recordStore, getOrCreateOnDemandStats(statsPerMap, recordStore));
} else {
addReplicaStatsOf(recordStore, getOrCreateOnDemandStats(statsPerMap, recordStore));
}
}
}
// reuse same HashMap to return calculated LocalMapStats.
for (Object object : statsPerMap.entrySet()) {
Map.Entry entry = (Map.Entry) object;
String mapName = ((String) entry.getKey());
LocalMapStatsImpl existingStats = getLocalMapStatsImpl(mapName);
LocalMapOnDemandCalculatedStats onDemand = ((LocalMapOnDemandCalculatedStats) entry.getValue());
addNearCacheStats(mapName, existingStats, onDemand);
LocalMapStatsImpl updatedStats = onDemand.updateAndGet(existingStats);
entry.setValue(updatedStats);
}
addStatsOfNoDataIncludedMaps(statsPerMap);
return statsPerMap;
}
use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class TestPartitionUtils method collectOwnedReplicaVersions.
private static void collectOwnedReplicaVersions(Node node, Map<Integer, long[]> replicaVersions) throws InterruptedException {
InternalPartitionService partitionService = node.getPartitionService();
Address nodeAddress = node.getThisAddress();
for (IPartition partition : partitionService.getPartitions()) {
if (nodeAddress.equals(partition.getOwnerOrNull())) {
int partitionId = partition.getPartitionId();
replicaVersions.put(partitionId, getReplicaVersions(node, partitionId));
}
}
}
use of com.hazelcast.spi.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()));
}
}
});
}
Aggregations