Search in sources :

Example 1 with CacheVersionedValue

use of org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue 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)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)1 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)1 CacheVersionedValue (org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue)1 GridNearSingleGetResponse (org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse)1 Message (org.apache.ignite.plugin.extensions.communication.Message)1