Search in sources :

Example 21 with GridCacheContext

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

the class GridDhtPartitionsExchangeFuture method updateTopologies.

/**
     * @param crd Coordinator flag.
     * @throws IgniteCheckedException If failed.
     */
private void updateTopologies(boolean crd) throws IgniteCheckedException {
    for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
        if (cacheCtx.isLocal())
            continue;
        GridClientPartitionTopology clientTop = cctx.exchange().clearClientTopology(cacheCtx.cacheId());
        long updSeq = clientTop == null ? -1 : clientTop.lastUpdateSequence();
        GridDhtPartitionTopology top = cacheCtx.topology();
        if (crd) {
            boolean updateTop = exchId.topologyVersion().equals(cacheCtx.startTopologyVersion());
            if (updateTop && clientTop != null)
                top.update(exchId, clientTop.partitionMap(true), clientTop.updateCounters(false));
        }
        top.updateTopologyVersion(exchId, this, updSeq, stopping(cacheCtx.cacheId()));
    }
    for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) top.updateTopologyVersion(exchId, this, -1, stopping(top.cacheId()));
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridClientPartitionTopology)

Example 22 with GridCacheContext

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

the class GridDhtPartitionsExchangeFuture method clientOnlyExchange.

/**
     * @throws IgniteCheckedException If failed.
     */
private void clientOnlyExchange() throws IgniteCheckedException {
    clientOnlyExchange = true;
    if (crd != null) {
        if (crd.isLocal()) {
            for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
                boolean updateTop = !cacheCtx.isLocal() && exchId.topologyVersion().equals(cacheCtx.startTopologyVersion());
                if (updateTop) {
                    for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) {
                        if (top.cacheId() == cacheCtx.cacheId()) {
                            cacheCtx.topology().update(exchId, top.partitionMap(true), top.updateCounters(false));
                            break;
                        }
                    }
                }
            }
        } else {
            if (!centralizedAff)
                sendLocalPartitions(crd);
            initDone();
            return;
        }
    } else {
        if (centralizedAff) {
            // Last server node failed.
            for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
                GridAffinityAssignmentCache aff = cacheCtx.affinity().affinityCache();
                aff.initialize(topologyVersion(), aff.idealAssignment());
            }
        }
    }
    onDone(topologyVersion());
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridClientPartitionTopology)

Example 23 with GridCacheContext

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

the class GridDhtPartitionsExchangeFuture method distributedExchange.

/**
     * @throws IgniteCheckedException If failed.
     */
private void distributedExchange() throws IgniteCheckedException {
    assert crd != null;
    assert !cctx.kernalContext().clientNode();
    for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
        if (cacheCtx.isLocal())
            continue;
        cacheCtx.preloader().onTopologyChanged(this);
    }
    waitPartitionRelease();
    boolean topChanged = discoEvt.type() != EVT_DISCOVERY_CUSTOM_EVT || affChangeMsg != null;
    for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
        if (cacheCtx.isLocal() || stopping(cacheCtx.cacheId()))
            continue;
        if (topChanged) {
            // Partition release future is done so we can flush the write-behind store.
            cacheCtx.store().forceFlush();
        }
        cacheCtx.topology().beforeExchange(this, !centralizedAff);
    }
    cctx.database().beforeExchange(this);
    // If a backup request, synchronously wait for backup start.
    if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
        DiscoveryCustomMessage customMessage = ((DiscoveryCustomEvent) discoEvt).customMessage();
        if (customMessage instanceof StartFullSnapshotAckDiscoveryMessage) {
            StartFullSnapshotAckDiscoveryMessage backupMsg = (StartFullSnapshotAckDiscoveryMessage) customMessage;
            if (!cctx.localNode().isClient() && !cctx.localNode().isDaemon()) {
                ClusterNode node = cctx.discovery().node(backupMsg.initiatorNodeId());
                assert node != null;
                IgniteInternalFuture fut = cctx.database().startLocalSnapshotCreation(backupMsg, node, backupMsg.message());
                if (fut != null)
                    fut.get();
            }
        }
    }
    if (crd.isLocal()) {
        if (remaining.isEmpty())
            onAllReceived();
    } else
        sendPartitions(crd);
    initDone();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) StartFullSnapshotAckDiscoveryMessage(org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent)

Example 24 with GridCacheContext

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

the class GridDhtPartitionsExchangeFuture method onDone.

/** {@inheritDoc} */
@Override
public boolean onDone(@Nullable AffinityTopologyVersion res, @Nullable Throwable err) {
    boolean realExchange = !dummy && !forcePreload;
    if (err == null && realExchange && !cctx.kernalContext().clientNode() && (serverNodeDiscoveryEvent() || affChangeMsg != null)) {
        for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
            if (!cacheCtx.affinityNode() || cacheCtx.isLocal())
                continue;
            cacheCtx.continuousQueries().flushBackupQueue(exchId.topologyVersion());
        }
    }
    if (err == null && realExchange) {
        for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
            if (cacheCtx.isLocal())
                continue;
            try {
                if (centralizedAff)
                    cacheCtx.topology().initPartitions(this);
            } catch (IgniteInterruptedCheckedException e) {
                U.error(log, "Failed to initialize partitions.", e);
            }
            GridCacheContext drCacheCtx = cacheCtx.isNear() ? cacheCtx.near().dht().context() : cacheCtx;
            if (drCacheCtx.isDrEnabled()) {
                try {
                    drCacheCtx.dr().onExchange(topologyVersion(), exchId.isLeft());
                } catch (IgniteCheckedException e) {
                    U.error(log, "Failed to notify DR: " + e, e);
                }
            }
        }
        if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED || discoEvt.type() == EVT_NODE_JOINED)
            detectLostPartitions();
        Map<Integer, CacheValidation> m = new HashMap<>(cctx.cacheContexts().size());
        for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
            Collection<Integer> lostParts = cacheCtx.isLocal() ? Collections.<Integer>emptyList() : cacheCtx.topology().lostPartitions();
            boolean valid = true;
            if (cacheCtx.config().getTopologyValidator() != null && !CU.isSystemCache(cacheCtx.name()))
                valid = cacheCtx.config().getTopologyValidator().validate(discoEvt.topologyNodes());
            m.put(cacheCtx.cacheId(), new CacheValidation(valid, lostParts));
        }
        cacheValidRes = m;
    }
    cctx.cache().onExchangeDone(exchId.topologyVersion(), exchActions, err, false);
    cctx.exchange().onExchangeDone(this, err);
    if (exchActions != null && err == null)
        exchActions.completeRequestFutures(cctx);
    if (exchangeOnChangeGlobalState && err == null)
        cctx.kernalContext().state().onExchangeDone();
    if (super.onDone(res, err) && realExchange) {
        if (log.isDebugEnabled())
            log.debug("Completed partition exchange [localNode=" + cctx.localNodeId() + ", exchange= " + this + ", durationFromInit=" + (U.currentTimeMillis() - initTs) + ']');
        initFut.onDone(err == null);
        if (exchId.isLeft()) {
            for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.config().getAffinity().removeNode(exchId.nodeId());
        }
        exchActions = null;
        if (discoEvt instanceof DiscoveryCustomEvent)
            ((DiscoveryCustomEvent) discoEvt).customMessage(null);
        cctx.exchange().lastFinishedFuture(this);
        return true;
    }
    return dummy;
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashMap(java.util.HashMap) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent)

Example 25 with GridCacheContext

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

the class GridNearGetResponse method prepareMarshal.

/** {@inheritDoc}
     * @param ctx*/
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    if (entries != null) {
        for (GridCacheEntryInfo info : entries) info.marshal(cctx);
    }
    if (err != null && errBytes == null)
        errBytes = U.marshal(ctx, err);
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext)

Aggregations

GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)121 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)20 ClusterNode (org.apache.ignite.cluster.ClusterNode)18 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)15 UUID (java.util.UUID)14 HashMap (java.util.HashMap)13 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)13 Map (java.util.Map)12 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)12 ArrayList (java.util.ArrayList)11 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)11 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)10 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)10 List (java.util.List)9 IgniteException (org.apache.ignite.IgniteException)8 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)8 Ignite (org.apache.ignite.Ignite)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7