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