use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class MapProxySupport method readBackupDataOrNull.
private Data readBackupDataOrNull(Data key) {
int partitionId = partitionService.getPartitionId(key);
IPartition partition = partitionService.getPartition(partitionId, false);
if (!partition.isOwnerOrBackup(thisAddress)) {
return null;
}
PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId);
RecordStore recordStore = partitionContainer.getExistingRecordStore(name);
if (recordStore == null) {
return null;
}
return recordStore.readBackupData(key);
}
use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class QueueService method createLocalQueueStats.
/**
* Returns the local queue statistics for the given name and partition ID. If this node is the owner for the partition,
* returned stats contain {@link LocalQueueStats#getOwnedItemCount()}, otherwise it contains
* {@link LocalQueueStats#getBackupItemCount()}.
*
* @param name the name of the queue for which the statistics are returned
* @param partitionId the partition ID for which the statistics are returned
* @return the statistics
*/
public LocalQueueStats createLocalQueueStats(String name, int partitionId) {
LocalQueueStatsImpl stats = getLocalQueueStatsImpl(name);
stats.setOwnedItemCount(0);
stats.setBackupItemCount(0);
QueueContainer container = containerMap.get(name);
if (container == null) {
return stats;
}
Address thisAddress = nodeEngine.getClusterService().getThisAddress();
IPartition partition = nodeEngine.getPartitionService().getPartition(partitionId);
Address owner = partition.getOwnerOrNull();
if (thisAddress.equals(owner)) {
stats.setOwnedItemCount(container.size());
} else if (owner != null) {
stats.setBackupItemCount(container.backupSize());
}
container.setStats(stats);
return stats;
}
use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class EvictionChecker method isOwnerOrBackup.
protected boolean isOwnerOrBackup(int partitionId) {
final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
final IPartitionService partitionService = nodeEngine.getPartitionService();
final IPartition partition = partitionService.getPartition(partitionId, false);
final Address thisAddress = nodeEngine.getThisAddress();
return partition.isOwnerOrBackup(thisAddress);
}
use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class Backup method beforeRun.
@Override
public void beforeRun() throws Exception {
NodeEngine nodeEngine = getNodeEngine();
int partitionId = getPartitionId();
InternalPartitionService partitionService = (InternalPartitionService) nodeEngine.getPartitionService();
ILogger logger = getLogger();
IPartition partition = partitionService.getPartition(partitionId);
Address owner = partition.getReplicaAddress(getReplicaIndex());
if (!nodeEngine.getThisAddress().equals(owner)) {
valid = false;
if (logger.isFinestEnabled()) {
logger.finest("Wrong target! " + toString() + " cannot be processed! Target should be: " + owner);
}
} else if (partitionService.isPartitionReplicaVersionStale(getPartitionId(), replicaVersions, getReplicaIndex())) {
valid = false;
if (logger.isFineEnabled()) {
long[] currentVersions = partitionService.getPartitionReplicaVersions(partitionId);
logger.fine("Ignoring stale backup! Current-versions: " + Arrays.toString(currentVersions) + ", Backup-versions: " + Arrays.toString(replicaVersions));
}
}
}
use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class LocalLockCleanupOperation method shouldBackup.
@Override
public boolean shouldBackup() {
final NodeEngine nodeEngine = getNodeEngine();
IPartitionService partitionService = nodeEngine.getPartitionService();
IPartition partition = partitionService.getPartition(getPartitionId());
return partition.isLocal() && Boolean.TRUE.equals(response);
}
Aggregations