Search in sources :

Example 11 with IPartition

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);
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) IPartition(com.hazelcast.spi.partition.IPartition)

Example 12 with IPartition

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;
}
Also used : Address(com.hazelcast.nio.Address) LocalQueueStatsImpl(com.hazelcast.monitor.impl.LocalQueueStatsImpl) IPartition(com.hazelcast.spi.partition.IPartition)

Example 13 with IPartition

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);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) IPartitionService(com.hazelcast.spi.partition.IPartitionService) IPartition(com.hazelcast.spi.partition.IPartition)

Example 14 with IPartition

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));
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) ILogger(com.hazelcast.logging.ILogger) IPartition(com.hazelcast.spi.partition.IPartition)

Example 15 with IPartition

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);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) IPartitionService(com.hazelcast.spi.partition.IPartitionService) IPartition(com.hazelcast.spi.partition.IPartition)

Aggregations

IPartition (com.hazelcast.spi.partition.IPartition)22 Address (com.hazelcast.nio.Address)13 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)6 NodeEngine (com.hazelcast.spi.NodeEngine)6 IPartitionService (com.hazelcast.spi.partition.IPartitionService)5 Node (com.hazelcast.instance.Node)4 HashSet (java.util.HashSet)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HashMap (java.util.HashMap)3 List (java.util.List)3 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)2 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)2 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)2 AssertTask (com.hazelcast.test.AssertTask)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1