Search in sources :

Example 1 with IntSet

use of org.apache.ignite.internal.util.collection.IntSet in project ignite by apache.

the class CacheMetricsImpl method getEntriesStat.

/**
 * Calculates entries count/partitions count metrics using one iteration over local partitions for all metrics
 */
public EntriesStatMetrics getEntriesStat() {
    int owningPartCnt = 0;
    int movingPartCnt = 0;
    long offHeapEntriesCnt = 0L;
    long offHeapPrimaryEntriesCnt = 0L;
    long offHeapBackupEntriesCnt = 0L;
    long heapEntriesCnt = 0L;
    int size = 0;
    long sizeLong = 0L;
    boolean isEmpty;
    try {
        AffinityTopologyVersion topVer = cctx.affinity().affinityTopologyVersion();
        if (AffinityTopologyVersion.NONE.equals(topVer))
            return unknownEntriesStat();
        final GridCacheAdapter<?, ?> cache = cctx.cache();
        if (cache != null) {
            offHeapEntriesCnt = cache.offHeapEntriesCount();
            size = cache.localSize(null);
            sizeLong = cache.localSizeLong(null);
        }
        if (cctx.isLocal()) {
            if (cache != null) {
                offHeapPrimaryEntriesCnt = offHeapEntriesCnt;
                heapEntriesCnt = cache.sizeLong();
            }
        } else {
            IntSet primaries = ImmutableIntSet.wrap(cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer));
            IntSet backups = ImmutableIntSet.wrap(cctx.affinity().backupPartitions(cctx.localNodeId(), topVer));
            if (cctx.isNear() && cache != null)
                heapEntriesCnt = cache.nearSize();
            for (GridDhtLocalPartition part : cctx.topology().currentLocalPartitions()) {
                // Partitions count.
                GridDhtPartitionState partState = part.state();
                if (partState == GridDhtPartitionState.OWNING)
                    owningPartCnt++;
                if (partState == GridDhtPartitionState.MOVING)
                    movingPartCnt++;
                // Offheap entries count
                if (cache == null)
                    continue;
                long cacheSize = part.dataStore().cacheSize(cctx.cacheId());
                if (primaries.contains(part.id()))
                    offHeapPrimaryEntriesCnt += cacheSize;
                else if (backups.contains(part.id()))
                    offHeapBackupEntriesCnt += cacheSize;
                heapEntriesCnt += part.publicSize(cctx.cacheId());
            }
        }
    } catch (Exception e) {
        return unknownEntriesStat();
    }
    isEmpty = (offHeapEntriesCnt == 0);
    EntriesStatMetrics stat = new EntriesStatMetrics();
    stat.offHeapEntriesCount(offHeapEntriesCnt);
    stat.offHeapPrimaryEntriesCount(offHeapPrimaryEntriesCnt);
    stat.offHeapBackupEntriesCount(offHeapBackupEntriesCnt);
    stat.heapEntriesCount(heapEntriesCnt);
    stat.size(size);
    stat.cacheSize(sizeLong);
    stat.keySize(size);
    stat.isEmpty(isEmpty);
    stat.totalPartitionsCount(owningPartCnt + movingPartCnt);
    stat.rebalancingPartitionsCount(movingPartCnt);
    return stat;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IntSet(org.apache.ignite.internal.util.collection.IntSet) ImmutableIntSet(org.apache.ignite.internal.util.collection.ImmutableIntSet) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Example 2 with IntSet

use of org.apache.ignite.internal.util.collection.IntSet in project ignite by apache.

the class LinkStorage method contains.

/**
 * {@inheritDoc}
 */
@Override
public boolean contains(CacheAwareLink cacheAwareLink) {
    long link = cacheAwareLink.link;
    long pageId = pageId(link);
    Map<Integer, Map<Byte, IntSet>> map = store.get(cacheAwareLink.cacheId);
    if (map != null) {
        Map<Byte, IntSet> innerMap = map.get(partId(pageId));
        if (innerMap != null) {
            IntSet set = innerMap.get((byte) itemId(link));
            if (set != null)
                return set.contains(pageIndex(pageId));
        }
    }
    return false;
}
Also used : BitSetIntSet(org.apache.ignite.internal.util.collection.BitSetIntSet) IntSet(org.apache.ignite.internal.util.collection.IntSet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with IntSet

use of org.apache.ignite.internal.util.collection.IntSet in project ignite by apache.

the class IgniteCacheOffheapManagerImpl method cacheData.

/**
 * @param primary Primary data flag.
 * @param backup Backup data flag.
 * @param topVer Topology version.
 * @return Data stores iterator.
 */
private Iterator<CacheDataStore> cacheData(boolean primary, boolean backup, AffinityTopologyVersion topVer) {
    assert primary || backup;
    if (grp.isLocal())
        return singletonIterator(locCacheDataStore);
    IgnitePredicate<GridDhtLocalPartition> filter;
    if (primary && backup)
        filter = F.alwaysTrue();
    else {
        IntSet parts = ImmutableIntSet.wrap(primary ? grp.affinity().primaryPartitions(ctx.localNodeId(), topVer) : grp.affinity().backupPartitions(ctx.localNodeId(), topVer));
        filter = part -> parts.contains(part.id());
    }
    return cacheDataStores(filter).iterator();
}
Also used : IntSet(org.apache.ignite.internal.util.collection.IntSet) ImmutableIntSet(org.apache.ignite.internal.util.collection.ImmutableIntSet) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Aggregations

IntSet (org.apache.ignite.internal.util.collection.IntSet)3 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)2 ImmutableIntSet (org.apache.ignite.internal.util.collection.ImmutableIntSet)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState)1 BitSetIntSet (org.apache.ignite.internal.util.collection.BitSetIntSet)1