Search in sources :

Example 16 with GridDhtLocalPartition

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

the class LoadAllWarmUpStrategy method loadDataInfo.

/**
 * Calculation of cache groups, partitions and count of pages that can load
 * into data region. Calculation starts and includes an index partition for
 * each group.
 *
 * @param region Data region.
 * @return Loadable groups and partitions.
 * @throws IgniteCheckedException – if faild.
 */
protected Map<CacheGroupContext, List<LoadPartition>> loadDataInfo(DataRegion region) throws IgniteCheckedException {
    // Get cache groups of data region.
    List<CacheGroupContext> regionGrps = grpCtxSup.get().stream().filter(grpCtx -> region.equals(grpCtx.dataRegion())).collect(toList());
    long availableLoadPageCnt = availableLoadPageCount(region);
    // Computing groups, partitions, and pages to load into data region.
    Map<CacheGroupContext, List<LoadPartition>> loadableGrps = new LinkedHashMap<>();
    for (int i = 0; i < regionGrps.size() && availableLoadPageCnt > 0; i++) {
        CacheGroupContext grp = regionGrps.get(i);
        // Index partition in priority.
        List<GridDhtLocalPartition> locParts = grp.topology().localPartitions();
        for (int j = -1; j < locParts.size() && availableLoadPageCnt > 0; j++) {
            int p = j == -1 ? INDEX_PARTITION : locParts.get(j).id();
            long partPageCnt = grp.shared().pageStore().pages(grp.groupId(), p);
            if (partPageCnt > 0) {
                long pageCnt = (availableLoadPageCnt - partPageCnt) >= 0 ? partPageCnt : availableLoadPageCnt;
                availableLoadPageCnt -= pageCnt;
                loadableGrps.computeIfAbsent(grp, grpCtx -> new ArrayList<>()).add(new LoadPartition(p, pageCnt));
            }
        }
    }
    return loadableGrps;
}
Also used : DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteLogger(org.apache.ignite.IgniteLogger) Supplier(java.util.function.Supplier) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) ArrayList(java.util.ArrayList) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) LinkedHashMap(java.util.LinkedHashMap) LoadAllWarmUpConfiguration(org.apache.ignite.configuration.LoadAllWarmUpConfiguration) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) S(org.apache.ignite.internal.util.typedef.internal.S) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with GridDhtLocalPartition

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

the class SchemaIndexCacheVisitorImpl method visit.

/**
 * {@inheritDoc}
 */
@Override
public void visit(SchemaIndexCacheVisitorClosure clo) {
    assert nonNull(clo);
    List<GridDhtLocalPartition> locParts = cctx.topology().localPartitions();
    if (locParts.isEmpty()) {
        buildIdxFut.onDone();
        return;
    }
    cctx.group().metrics().addIndexBuildCountPartitionsLeft(locParts.size());
    cctx.cache().metrics0().resetIndexRebuildKeyProcessed();
    beforeExecute();
    AtomicInteger partsCnt = new AtomicInteger(locParts.size());
    AtomicBoolean stop = new AtomicBoolean();
    // To avoid a race between clearing pageMemory (on a cache stop ex. deactivation)
    // and rebuilding indexes, which can lead to a fail of the node.
    SchemaIndexCacheCompoundFuture buildIdxCompoundFut = new SchemaIndexCacheCompoundFuture();
    for (GridDhtLocalPartition locPart : locParts) {
        GridWorkerFuture<SchemaIndexCacheStat> workerFut = new GridWorkerFuture<>();
        GridWorker worker = new SchemaIndexCachePartitionWorker(cctx, locPart, stop, cancelTok, clo, workerFut, partsCnt);
        workerFut.setWorker(worker);
        buildIdxCompoundFut.add(workerFut);
        cctx.kernalContext().pools().buildIndexExecutorService().execute(worker);
    }
    buildIdxCompoundFut.listen(fut -> {
        Throwable err = fut.error();
        if (isNull(err) && collectStat && log.isInfoEnabled()) {
            try {
                GridCompoundFuture<SchemaIndexCacheStat, SchemaIndexCacheStat> compoundFut = (GridCompoundFuture<SchemaIndexCacheStat, SchemaIndexCacheStat>) fut;
                SchemaIndexCacheStat resStat = new SchemaIndexCacheStat();
                compoundFut.futures().stream().map(IgniteInternalFuture::result).filter(Objects::nonNull).forEach(resStat::accumulate);
                log.info(indexStatStr(resStat));
            } catch (Exception e) {
                log.error("Error when trying to print index build/rebuild statistics [cacheName=" + cctx.cache().name() + ", grpName=" + cctx.group().name() + "]", e);
            }
        }
        buildIdxFut.onDone(err);
    });
    buildIdxCompoundFut.markInitialized();
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridWorkerFuture(org.apache.ignite.internal.util.worker.GridWorkerFuture) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Example 18 with GridDhtLocalPartition

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

the class GridDhtGetSingleFuture method map.

/**
 * @param key Key.
 * @return {@code True} if mapped.
 */
private boolean map(KeyCacheObject key, boolean forceKeys) {
    try {
        int keyPart = cctx.affinity().partition(key);
        if (cctx.mvccEnabled()) {
            boolean noOwners = cctx.topology().owners(keyPart, topVer).isEmpty();
            // request with no results and therefore forceKeys flag may be set to true here.
            if (noOwners)
                forceKeys = true;
        }
        GridDhtLocalPartition part = topVer.topologyVersion() > 0 ? cache().topology().localPartition(keyPart, topVer, true) : cache().topology().localPartition(keyPart);
        if (part == null)
            return false;
        assert this.part == -1;
        // By reserving, we make sure that partition won't be unloaded while processed.
        if (part.reserve()) {
            if (forceKeys || (part.state() == OWNING || part.state() == LOST)) {
                this.part = part.id();
                return true;
            } else {
                part.release();
                return false;
            }
        } else
            return false;
    } catch (GridDhtInvalidPartitionException ex) {
        return false;
    }
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Example 19 with GridDhtLocalPartition

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

the class GridDhtCacheAdapter method localEntriesIteratorEx.

/**
 * @param primary If {@code true} includes primary entries.
 * @param backup If {@code true} includes backup entries.
 * @param topVer Specified affinity topology version.
 * @return Local entries iterator.
 */
private Iterator<? extends GridCacheEntryEx> localEntriesIteratorEx(final boolean primary, final boolean backup, final AffinityTopologyVersion topVer) {
    assert primary || backup;
    if (primary && backup)
        return entries().iterator();
    else {
        final Iterator<GridDhtLocalPartition> partIt = topology().currentLocalPartitions().iterator();
        return new Iterator<GridCacheMapEntry>() {

            private GridCacheMapEntry next;

            private Iterator<GridCacheMapEntry> curIt;

            {
                advance();
            }

            @Override
            public boolean hasNext() {
                return next != null;
            }

            @Override
            public GridCacheMapEntry next() {
                if (next == null)
                    throw new NoSuchElementException();
                GridCacheMapEntry e = next;
                advance();
                return e;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }

            private void advance() {
                next = null;
                do {
                    if (curIt == null) {
                        while (partIt.hasNext()) {
                            GridDhtLocalPartition part = partIt.next();
                            if (primary == part.primary(topVer)) {
                                curIt = part.entries(ctx.cacheId()).iterator();
                                break;
                            }
                        }
                    }
                    if (curIt != null) {
                        if (curIt.hasNext()) {
                            next = curIt.next();
                            break;
                        } else
                            curIt = null;
                    }
                } while (partIt.hasNext());
            }
        };
    }
}
Also used : Iterator(java.util.Iterator) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) NoSuchElementException(java.util.NoSuchElementException)

Example 20 with GridDhtLocalPartition

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

the class GridDhtCacheAdapter method primarySizeLong.

/**
 * {@inheritDoc}
 */
@Override
public long primarySizeLong() {
    long sum = 0;
    AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    for (GridDhtLocalPartition p : topology().currentLocalPartitions()) {
        if (p.primary(topVer))
            sum += p.dataStore().cacheSize(ctx.cacheId());
    }
    return sum;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Aggregations

GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)95 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)19 IgniteEx (org.apache.ignite.internal.IgniteEx)19 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)19 ArrayList (java.util.ArrayList)18 Map (java.util.Map)18 Test (org.junit.Test)18 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)15 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)13 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)13 Ignite (org.apache.ignite.Ignite)12 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 IgniteException (org.apache.ignite.IgniteException)11