Search in sources :

Example 71 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method resetLostPartitions.

/**
 * @param cacheNames Cache names.
 */
private void resetLostPartitions(Collection<String> cacheNames) {
    assert !exchCtx.mergeExchanges();
    try {
        doInParallelUninterruptibly(U.availableThreadCount(cctx.kernalContext(), GridIoPolicy.SYSTEM_POOL, 2), cctx.kernalContext().pools().getSystemExecutorService(), cctx.affinity().caches().values(), desc -> {
            if (desc.cacheConfiguration().getCacheMode() == CacheMode.LOCAL)
                return null;
            if (cacheNames.contains(desc.cacheName())) {
                CacheGroupContext grp = cctx.cache().cacheGroup(desc.groupId());
                GridDhtPartitionTopology top = grp != null ? grp.topology() : cctx.exchange().clientTopology(desc.groupId(), events().discoveryCache());
                top.resetLostPartitions(initialVersion());
            }
            return null;
        });
    } catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) IgniteException(org.apache.ignite.IgniteException) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 72 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method initTopologies.

/**
 * @throws IgniteCheckedException If failed.
 */
private void initTopologies() throws IgniteCheckedException {
    cctx.database().checkpointReadLock();
    try {
        if (crd != null) {
            for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
                if (grp.isLocal())
                    continue;
                grp.topology().beforeExchange(this, !centralizedAff && !forceAffReassignment, false);
                cctx.exchange().exchangerUpdateHeartbeat();
            }
        }
    } finally {
        cctx.database().checkpointReadUnlock();
    }
}
Also used : CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 73 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method assignPartitionsStates.

/**
 * @param cacheGroupsToResetOwners Set of cache groups which need to reset partitions state,
 *                                 null if reset partitions state for all cache groups needed
 */
private void assignPartitionsStates(Set<Integer> cacheGroupsToResetOwners) {
    Map<String, List<SupplyPartitionInfo>> supplyInfoMap = log.isInfoEnabled() ? new ConcurrentHashMap<>() : null;
    try {
        U.doInParallel(cctx.kernalContext().pools().getSystemExecutorService(), nonLocalCacheGroupDescriptors(), grpDesc -> {
            CacheGroupContext grpCtx = cctx.cache().cacheGroup(grpDesc.groupId());
            GridDhtPartitionTopology top = grpCtx != null ? grpCtx.topology() : cctx.exchange().clientTopology(grpDesc.groupId(), events().discoveryCache());
            if (CU.isPersistentCache(grpDesc.config(), cctx.gridConfig().getDataStorageConfiguration())) {
                List<SupplyPartitionInfo> list;
                if (cacheGroupsToResetOwners == null || cacheGroupsToResetOwners.contains(grpDesc.groupId()))
                    list = assignPartitionStates(top, true);
                else
                    list = assignPartitionStates(top, false);
                if (supplyInfoMap != null && !F.isEmpty(list))
                    supplyInfoMap.put(grpDesc.cacheOrGroupName(), list);
            } else if (cacheGroupsToResetOwners == null)
                assignPartitionSizes(top);
            return null;
        });
    } catch (IgniteCheckedException e) {
        throw new IgniteException("Failed to assign partition states", e);
    }
    if (!F.isEmpty(supplyInfoMap))
        printPartitionRebalancingFully(supplyInfoMap);
    timeBag.finishGlobalStage("Assign partitions states");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) IgniteException(org.apache.ignite.IgniteException) ArrayList(java.util.ArrayList) List(java.util.List) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 74 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method finalizePartitionCounters.

/**
 * Removes gaps in the local update counters. Gaps in update counters are possible on backup node when primary
 * failed to send update counter deltas to backup.
 */
private void finalizePartitionCounters() {
    // Reserve at least 2 threads for system operations.
    int parallelismLvl = U.availableThreadCount(cctx.kernalContext(), GridIoPolicy.SYSTEM_POOL, 2);
    try {
        U.<CacheGroupContext, Void>doInParallelUninterruptibly(parallelismLvl, cctx.kernalContext().pools().getSystemExecutorService(), nonLocalCacheGroups(), grp -> {
            Set<Integer> parts;
            if (exchCtx.exchangeFreeSwitch()) {
                assert !isSnapshotOperation(firstDiscoEvt) : "Not allowed for taking snapshots: " + this;
                // Previous topology to resolve failed primaries set.
                AffinityTopologyVersion topVer = sharedContext().exchange().readyAffinityVersion();
                // Failed node's primary partitions. Safe to use affinity since topology was fully rebalanced.
                parts = grp.affinity().primaryPartitions(firstDiscoEvt.eventNode().id(), topVer);
            } else
                parts = grp.topology().localPartitionMap().keySet();
            grp.topology().finalizeUpdateCounters(parts);
            return null;
        });
    } catch (IgniteCheckedException e) {
        throw new IgniteException("Failed to finalize partition counters", e);
    }
    timeBag.finishGlobalStage("Finalize update counters");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteException(org.apache.ignite.IgniteException) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 75 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method processSingleMessageOnCrdFinish.

/**
 * @param msg Single message to process.
 * @param messageAccumulator Message to store message which need to be sent after.
 */
private void processSingleMessageOnCrdFinish(GridDhtPartitionsSingleMessage msg, Map<Integer, CacheGroupAffinityMessage> messageAccumulator) {
    for (Map.Entry<Integer, GridDhtPartitionMap> e : msg.partitions().entrySet()) {
        Integer grpId = e.getKey();
        CacheGroupContext grp = cctx.cache().cacheGroup(grpId);
        GridDhtPartitionTopology top = grp != null ? grp.topology() : cctx.exchange().clientTopology(grpId, events().discoveryCache());
        CachePartitionPartialCountersMap cntrs = msg.partitionUpdateCounters(grpId, top.partitions());
        if (cntrs != null)
            top.collectUpdateCounters(cntrs);
    }
    Collection<Integer> affReq = msg.cacheGroupsAffinityRequest();
    if (affReq != null)
        CacheGroupAffinityMessage.createAffinityMessages(cctx, exchCtx.events().topologyVersion(), affReq, messageAccumulator);
}
Also used : GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)103 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)31 IgniteEx (org.apache.ignite.internal.IgniteEx)29 Map (java.util.Map)27 HashMap (java.util.HashMap)24 IgniteException (org.apache.ignite.IgniteException)22 ArrayList (java.util.ArrayList)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 Test (org.junit.Test)20 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)19 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)16 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)16 HashSet (java.util.HashSet)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)12 Set (java.util.Set)11 Collection (java.util.Collection)10