Search in sources :

Example 1 with GridNearSingleGetRequest

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest in project ignite by apache.

the class GridDhtAtomicCache method start.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "IfMayBeConditional", "SimplifiableIfStatement" })
@Override
public void start() throws IgniteCheckedException {
    super.start();
    CacheMetricsImpl m = new CacheMetricsImpl(ctx);
    if (ctx.dht().near() != null)
        m.delegate(ctx.dht().near().metrics0());
    metrics = m;
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetRequest.class, new CI2<UUID, GridNearGetRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearGetRequest req) {
            processNearGetRequest(nodeId, req);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetRequest.class, new CI2<UUID, GridNearSingleGetRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearSingleGetRequest req) {
            processNearSingleGetRequest(nodeId, req);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicAbstractUpdateRequest.class, new CI2<UUID, GridNearAtomicAbstractUpdateRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearAtomicAbstractUpdateRequest req) {
            processNearAtomicUpdateRequest(nodeId, req);
        }

        @Override
        public String toString() {
            return "GridNearAtomicAbstractUpdateRequest handler " + "[msgIdx=" + GridNearAtomicAbstractUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicUpdateResponse.class, new CI2<UUID, GridNearAtomicUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridNearAtomicUpdateResponse res) {
            processNearAtomicUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridNearAtomicUpdateResponse handler " + "[msgIdx=" + GridNearAtomicUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicAbstractUpdateRequest.class, new CI2<UUID, GridDhtAtomicAbstractUpdateRequest>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicAbstractUpdateRequest req) {
            processDhtAtomicUpdateRequest(nodeId, req);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicUpdateRequest handler " + "[msgIdx=" + GridDhtAtomicUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicUpdateResponse.class, new CI2<UUID, GridDhtAtomicUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicUpdateResponse res) {
            processDhtAtomicUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicUpdateResponse handler " + "[msgIdx=" + GridDhtAtomicUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicDeferredUpdateResponse.class, new CI2<UUID, GridDhtAtomicDeferredUpdateResponse>() {

        @Override
        public void apply(UUID nodeId, GridDhtAtomicDeferredUpdateResponse res) {
            processDhtAtomicDeferredUpdateResponse(nodeId, res);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicDeferredUpdateResponse handler " + "[msgIdx=" + GridDhtAtomicDeferredUpdateResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicNearResponse.class, new CI2<UUID, GridDhtAtomicNearResponse>() {

        @Override
        public void apply(UUID uuid, GridDhtAtomicNearResponse msg) {
            processDhtAtomicNearResponse(uuid, msg);
        }

        @Override
        public String toString() {
            return "GridDhtAtomicNearResponse handler " + "[msgIdx=" + GridDhtAtomicNearResponse.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicCheckUpdateRequest.class, new CI2<UUID, GridNearAtomicCheckUpdateRequest>() {

        @Override
        public void apply(UUID uuid, GridNearAtomicCheckUpdateRequest msg) {
            processCheckUpdateRequest(uuid, msg);
        }

        @Override
        public String toString() {
            return "GridNearAtomicCheckUpdateRequest handler " + "[msgIdx=" + GridNearAtomicCheckUpdateRequest.CACHE_MSG_IDX + ']';
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysRequest.class, new MessageHandler<GridDhtForceKeysRequest>() {

        @Override
        public void onMessage(ClusterNode node, GridDhtForceKeysRequest msg) {
            processForceKeysRequest(node, msg);
        }
    });
    ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysResponse.class, new MessageHandler<GridDhtForceKeysResponse>() {

        @Override
        public void onMessage(ClusterNode node, GridDhtForceKeysResponse msg) {
            processForceKeyResponse(node, msg);
        }
    });
    if (near == null) {
        ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2<UUID, GridNearGetResponse>() {

            @Override
            public void apply(UUID nodeId, GridNearGetResponse res) {
                processNearGetResponse(nodeId, res);
            }
        });
        ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetResponse.class, new CI2<UUID, GridNearSingleGetResponse>() {

            @Override
            public void apply(UUID nodeId, GridNearSingleGetResponse res) {
                processNearSingleGetResponse(nodeId, res);
            }
        });
    }
}
Also used : GridDhtForceKeysResponse(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) GridDhtForceKeysRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest) UUID(java.util.UUID) GridNearGetResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetResponse) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridNearSingleGetResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse) GridNearSingleGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest)

Example 2 with GridNearSingleGetRequest

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest in project ignite by apache.

the class GridDhtTransactionalCacheAdapter method start.

/** {@inheritDoc} */
@Override
public void start() throws IgniteCheckedException {
    super.start();
    preldr = new GridDhtPreloader(ctx);
    preldr.start();
    ctx.io().addHandler(ctx.cacheId(), GridNearGetRequest.class, new CI2<UUID, GridNearGetRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearGetRequest req) {
            processNearGetRequest(nodeId, req);
        }
    });
    ctx.io().addHandler(ctx.cacheId(), GridNearSingleGetRequest.class, new CI2<UUID, GridNearSingleGetRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearSingleGetRequest req) {
            processNearSingleGetRequest(nodeId, req);
        }
    });
    ctx.io().addHandler(ctx.cacheId(), GridNearLockRequest.class, new CI2<UUID, GridNearLockRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearLockRequest req) {
            processNearLockRequest(nodeId, req);
        }
    });
    ctx.io().addHandler(ctx.cacheId(), GridDhtLockRequest.class, new CI2<UUID, GridDhtLockRequest>() {

        @Override
        public void apply(UUID nodeId, GridDhtLockRequest req) {
            processDhtLockRequest(nodeId, req);
        }
    });
    ctx.io().addHandler(ctx.cacheId(), GridDhtLockResponse.class, new CI2<UUID, GridDhtLockResponse>() {

        @Override
        public void apply(UUID nodeId, GridDhtLockResponse req) {
            processDhtLockResponse(nodeId, req);
        }
    });
    ctx.io().addHandler(ctx.cacheId(), GridNearUnlockRequest.class, new CI2<UUID, GridNearUnlockRequest>() {

        @Override
        public void apply(UUID nodeId, GridNearUnlockRequest req) {
            processNearUnlockRequest(nodeId, req);
        }
    });
    ctx.io().addHandler(ctx.cacheId(), GridDhtUnlockRequest.class, new CI2<UUID, GridDhtUnlockRequest>() {

        @Override
        public void apply(UUID nodeId, GridDhtUnlockRequest req) {
            processDhtUnlockRequest(nodeId, req);
        }
    });
}
Also used : GridNearLockRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest) GridNearUnlockRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearUnlockRequest) GridDhtPreloader(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader) GridNearSingleGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest) UUID(java.util.UUID)

Example 3 with GridNearSingleGetRequest

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest in project ignite by apache.

the class GridCachePartitionedGetSelfTest method prepare.

/**
 * Puts value to primary node and registers listener
 * that sets {@link #received} flag to {@code true}
 * if {@link GridNearGetRequest} was received on primary node.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings("deprecation")
private void prepare() throws Exception {
    for (int i = 0; i < GRID_CNT; i++) {
        Ignite g = grid(i);
        if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimary(grid(i).localNode(), KEY)) {
            info("Primary node: " + g.cluster().localNode().id());
            // Put value.
            g.cache(DEFAULT_CACHE_NAME).put(KEY, VAL);
            // Register listener.
            ((IgniteKernal) g).context().io().addMessageListener(TOPIC_CACHE, new GridMessageListener() {

                @Override
                public void onMessage(UUID nodeId, Object msg, byte plc) {
                    info("Received message from node [nodeId=" + nodeId + ", msg=" + msg + ']');
                    if (msg instanceof GridNearSingleGetRequest) {
                        info("Setting flag: " + System.identityHashCode(received));
                        received.set(true);
                    }
                }
            });
            break;
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridNearSingleGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

Example 4 with GridNearSingleGetRequest

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest in project ignite by apache.

the class GridPartitionedSingleGetFuture method map.

/**
 * @param topVer Topology version.
 */
@SuppressWarnings("unchecked")
private void map(final AffinityTopologyVersion topVer) {
    ClusterNode node = mapKeyToNode(topVer);
    if (node == null) {
        assert isDone() : this;
        return;
    }
    if (isDone())
        return;
    if (node.isLocal()) {
        final GridDhtFuture<GridCacheEntryInfo> fut = cctx.dht().getDhtSingleAsync(node.id(), -1, key, false, readThrough, topVer, subjId, taskName == null ? 0 : taskName.hashCode(), expiryPlc, skipVals, recovery);
        final Collection<Integer> invalidParts = fut.invalidPartitions();
        if (!F.isEmpty(invalidParts)) {
            AffinityTopologyVersion updTopVer = cctx.shared().exchange().readyAffinityVersion();
            assert updTopVer.compareTo(topVer) > 0 : "Got invalid partitions for local node but topology " + "version did not change [topVer=" + topVer + ", updTopVer=" + updTopVer + ", invalidParts=" + invalidParts + ']';
            // Remap recursively.
            map(updTopVer);
        } else {
            fut.listen(new CI1<IgniteInternalFuture<GridCacheEntryInfo>>() {

                @Override
                public void apply(IgniteInternalFuture<GridCacheEntryInfo> fut) {
                    try {
                        GridCacheEntryInfo info = fut.get();
                        setResult(info);
                    } catch (Exception e) {
                        U.error(log, "Failed to get values from dht cache [fut=" + fut + "]", e);
                        onDone(e);
                    }
                }
            });
        }
    } else {
        synchronized (this) {
            assert this.node == null;
            this.topVer = topVer;
            this.node = node;
        }
        if (!trackable) {
            trackable = true;
            cctx.mvcc().addFuture(this, futId);
        }
        boolean needVer = this.needVer;
        final BackupPostProcessingClosure postClos = CU.createBackupPostProcessingClosure(topVer, log, cctx, key, expiryPlc, readThrough, skipVals);
        if (postClos != null) {
            // Need version to correctly store value.
            needVer = true;
            postProcessingClos = postClos;
        }
        GridCacheMessage req = new GridNearSingleGetRequest(cctx.cacheId(), futId.localId(), key, readThrough, topVer, subjId, taskName == null ? 0 : taskName.hashCode(), expiryPlc != null ? expiryPlc.forCreate() : -1L, expiryPlc != null ? expiryPlc.forAccess() : -1L, skipVals, /*add reader*/
        false, needVer, cctx.deploymentEnabled(), recovery);
        try {
            cctx.io().send(node, req, cctx.ioPolicy());
        } catch (IgniteCheckedException e) {
            if (e instanceof ClusterTopologyCheckedException)
                onNodeLeft(node.id());
            else
                onDone(e);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) BackupPostProcessingClosure(org.apache.ignite.internal.processors.cache.GridCacheUtils.BackupPostProcessingClosure) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNearSingleGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

GridNearSingleGetRequest (org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest)4 UUID (java.util.UUID)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 GridNearGetRequest (org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest)2 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)1 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 CacheMetricsImpl (org.apache.ignite.internal.processors.cache.CacheMetricsImpl)1 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)1 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)1 GridCacheMessage (org.apache.ignite.internal.processors.cache.GridCacheMessage)1 BackupPostProcessingClosure (org.apache.ignite.internal.processors.cache.GridCacheUtils.BackupPostProcessingClosure)1 GridDhtForceKeysRequest (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest)1 GridDhtForceKeysResponse (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse)1 GridDhtPreloader (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader)1