Search in sources :

Example 21 with GridCacheEntryInfo

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

the class GridDhtCacheAdapter method processNearSingleGetRequest.

/**
     * @param nodeId Node ID.
     * @param req Get request.
     */
protected void processNearSingleGetRequest(final UUID nodeId, final GridNearSingleGetRequest req) {
    assert ctx.affinityNode();
    final CacheExpiryPolicy expiryPlc = CacheExpiryPolicy.fromRemote(req.createTtl(), req.accessTtl());
    IgniteInternalFuture<GridCacheEntryInfo> fut = getDhtSingleAsync(nodeId, req.messageId(), req.key(), req.addReader(), req.readThrough(), req.topologyVersion(), req.subjectId(), req.taskNameHash(), expiryPlc, req.skipValues(), req.recovery());
    fut.listen(new CI1<IgniteInternalFuture<GridCacheEntryInfo>>() {

        @Override
        public void apply(IgniteInternalFuture<GridCacheEntryInfo> f) {
            GridNearSingleGetResponse res;
            GridDhtFuture<GridCacheEntryInfo> fut = (GridDhtFuture<GridCacheEntryInfo>) f;
            try {
                GridCacheEntryInfo info = fut.get();
                if (F.isEmpty(fut.invalidPartitions())) {
                    Message res0 = null;
                    if (info != null) {
                        if (req.needEntryInfo()) {
                            info.key(null);
                            res0 = info;
                        } else if (req.needVersion())
                            res0 = new CacheVersionedValue(info.value(), info.version());
                        else
                            res0 = info.value();
                    }
                    res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), req.topologyVersion(), res0, false, req.addDeploymentInfo());
                    if (info != null && req.skipValues())
                        res.setContainsValue();
                } else {
                    AffinityTopologyVersion topVer = ctx.shared().exchange().readyAffinityVersion();
                    assert topVer.compareTo(req.topologyVersion()) >= 0 : "Wrong ready topology version for " + "invalid partitions response [topVer=" + topVer + ", req=" + req + ']';
                    res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), topVer, null, true, req.addDeploymentInfo());
                }
            } catch (NodeStoppingException ignored) {
                return;
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed processing get request: " + req, e);
                res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), req.topologyVersion(), null, false, req.addDeploymentInfo());
                res.error(e);
            }
            try {
                ctx.io().send(nodeId, res, ctx.ioPolicy());
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed to send get response to node (is node still alive?) [nodeId=" + nodeId + ",req=" + req + ", res=" + res + ']', e);
            }
            sendTtlUpdateRequest(expiryPlc);
        }
    });
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) CacheVersionedValue(org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue) Message(org.apache.ignite.plugin.extensions.communication.Message) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridNearSingleGetResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)

Example 22 with GridCacheEntryInfo

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

the class IgniteTxHandler method startRemoteTx.

/**
     * @param nodeId Node ID.
     * @param req Request.
     * @param res Response.
     * @return Remote transaction.
     * @throws IgniteCheckedException If failed.
     */
@Nullable
GridDhtTxRemote startRemoteTx(UUID nodeId, GridDhtTxPrepareRequest req, GridDhtTxPrepareResponse res) throws IgniteCheckedException {
    if (!F.isEmpty(req.writes())) {
        GridDhtTxRemote tx = ctx.tm().tx(req.version());
        if (tx == null) {
            boolean single = req.last() && req.writes().size() == 1;
            tx = new GridDhtTxRemote(ctx, req.nearNodeId(), req.futureId(), nodeId, req.topologyVersion(), req.version(), null, req.system(), req.policy(), req.concurrency(), req.isolation(), req.isInvalidate(), req.timeout(), req.writes() != null ? Math.max(req.writes().size(), req.txSize()) : req.txSize(), req.nearXidVersion(), req.transactionNodes(), req.subjectId(), req.taskNameHash(), single);
            tx.writeVersion(req.writeVersion());
            tx = ctx.tm().onCreated(null, tx);
            if (tx == null || !ctx.tm().onStarted(tx)) {
                if (log.isDebugEnabled())
                    log.debug("Attempt to start a completed transaction (will ignore): " + tx);
                return null;
            }
            if (ctx.discovery().node(nodeId) == null) {
                tx.state(ROLLING_BACK);
                tx.state(ROLLED_BACK);
                ctx.tm().uncommitTx(tx);
                return null;
            }
        } else {
            tx.writeVersion(req.writeVersion());
            tx.transactionNodes(req.transactionNodes());
        }
        if (!tx.isSystemInvalidate()) {
            int idx = 0;
            for (IgniteTxEntry entry : req.writes()) {
                GridCacheContext cacheCtx = entry.context();
                int part = cacheCtx.affinity().partition(entry.key());
                GridDhtLocalPartition locPart = cacheCtx.topology().localPartition(part, req.topologyVersion(), false);
                if (locPart != null && locPart.reserve()) {
                    try {
                        tx.addWrite(entry, ctx.deploy().globalLoader());
                        if (isNearEnabled(cacheCtx) && req.invalidateNearEntry(idx))
                            invalidateNearEntry(cacheCtx, entry.key(), req.version());
                        if (req.needPreloadKey(idx)) {
                            GridCacheEntryEx cached = entry.cached();
                            if (cached == null)
                                cached = cacheCtx.cache().entryEx(entry.key(), req.topologyVersion());
                            GridCacheEntryInfo info = cached.info();
                            if (info != null && !info.isNew() && !info.isDeleted())
                                res.addPreloadEntry(info);
                        }
                        if (cacheCtx.readThroughConfigured() && !entry.skipStore() && entry.op() == TRANSFORM && entry.oldValueOnPrimary() && !entry.hasValue()) {
                            while (true) {
                                try {
                                    GridCacheEntryEx cached = entry.cached();
                                    if (cached == null) {
                                        cached = cacheCtx.cache().entryEx(entry.key(), req.topologyVersion());
                                        entry.cached(cached);
                                    }
                                    CacheObject val = cached.innerGet(/*ver*/
                                    null, tx, /*readThrough*/
                                    false, /*updateMetrics*/
                                    false, /*evt*/
                                    false, tx.subjectId(), /*transformClo*/
                                    null, tx.resolveTaskName(), /*expiryPlc*/
                                    null, /*keepBinary*/
                                    true);
                                    if (val == null)
                                        val = cacheCtx.toCacheObject(cacheCtx.store().load(null, entry.key()));
                                    if (val != null)
                                        entry.readValue(val);
                                    break;
                                } catch (GridCacheEntryRemovedException ignored) {
                                    if (log.isDebugEnabled())
                                        log.debug("Got entry removed exception, will retry: " + entry.txKey());
                                    entry.cached(cacheCtx.cache().entryEx(entry.key(), req.topologyVersion()));
                                }
                            }
                        }
                    } catch (GridDhtInvalidPartitionException e) {
                        tx.addInvalidPartition(cacheCtx, e.partition());
                        tx.clearEntry(entry.txKey());
                    } finally {
                        locPart.release();
                    }
                } else
                    tx.addInvalidPartition(cacheCtx, part);
                idx++;
            }
        }
        // Prepare prior to reordering, so the pending locks added
        // in prepare phase will get properly ordered as well.
        tx.prepareRemoteTx();
        if (req.last()) {
            assert !F.isEmpty(req.transactionNodes()) : "Received last prepare request with empty transaction nodes: " + req;
            tx.state(PREPARED);
        }
        res.invalidPartitionsByCacheId(tx.invalidPartitions());
        if (tx.empty() && req.last()) {
            tx.rollbackRemoteTx();
            return null;
        }
        return tx;
    }
    return null;
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) GridDhtTxRemote(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)22 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)8 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)6 Collection (java.util.Collection)5 Map (java.util.Map)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)4 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)4 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)4 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)4 ArrayList (java.util.ArrayList)3 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)3 GridCacheMessage (org.apache.ignite.internal.processors.cache.GridCacheMessage)3 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3