use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class CacheProxySupport method getPartitionsForKeys.
protected PartitionIdSet getPartitionsForKeys(Set<Data> keys) {
IPartitionService partitionService = getNodeEngine().getPartitionService();
int partitions = partitionService.getPartitionCount();
PartitionIdSet partitionIds = new PartitionIdSet(partitions);
Iterator<Data> iterator = keys.iterator();
int addedPartitions = 0;
while (iterator.hasNext() && addedPartitions < partitions) {
Data key = iterator.next();
if (partitionIds.add(partitionService.getPartitionId(key))) {
addedPartitions++;
}
}
return partitionIds;
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class CacheLoadAllOperation method run.
@Override
public void run() throws Exception {
int partitionId = getPartitionId();
IPartitionService partitionService = getNodeEngine().getPartitionService();
Set<Data> filteredKeys = null;
if (keys != null) {
filteredKeys = new HashSet<Data>();
for (Data k : keys) {
if (partitionService.getPartitionId(k) == partitionId) {
filteredKeys.add(k);
}
}
}
if (filteredKeys == null || filteredKeys.isEmpty()) {
return;
}
try {
ICacheService service = getService();
cache = service.getOrCreateRecordStore(name, partitionId);
Set<Data> keysLoaded = cache.loadAll(filteredKeys, replaceExistingValues);
int loadedKeyCount = keysLoaded.size();
if (loadedKeyCount > 0) {
backupRecords = createHashMap(loadedKeyCount);
for (Data key : keysLoaded) {
CacheRecord record = cache.getRecord(key);
// So if the loaded key is evicted, don't send it to backup.
if (record != null) {
backupRecords.put(key, record);
}
}
shouldBackup = !backupRecords.isEmpty();
}
} catch (CacheException e) {
response = new CacheClearResponse(e);
}
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class CacheGetInvalidationMetaDataOperation method getOwnedPartitions.
private List<Integer> getOwnedPartitions() {
IPartitionService partitionService = getNodeEngine().getPartitionService();
Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
List<Integer> ownedPartitions = memberPartitionsMap.get(getNodeEngine().getThisAddress());
return ownedPartitions == null ? Collections.<Integer>emptyList() : ownedPartitions;
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class CardinalityEstimatorService method prepareReplicationOperation.
@Override
public Operation prepareReplicationOperation(PartitionReplicationEvent event) {
final IPartitionService partitionService = nodeEngine.getPartitionService();
final int roughSize = (int) ((containers.size() * SIZING_FUDGE_FACTOR) / partitionService.getPartitionCount());
Map<String, CardinalityEstimatorContainer> data = createHashMap(roughSize);
int partitionId = event.getPartitionId();
for (Map.Entry<String, CardinalityEstimatorContainer> containerEntry : containers.entrySet()) {
String name = containerEntry.getKey();
CardinalityEstimatorContainer container = containerEntry.getValue();
if (partitionId == getPartitionId(name) && event.getReplicaIndex() <= container.getTotalBackupCount()) {
data.put(name, containerEntry.getValue());
}
}
return data.isEmpty() ? null : new ReplicationOperation(data);
}
use of com.hazelcast.internal.partition.IPartitionService in project hazelcast by hazelcast.
the class AddPartitionLostListenerMessageTask method processInternal.
@Override
protected CompletableFuture<UUID> processInternal() {
final IPartitionService partitionService = getService(getServiceName());
final PartitionLostListener listener = event -> {
if (endpoint.isAlive()) {
ClusterService clusterService = getService(ClusterServiceImpl.SERVICE_NAME);
Address eventSource = event.getEventSource();
MemberImpl member = clusterService.getMember(eventSource);
ClientMessage eventMessage = ClientAddPartitionLostListenerCodec.encodePartitionLostEvent(event.getPartitionId(), event.getLostBackupCount(), member.getUuid());
sendClientMessage(null, eventMessage);
}
};
if (parameters) {
return newCompletedFuture(partitionService.addLocalPartitionLostListener(listener));
}
return partitionService.addPartitionLostListenerAsync(listener);
}
Aggregations