Search in sources :

Example 76 with GridCacheContext

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

the class GridDhtPartitionsExchangeFuture method updatePartitionFullMap.

/**
     * Updates partition map in all caches.
     *
     * @param msg Partitions full messages.
     */
private void updatePartitionFullMap(GridDhtPartitionsFullMessage msg) {
    cctx.versions().onExchange(msg.lastVersion().order());
    for (Map.Entry<Integer, GridDhtPartitionFullMap> entry : msg.partitions().entrySet()) {
        Integer cacheId = entry.getKey();
        Map<Integer, T2<Long, Long>> cntrMap = msg.partitionUpdateCounters(cacheId);
        GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
        if (cacheCtx != null)
            cacheCtx.topology().update(exchId, entry.getValue(), cntrMap);
        else {
            ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(AffinityTopologyVersion.NONE);
            if (oldest != null && oldest.isLocal())
                cctx.exchange().clientTopology(cacheId, this).update(exchId, entry.getValue(), cntrMap);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) T2(org.apache.ignite.internal.util.typedef.T2)

Example 77 with GridCacheContext

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

the class GridDhtPartitionsExchangeFuture method updatePartitionSingleMap.

/**
     * Updates partition map in all caches.
     *
     * @param msg Partitions single message.
     */
private void updatePartitionSingleMap(ClusterNode node, GridDhtPartitionsSingleMessage msg) {
    msgs.put(node.id(), msg);
    for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg.partitions().entrySet()) {
        Integer cacheId = entry.getKey();
        GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
        GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() : cctx.exchange().clientTopology(cacheId, this);
        top.update(exchId, entry.getValue());
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 78 with GridCacheContext

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

the class GridDhtPartitionsExchangeFuture method onAllReceived.

/**
     *
     */
private void onAllReceived() {
    try {
        assert crd.isLocal();
        if (!crd.equals(discoCache.serverNodes().get(0))) {
            for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
                if (!cacheCtx.isLocal())
                    cacheCtx.topology().beforeExchange(this, !centralizedAff);
            }
        }
        for (GridDhtPartitionsAbstractMessage msg : msgs.values()) {
            if (msg instanceof GridDhtPartitionsSingleMessage) {
                GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
                for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg0.partitions().entrySet()) {
                    Integer cacheId = entry.getKey();
                    GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
                    GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() : cctx.exchange().clientTopology(cacheId, this);
                    Map<Integer, T2<Long, Long>> cntrs = msg0.partitionUpdateCounters(cacheId);
                    if (cntrs != null)
                        top.applyUpdateCounters(cntrs);
                }
            }
        }
        if (discoEvt.type() == EVT_NODE_JOINED) {
            if (cctx.kernalContext().state().active())
                assignPartitionsStates();
        } else if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
            assert discoEvt instanceof DiscoveryCustomEvent;
            if (((DiscoveryCustomEvent) discoEvt).customMessage() instanceof DynamicCacheChangeBatch) {
                if (exchActions != null) {
                    if (exchActions.newClusterState() == ClusterState.ACTIVE)
                        assignPartitionsStates();
                    Set<String> caches = exchActions.cachesToResetLostPartitions();
                    if (!F.isEmpty(caches))
                        resetLostPartitions(caches);
                }
            }
        } else if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED)
            detectLostPartitions();
        updateLastVersion(cctx.versions().last());
        cctx.versions().onExchange(lastVer.get().order());
        if (centralizedAff) {
            IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut = cctx.affinity().initAffinityOnNodeLeft(this);
            if (!fut.isDone()) {
                fut.listen(new IgniteInClosure<IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>>>() {

                    @Override
                    public void apply(IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut) {
                        onAffinityInitialized(fut);
                    }
                });
            } else
                onAffinityInitialized(fut);
        } else {
            List<ClusterNode> nodes;
            synchronized (this) {
                srvNodes.remove(cctx.localNode());
                nodes = new ArrayList<>(srvNodes);
            }
            if (!nodes.isEmpty())
                sendAllPartitions(nodes);
            if (exchangeOnChangeGlobalState && !F.isEmpty(changeGlobalStateExceptions))
                cctx.kernalContext().state().onFullResponseMessage(changeGlobalStateExceptions);
            onDone(exchangeId().topologyVersion());
        }
    } catch (IgniteCheckedException e) {
        if (reconnectOnError(e))
            onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
        else
            onDone(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) Set(java.util.Set) HashSet(java.util.HashSet) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) T2(org.apache.ignite.internal.util.typedef.T2)

Example 79 with GridCacheContext

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

the class IgniteTxManager method removeObsolete.

/**
 * @param tx Transaction.
 */
private void removeObsolete(IgniteInternalTx tx) {
    Collection<IgniteTxEntry> entries = tx.local() ? tx.allEntries() : tx.writeEntries();
    for (IgniteTxEntry entry : entries) {
        GridCacheEntryEx cached = entry.cached();
        GridCacheContext cacheCtx = entry.context();
        if (cached == null)
            cached = cacheCtx.cache().peekEx(entry.key());
        if (cached.detached())
            continue;
        try {
            if (cached.obsolete() || cached.markObsoleteIfEmpty(tx.xidVersion()))
                cacheCtx.cache().removeEntry(cached);
            if (!tx.near() && isNearEnabled(cacheCtx)) {
                GridNearCacheAdapter near = cacheCtx.isNear() ? cacheCtx.near() : cacheCtx.dht().near();
                GridNearCacheEntry e = near.peekExx(entry.key());
                if (e != null && e.markObsoleteIfEmpty(null))
                    near.removeEntry(e);
            }
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to remove obsolete entry from cache: " + cached, e);
        }
    }
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter)

Example 80 with GridCacheContext

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

the class GridCacheJdbcBlobStoreMultithreadedSelfTest method checkOpenedClosedCount.

/**
 */
private void checkOpenedClosedCount() {
    assertEquals(GRID_CNT, Ignition.allGrids().size());
    for (Ignite ignite : Ignition.allGrids()) {
        GridCacheContext cctx = ((IgniteKernal) ignite).internalCache(DEFAULT_CACHE_NAME).context();
        CacheStore store = cctx.store().configuredStore();
        long opened = ((LongAdder) U.field(store, "opened")).sum();
        long closed = ((LongAdder) U.field(store, "closed")).sum();
        assert opened > 0;
        assert closed > 0;
        assertEquals(opened, closed);
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) LongAdder(java.util.concurrent.atomic.LongAdder) Ignite(org.apache.ignite.Ignite) CacheStore(org.apache.ignite.cache.store.CacheStore)

Aggregations

GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)147 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)37 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)22 HashMap (java.util.HashMap)21 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 Map (java.util.Map)19 UUID (java.util.UUID)18 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)18 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)16 ArrayList (java.util.ArrayList)15 IgniteException (org.apache.ignite.IgniteException)14 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)14 List (java.util.List)13 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)13 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)13 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 ConcurrentMap (java.util.concurrent.ConcurrentMap)10 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)10 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8