Search in sources :

Example 11 with IPartition

use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.

the class MapBackupAccessor method getRecord.

public Record getRecord(K key) {
    IPartition partition = getPartitionForKey(key);
    HazelcastInstance hz = getHazelcastInstance(partition);
    Node node = getNode(hz);
    SerializationService serializationService = node.getSerializationService();
    MapService mapService = node.getNodeEngine().getService(MapService.SERVICE_NAME);
    MapServiceContext context = mapService.getMapServiceContext();
    int partitionId = partition.getPartitionId();
    PartitionContainer partitionContainer = context.getPartitionContainer(partitionId);
    return runOnPartitionThread(hz, new GetRecordCallable(serializationService, partitionContainer, key), partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) SerializationService(com.hazelcast.internal.serialization.SerializationService) MapService(com.hazelcast.map.impl.MapService) IPartition(com.hazelcast.internal.partition.IPartition) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 12 with IPartition

use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.

the class WanPublisherMigrationTest method testMigration.

@Test
public void testMigration() {
    HazelcastInstance[] instances = factory.newInstances(getConfig());
    HazelcastInstance member1 = instances[0];
    HazelcastInstance member2 = instances[1];
    IMap<Object, Object> map = member1.getMap("dummyMap");
    for (int i = 0; i < 100; i++) {
        map.put(i, i);
    }
    int partitionsToMigrate = 0;
    for (IPartition partition : getPartitionService(member1).getPartitions()) {
        if (partition.isLocal()) {
            partitionsToMigrate++;
        }
    }
    member1.shutdown();
    assertClusterSizeEventually(1, member2);
    MigrationCountingWanPublisher publisher = getPublisher(member2);
    if (!failMigrations) {
        assertEquals(exceptionMsg("migrationStart", publisher), partitionsToMigrate, publisher.migrationStart.intValue());
        // it may happen that we have additional partition anti-entropy operations
        // that call process but don't show up as migration operations
        assertTrue("Expected at least " + partitionsToMigrate + " migration operations to be processed but was " + publisher, publisher.migrationProcess.intValue() >= partitionsToMigrate);
        assertEquals(exceptionMsg("migrationCommit", publisher), partitionsToMigrate, publisher.migrationCommit.intValue());
    } else {
        assertEquals(exceptionMsg("migrationStart", publisher), partitionsToMigrate + 1, publisher.migrationStart.intValue());
        // it may happen that we have additional partition anti-entropy operations
        // that call process but don't show up as migration operations
        assertTrue("Expected at least " + partitionsToMigrate + " migration operations to be processed but was " + publisher, publisher.migrationProcess.intValue() >= partitionsToMigrate);
        assertEquals(exceptionMsg("migrationCommit", publisher), partitionsToMigrate, publisher.migrationCommit.intValue());
        assertEquals(exceptionMsg("migrationRollback", publisher), 1, publisher.migrationRollback.intValue());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IPartition(com.hazelcast.internal.partition.IPartition) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with IPartition

use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.

the class DefaultRecordStore method isBackup.

private boolean isBackup(RecordStore recordStore) {
    int partitionId = recordStore.getPartitionId();
    IPartition partition = partitionService.getPartition(partitionId, false);
    return !partition.isLocal();
}
Also used : IPartition(com.hazelcast.internal.partition.IPartition)

Example 14 with IPartition

use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.

the class MapKeyLoader method calculateRole.

/**
 * Calculates and returns the role for the map key loader on this partition
 */
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.cluster.Address) IPartition(com.hazelcast.internal.partition.IPartition) Member(com.hazelcast.cluster.Member)

Example 15 with IPartition

use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.

the class LocalMapStatsProvider method addIndexStats.

private void addIndexStats(String mapName, LocalMapStatsImpl localMapStats) {
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    Indexes globalIndexes = mapContainer.getIndexes();
    Map<String, OnDemandIndexStats> freshStats = null;
    if (globalIndexes != null) {
        assert globalIndexes.isGlobal();
        localMapStats.setQueryCount(globalIndexes.getIndexesStats().getQueryCount());
        localMapStats.setIndexedQueryCount(globalIndexes.getIndexesStats().getIndexedQueryCount());
        freshStats = aggregateFreshIndexStats(globalIndexes.getIndexes(), null);
        finalizeFreshIndexStats(freshStats);
    } else {
        long queryCount = 0;
        long indexedQueryCount = 0;
        PartitionContainer[] partitionContainers = mapServiceContext.getPartitionContainers();
        for (PartitionContainer partitionContainer : partitionContainers) {
            IPartition partition = partitionService.getPartition(partitionContainer.getPartitionId());
            if (!partition.isLocal()) {
                continue;
            }
            Indexes partitionIndexes = partitionContainer.getIndexes().get(mapName);
            if (partitionIndexes == null) {
                continue;
            }
            assert !partitionIndexes.isGlobal();
            IndexesStats indexesStats = partitionIndexes.getIndexesStats();
            // Partitions may have different query stats due to migrations
            // (partition stats is not preserved while migrating) and/or
            // partition-specific queries, map query stats is estimated as a
            // maximum among partitions.
            queryCount = Math.max(queryCount, indexesStats.getQueryCount());
            indexedQueryCount = Math.max(indexedQueryCount, indexesStats.getIndexedQueryCount());
            freshStats = aggregateFreshIndexStats(partitionIndexes.getIndexes(), freshStats);
        }
        localMapStats.setQueryCount(queryCount);
        localMapStats.setIndexedQueryCount(indexedQueryCount);
        finalizeFreshIndexStats(freshStats);
    }
    localMapStats.updateIndexStats(freshStats);
}
Also used : OnDemandIndexStats(com.hazelcast.internal.monitor.impl.OnDemandIndexStats) IndexesStats(com.hazelcast.internal.monitor.impl.IndexesStats) Indexes(com.hazelcast.query.impl.Indexes) IPartition(com.hazelcast.internal.partition.IPartition)

Aggregations

IPartition (com.hazelcast.internal.partition.IPartition)28 Address (com.hazelcast.cluster.Address)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 Node (com.hazelcast.instance.impl.Node)7 Accessors.getNode (com.hazelcast.test.Accessors.getNode)6 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)5 IPartitionService (com.hazelcast.internal.partition.IPartitionService)4 MapService (com.hazelcast.map.impl.MapService)4 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 CacheService (com.hazelcast.cache.impl.CacheService)2 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)2 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)2