Search in sources :

Example 16 with IPartition

use of com.hazelcast.internal.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 (int i = 0; i < partitionContainers.length; i++) {
        PartitionContainer partitionContainer = partitionContainers[i];
        Collection<RecordStore> allRecordStores = partitionContainer.getAllRecordStores();
        for (RecordStore recordStore : allRecordStores) {
            if (!isStatsCalculationEnabledFor(recordStore)) {
                continue;
            }
            IPartition partition = partitionService.getPartition(partitionContainer.getPartitionId(), false);
            if (partition.isLocal()) {
                addStatsOfPrimaryReplica(recordStore, getOrCreateOnDemandStats(statsPerMap, recordStore));
            } else {
                addStatsOfBackupReplica(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);
        addIndexStats(mapName, existingStats);
        addStructureStats(mapName, onDemand);
        LocalMapStatsImpl updatedStats = onDemand.updateAndGet(existingStats);
        entry.setValue(updatedStats);
    }
    addStatsOfNoDataIncludedMaps(statsPerMap);
    return statsPerMap;
}
Also used : LocalMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalMapStatsImpl) HashMap(java.util.HashMap) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) DistributedObject(com.hazelcast.core.DistributedObject) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) IPartition(com.hazelcast.internal.partition.IPartition)

Example 17 with IPartition

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

the class LocalMapStatsProvider method updateMapOnDemandStats.

private void updateMapOnDemandStats(String mapName, LocalMapOnDemandCalculatedStats onDemandStats) {
    PartitionContainer[] partitionContainers = mapServiceContext.getPartitionContainers();
    for (PartitionContainer partitionContainer : partitionContainers) {
        IPartition partition = partitionService.getPartition(partitionContainer.getPartitionId());
        RecordStore existingRecordStore = partitionContainer.getExistingRecordStore(mapName);
        if (existingRecordStore == null) {
            continue;
        }
        if (partition.isLocal()) {
            addStatsOfPrimaryReplica(existingRecordStore, onDemandStats);
        } else {
            addStatsOfBackupReplica(existingRecordStore, onDemandStats);
        }
    }
    addStructureStats(mapName, onDemandStats);
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) IPartition(com.hazelcast.internal.partition.IPartition)

Example 18 with IPartition

use of com.hazelcast.internal.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.internal.partition.IPartition)

Example 19 with IPartition

use of com.hazelcast.internal.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 = partitionService.getPartition(partitionId, false);
    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.cluster.Address) LocalQueueStatsImpl(com.hazelcast.internal.monitor.impl.LocalQueueStatsImpl) IPartition(com.hazelcast.internal.partition.IPartition)

Example 20 with IPartition

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

the class TimedMemberStateFactory method createMemberState.

private void createMemberState(MemberStateImpl memberState, Collection<StatisticsAwareService> services) {
    Node node = instance.node;
    final Collection<Client> clients = instance.node.clientEngine.getClients();
    final Set<ClientEndPointDTO> serializableClientEndPoints = createHashSet(clients.size());
    for (Client client : clients) {
        serializableClientEndPoints.add(new ClientEndPointDTO(client));
    }
    memberState.setClients(serializableClientEndPoints);
    memberState.setName(instance.getName());
    memberState.setUuid(node.getThisUuid());
    if (instance.getConfig().getCPSubsystemConfig().getCPMemberCount() == 0) {
        memberState.setCpMemberUuid(null);
    } else {
        CPMember localCPMember = instance.getCPSubsystem().getLocalCPMember();
        memberState.setCpMemberUuid(localCPMember != null ? localCPMember.getUuid() : null);
    }
    Address thisAddress = node.getThisAddress();
    memberState.setAddress(thisAddress.getHost() + ":" + thisAddress.getPort());
    memberState.setEndpoints(node.getLocalMember().getAddressMap());
    MemberPartitionStateImpl memberPartitionState = (MemberPartitionStateImpl) memberState.getMemberPartitionState();
    InternalPartitionService partitionService = node.getPartitionService();
    IPartition[] partitions = partitionService.getPartitions();
    List<Integer> partitionList = memberPartitionState.getPartitions();
    for (IPartition partition : partitions) {
        if (partition.isLocal()) {
            partitionList.add(partition.getPartitionId());
        }
    }
    memberPartitionState.setMemberStateSafe(memberStateSafe);
    memberState.setOperationStats(getOperationStats());
    createMemState(memberState, services);
    createNodeState(memberState);
    createHotRestartState(memberState);
    createClusterHotRestartStatus(memberState);
    memberState.setClientStats(getClientAttributes(node.getClientEngine().getClientStatistics()));
}
Also used : Address(com.hazelcast.cluster.Address) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.impl.Node) CPMember(com.hazelcast.cp.CPMember) MemberPartitionStateImpl(com.hazelcast.internal.monitor.impl.MemberPartitionStateImpl) Client(com.hazelcast.client.Client) 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