Search in sources :

Example 1 with GridDhtForceKeysRequest

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest 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 GridDhtForceKeysRequest

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest in project ignite by apache.

the class CacheMvccBackupsAbstractTest method doTestRebalanceNodeAdd.

/**
 * @throws Exception If failed.
 */
private void doTestRebalanceNodeAdd(boolean delayRebalance) throws Exception {
    testSpi = true;
    final Ignite node1 = startGrid(0);
    final IgniteCache<Object, Object> cache = node1.createCache(cacheConfiguration(cacheMode(), FULL_SYNC, 1, 16).setIndexedTypes(Integer.class, Integer.class));
    try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        SqlFieldsQuery qry = new SqlFieldsQuery("INSERT INTO Integer (_key, _val) values " + "(1,1),(2,2),(3,3),(4,4),(5,5)");
        cache.query(qry).getAll();
        tx.commit();
    }
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(node1);
    // Check for a force key request.
    spi.closure(new IgniteBiInClosure<ClusterNode, Message>() {

        @Override
        public void apply(ClusterNode node, Message msg) {
            if (delayRebalance && msg instanceof GridDhtPartitionSupplyMessage)
                doSleep(500);
            if (msg instanceof GridDhtForceKeysResponse)
                fail("Force key request");
        }
    });
    final Ignite node2 = startGrid(1);
    TestRecordingCommunicationSpi.spi(node2).closure(new IgniteBiInClosure<ClusterNode, Message>() {

        @Override
        public void apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtForceKeysRequest)
                fail("Force key request");
        }
    });
    IgniteCache<Object, Object> cache2 = node2.cache(DEFAULT_CACHE_NAME);
    try (Transaction tx = node2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        SqlFieldsQuery qry = new SqlFieldsQuery("DELETE FROM Integer WHERE _key IN " + "(1,2,3,4,5)");
        cache2.query(qry).getAll();
        tx.commit();
    }
    awaitPartitionMapExchange();
    doSleep(2000);
    stopGrid(1);
    try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        SqlFieldsQuery qry = new SqlFieldsQuery("INSERT INTO Integer (_key, _val) values " + "(1,1),(2,2),(3,3),(4,4),(5,5)");
        cache.query(qry).getAll();
        tx.commit();
    }
    doSleep(1000);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtForceKeysResponse(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) GridDhtForceKeysRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest) Ignite(org.apache.ignite.Ignite) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 3 with GridDhtForceKeysRequest

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest in project ignite by apache.

the class CacheLateAffinityAssignmentTest method testNoForceKeysRequests.

/**
 * @throws Exception If failed.
 */
@Test
public void testNoForceKeysRequests() throws Exception {
    cacheC = new IgniteClosure<String, CacheConfiguration[]>() {

        @Override
        public CacheConfiguration[] apply(String s) {
            return null;
        }
    };
    final AtomicBoolean fail = new AtomicBoolean();
    spiC = new IgniteClosure<String, TestRecordingCommunicationSpi>() {

        @Override
        public TestRecordingCommunicationSpi apply(String s) {
            TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
            spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

                @Override
                public boolean apply(ClusterNode node, Message msg) {
                    if (msg instanceof GridDhtForceKeysRequest || msg instanceof GridDhtForceKeysResponse) {
                        fail.set(true);
                        U.dumpStack(log, "Unexpected message: " + msg);
                    }
                    return false;
                }
            });
            return spi;
        }
    };
    final int SRVS = 3;
    for (int i = 0; i < SRVS; i++) startGrid(i);
    startClientGrid(SRVS);
    final List<CacheConfiguration> ccfgs = new ArrayList<>();
    ccfgs.add(cacheConfiguration("tc1", TRANSACTIONAL, 0));
    ccfgs.add(cacheConfiguration("tc2", TRANSACTIONAL, 1));
    ccfgs.add(cacheConfiguration("tc3", TRANSACTIONAL, 2));
    for (CacheConfiguration ccfg : ccfgs) ignite(0).createCache(ccfg);
    final int NODES = SRVS + 1;
    final AtomicInteger nodeIdx = new AtomicInteger();
    final long stopTime = System.currentTimeMillis() + 60_000;
    IgniteInternalFuture<?> updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            int idx = nodeIdx.getAndIncrement();
            Ignite node = grid(idx);
            List<IgniteCache<Object, Object>> caches = new ArrayList<>();
            for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
            while (!fail.get() && System.currentTimeMillis() < stopTime) {
                for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
            }
            return null;
        }
    }, NODES, "update-thread");
    IgniteInternalFuture<?> srvRestartFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            while (!fail.get() && System.currentTimeMillis() < stopTime) {
                Ignite node = startGrid(NODES);
                List<IgniteCache<Object, Object>> caches = new ArrayList<>();
                for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
                for (int i = 0; i < 2; i++) {
                    for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
                }
                U.sleep(500);
                stopGrid(NODES);
                U.sleep(500);
            }
            return null;
        }
    }, "srv-restart");
    srvRestartFut.get();
    updateFut.get();
    assertFalse("Unexpected messages.", fail.get());
}
Also used : GridDhtForceKeysResponse(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) ArrayList(java.util.ArrayList) GridDhtForceKeysRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest) Ignite(org.apache.ignite.Ignite) List(java.util.List) ArrayList(java.util.ArrayList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IgniteCache(org.apache.ignite.IgniteCache) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)3 GridDhtForceKeysRequest (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest)3 GridDhtForceKeysResponse (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Ignite (org.apache.ignite.Ignite)2 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)2 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)2 Message (org.apache.ignite.plugin.extensions.communication.Message)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteException (org.apache.ignite.IgniteException)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)1 CacheAffinityChangeMessage (org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage)1 CacheMetricsImpl (org.apache.ignite.internal.processors.cache.CacheMetricsImpl)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1