Search in sources :

Example 16 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.

the class GridDhtPartitionDemander method createDemandMessage.

/**
     * @param old Old message.
     * @param parts Partitions to demand.
     * @return New demand message.
     */
private GridDhtPartitionDemandMessage createDemandMessage(GridDhtPartitionDemandMessage old, Collection<Integer> parts) {
    Map<Integer, Long> partCntrs = null;
    for (Integer part : parts) {
        try {
            if (cctx.shared().database().persistenceEnabled()) {
                if (partCntrs == null)
                    partCntrs = new HashMap<>(parts.size(), 1.0f);
                GridDhtLocalPartition p = cctx.topology().localPartition(part, old.topologyVersion(), false);
                partCntrs.put(part, p.initialUpdateCounter());
            }
        } catch (GridDhtInvalidPartitionException ignore) {
        // Skip this partition.
        }
    }
    return new GridDhtPartitionDemandMessage(old, parts, partCntrs);
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) HashMap(java.util.HashMap) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)

Example 17 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.

the class IgniteCacheOffheapManagerImpl method read.

/** {@inheritDoc} */
@Nullable
@Override
public CacheDataRow read(KeyCacheObject key) throws IgniteCheckedException {
    CacheDataRow row;
    if (cctx.isLocal())
        row = locCacheDataStore.find(key);
    else {
        GridDhtLocalPartition part = cctx.topology().localPartition(cctx.affinity().partition(key), null, false);
        row = part != null ? dataStore(part).find(key) : null;
    }
    assert row == null || row.value() != null : row;
    return row;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.

the class GridDistributedCacheAdapter method localSizeLong.

/** {@inheritDoc} */
@Override
public long localSizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException {
    PeekModes modes = parsePeekModes(peekModes, true);
    long size = 0;
    if (modes.near)
        size += nearSize();
    // Swap and offheap are disabled for near cache.
    if (modes.primary || modes.backup) {
        AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
        IgniteCacheOffheapManager offheap = ctx.offheap();
        if (modes.offheap)
            size += offheap.entriesCount(modes.primary, modes.backup, topVer);
        else if (modes.heap) {
            for (GridDhtLocalPartition locPart : ctx.topology().currentLocalPartitions()) {
                if ((modes.primary && locPart.primary(topVer)) || (modes.backup && locPart.backup(topVer)))
                    size += locPart.publicSize();
            }
        }
    }
    return size;
}
Also used : IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)

Example 19 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.

the class IgniteCacheLockPartitionOnAffinityRunTest method getOrganizationCountFromPartitionMap.

/**
     * @param ignite Ignite.
     * @param orgId Organization id.
     * @return Count of found Person object with specified orgId
     * @throws Exception If failed.
     */
private static int getOrganizationCountFromPartitionMap(final IgniteEx ignite, int orgId) throws Exception {
    int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId);
    GridCacheAdapter<?, ?> cacheAdapterOrg = ignite.context().cache().internalCache(Organization.class.getSimpleName());
    GridDhtLocalPartition pOrgs = cacheAdapterOrg.context().topology().localPartition(part, AffinityTopologyVersion.NONE, false);
    int cnt = 0;
    GridCursor<? extends CacheDataRow> c = pOrgs.dataStore().cursor();
    CacheObjectContext ctx = cacheAdapterOrg.context().cacheObjectContext();
    while (c.next()) {
        CacheDataRow e = c.get();
        Integer k = e.key().value(ctx, false);
        Organization org = e.value().value(ctx, false);
        if (org != null && org.getId() == orgId)
            ++cnt;
    }
    return cnt;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)

Example 20 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.

the class IgniteCacheLockPartitionOnAffinityRunTest method getPersonsCountFromPartitionMap.

/**
     * @param ignite Ignite.
     * @param orgId Organization id.
     * @return Count of found Person object with specified orgId
     * @throws Exception If failed.
     */
private static int getPersonsCountFromPartitionMap(final IgniteEx ignite, int orgId) throws Exception {
    int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId);
    GridCacheAdapter<?, ?> cacheAdapterPers = ignite.context().cache().internalCache(Person.class.getSimpleName());
    GridDhtLocalPartition pPers = cacheAdapterPers.context().topology().localPartition(part, AffinityTopologyVersion.NONE, false);
    int cnt = 0;
    GridCursor<? extends CacheDataRow> c = pPers.dataStore().cursor();
    CacheObjectContext ctx = cacheAdapterPers.context().cacheObjectContext();
    while (c.next()) {
        CacheDataRow e = c.get();
        Person.Key k = e.key().value(ctx, false);
        Person p = e.value().value(ctx, false);
        if (p != null && p.getOrgId() == orgId && k.orgId == orgId)
            ++cnt;
    }
    return cnt;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)

Aggregations

GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)25 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology)6 CacheDataRow (org.apache.ignite.internal.processors.cache.database.CacheDataRow)5 Map (java.util.Map)4 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 Ignite (org.apache.ignite.Ignite)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)3 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)3 T2 (org.apache.ignite.internal.util.typedef.T2)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2