Search in sources :

Example 16 with IPartition

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();
}
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 17 with IPartition

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

Example 18 with IPartition

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;
}
Also used : LocalMapStatsImpl(com.hazelcast.monitor.impl.LocalMapStatsImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) IPartition(com.hazelcast.spi.partition.IPartition)

Example 19 with IPartition

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

Example 20 with IPartition

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()));
            }
        }
    });
}
Also used : Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) List(java.util.List) IPartition(com.hazelcast.spi.partition.IPartition) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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