Search in sources :

Example 26 with IPartition

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

the class MapBackupAccessor method size.

@Override
public int size() {
    InternalPartitionService partitionService = getNode(cluster[0]).getPartitionService();
    IPartition[] partitions = partitionService.getPartitions();
    int count = 0;
    for (IPartition partition : partitions) {
        Address replicaAddress = partition.getReplicaAddress(replicaIndex);
        if (replicaAddress == null) {
            continue;
        }
        HazelcastInstance hz = getInstanceWithAddress(replicaAddress);
        NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
        MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
        MapServiceContext context = mapService.getMapServiceContext();
        int partitionId = partition.getPartitionId();
        PartitionContainer partitionContainer = context.getPartitionContainer(partitionId);
        count += runOnPartitionThread(hz, new SizeCallable(partitionContainer), partitionId);
    }
    return count;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MapService(com.hazelcast.map.impl.MapService) IPartition(com.hazelcast.internal.partition.IPartition) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 27 with IPartition

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

the class Accessors method getAllIndexes.

/**
 * Obtains a list of {@link Indexes} for the given map local to the node
 * associated with it.
 * <p>
 * There may be more than one indexes instance associated with a map if its
 * indexes are partitioned.
 *
 * @param map the map to obtain the indexes for.
 * @return the obtained indexes list.
 */
public static List<Indexes> getAllIndexes(IMap map) {
    MapProxyImpl mapProxy = (MapProxyImpl) map;
    String mapName = mapProxy.getName();
    NodeEngine nodeEngine = mapProxy.getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    Indexes maybeGlobalIndexes = mapContainer.getIndexes();
    if (maybeGlobalIndexes != null) {
        return Collections.singletonList(maybeGlobalIndexes);
    }
    PartitionContainer[] partitionContainers = mapServiceContext.getPartitionContainers();
    List<Indexes> allIndexes = new ArrayList<>();
    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();
        allIndexes.add(partitionIndexes);
    }
    return allIndexes;
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) IPartitionService(com.hazelcast.internal.partition.IPartitionService) ArrayList(java.util.ArrayList) Indexes(com.hazelcast.query.impl.Indexes) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer) NodeEngine(com.hazelcast.spi.impl.NodeEngine) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MapService(com.hazelcast.map.impl.MapService) IPartition(com.hazelcast.internal.partition.IPartition)

Example 28 with IPartition

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

the class HazelcastTestSupport method getPartitionId.

// ##################################
// ########## partition ID ##########
// ##################################
/**
 * Gets a partition ID owned by this particular member.
 */
public static int getPartitionId(HazelcastInstance hz) {
    warmUpPartitions(hz);
    InternalPartitionService partitionService = Accessors.getPartitionService(hz);
    for (IPartition partition : partitionService.getPartitions()) {
        if (partition.isLocal()) {
            return partition.getPartitionId();
        }
    }
    throw new RuntimeException("No local partitions are found for hz: " + hz.getName());
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) 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