Search in sources :

Example 6 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class IgniteCacheClientMultiNodeUpdateTopologyLockTest method testPessimisticTx.

/**
     * @throws Exception If failed.
     */
public void testPessimisticTx() throws Exception {
    startGrids(3);
    client = true;
    Ignite clientNode = startGrid(3);
    client = false;
    IgniteCache<Integer, Integer> cache = clientNode.createCache(cacheConfiguration(0, FULL_SYNC));
    awaitPartitionMapExchange();
    Integer key1 = movingKeysAfterJoin(ignite(1), TEST_CACHE, 1).get(0);
    Integer key2 = movingKeysAfterJoin(ignite(2), TEST_CACHE, 1).get(0);
    log.info("Start tx [key1=" + key1 + ", key2=" + key2 + ']');
    IgniteInternalFuture<?> startFut;
    TestRecordingCommunicationSpi spi2 = TestRecordingCommunicationSpi.spi(ignite(2));
    final TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(clientNode);
    final UUID node0Id = ignite(0).cluster().localNode().id();
    final UUID node2Id = ignite(2).cluster().localNode().id();
    spi2.record(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (!node0Id.equals(node.id()))
                return false;
            return (msg instanceof GridDhtPartitionsSingleMessage) && ((GridDhtPartitionsSingleMessage) msg).exchangeId() != null;
        }
    });
    clientSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(final ClusterNode node, final Message msg) {
            if (!node2Id.equals(node.id()))
                return false;
            if (msg instanceof GridNearTxFinishRequest) {
                log.info("Delay message [msg=" + msg + ']');
                GridTestUtils.runAsync(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(5000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        log.info("Send delayed message [msg=" + msg + ']');
                        clientSpi.stopBlock(true);
                    }
                });
                return true;
            }
            return false;
        }
    });
    try (Transaction tx = clientNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        cache.put(key1, 1);
        startFut = GridTestUtils.runAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                startGrid(4);
                return null;
            }
        }, "start-thread");
        spi2.waitForRecorded();
        U.sleep(5);
        cache.put(key2, 2);
        log.info("Commit tx");
        tx.commit();
    }
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
    startFut.get();
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
    awaitPartitionMapExchange();
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) Callable(java.util.concurrent.Callable) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest)

Example 7 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class IgniteCacheTxRecoveryRollbackTest method nearTx2.

/**
     * Stop both tx near node (client2) and primary node, near cache tx on client1 is invalidated.
     *
     * @param concurrency Tx concurrency or {@code null} for implicit transaction.
     * @throws Exception If failed.
     */
private void nearTx2(final TransactionConcurrency concurrency) throws Exception {
    startGrids(4);
    Ignite srv0 = grid(0);
    srv0.createCache(cacheConfiguration(2, false, false));
    awaitPartitionMapExchange();
    client = true;
    Ignite client1 = startGrid(4);
    final Ignite client2 = startGrid(5);
    final Integer key = primaryKey(srv0.cache(DEFAULT_CACHE_NAME));
    final IgniteCache<Integer, Integer> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<Integer, Integer>());
    final IgniteCache<Integer, Integer> cache2 = client2.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<Integer, Integer>());
    cache1.put(key, 1);
    final Integer newVal = 2;
    testSpi(client2).blockMessages(GridNearTxFinishRequest.class, srv0.name());
    testSpi(srv0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return msg instanceof GridDhtTxFinishRequest;
        }
    });
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            log.info("Start put, concurrency: " + concurrency);
            if (concurrency != null) {
                try (Transaction tx = client2.transactions().txStart(concurrency, REPEATABLE_READ)) {
                    cache2.put(key, newVal);
                    tx.commit();
                }
            } else
                cache2.put(key, newVal);
            return null;
        }
    });
    U.sleep(500);
    assertFalse(fut.isDone());
    testSpi(client2).waitForBlocked(GridNearTxFinishRequest.class, srv0.name());
    stopGrid(client2.name());
    stopGrid(srv0.name());
    try {
        fut.get();
    } catch (IgniteCheckedException ignore) {
    // No-op.
    }
    final IgniteCache<Integer, Integer> srvCache = grid(1).cache(DEFAULT_CACHE_NAME);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return newVal.equals(srvCache.get(key)) && newVal.equals(cache1.get(key));
        }
    }, 5000);
    checkData(F.asMap(key, newVal));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Message(org.apache.ignite.plugin.extensions.communication.Message) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CacheLoaderException(javax.cache.integration.CacheLoaderException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheWriterException(javax.cache.integration.CacheWriterException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite)

Example 8 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class IgniteCacheAtomicProtocolTest method putAllMissedDhtRequest_UnstableTopology.

/**
     * @param fail0 Fail node 0 flag.
     * @param fail1 Fail node 1 flag.
     * @throws Exception If failed.
     */
private void putAllMissedDhtRequest_UnstableTopology(boolean fail0, boolean fail1) throws Exception {
    blockRebalance = true;
    ccfg = cacheConfiguration(1, FULL_SYNC);
    startServers(4);
    client = true;
    Ignite client = startGrid(4);
    IgniteCache<Integer, Integer> nearCache = client.cache(TEST_CACHE);
    if (fail0) {
        testSpi(ignite(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                return msg instanceof GridDhtAtomicAbstractUpdateRequest;
            }
        });
    }
    if (fail1) {
        testSpi(ignite(2)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                return msg instanceof GridDhtAtomicAbstractUpdateRequest;
            }
        });
    }
    Integer key1 = primaryKey(ignite(0).cache(TEST_CACHE));
    Integer key2 = primaryKey(ignite(2).cache(TEST_CACHE));
    log.info("Start put [key1=" + key1 + ", key2=" + key1 + ']');
    Map<Integer, Integer> map = new HashMap<>();
    map.put(key1, 10);
    map.put(key2, 20);
    IgniteFuture<?> fut = nearCache.putAllAsync(map);
    U.sleep(500);
    assertFalse(fut.isDone());
    if (fail0)
        stopGrid(0);
    if (fail1)
        stopGrid(2);
    fut.get();
    checkData(map);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) Ignite(org.apache.ignite.Ignite)

Example 9 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class CacheExchangeMessageDuplicatedStateTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    cfg.setClientMode(client);
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    commSpi.record(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return (msg.getClass() == GridDhtPartitionsSingleMessage.class || msg.getClass() == GridDhtPartitionsFullMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null;
        }
    });
    cfg.setCommunicationSpi(commSpi);
    List<CacheConfiguration> ccfgs = new ArrayList<>();
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF1_CACHE1);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF1_CACHE2);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF3_CACHE1);
        ccfg.setBackups(3);
        RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 64);
        ccfg.setAffinity(aff);
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF4_FILTER_CACHE1);
        ccfg.setNodeFilter(new TestNodeFilter());
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF4_FILTER_CACHE2);
        ccfg.setNodeFilter(new TestNodeFilter());
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ccfgs.add(ccfg);
    }
    cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ArrayList(java.util.ArrayList) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 10 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure) throws IgniteSpiException {
            if (getSpiContext().localNode().id().equals(failingNodeId)) {
                if (ignoredMessage((GridIoMessage) msg) && ignoreMsgNodeIds != null) {
                    for (UUID ignored : ignoreMsgNodeIds) {
                        if (node.id().equals(ignored))
                            return;
                    }
                }
            }
            super.sendMessage(node, msg, ackClosure);
        }
    });
    cfg.getTransactionConfiguration().setDefaultTxConcurrency(PESSIMISTIC);
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) UUID(java.util.UUID) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Aggregations

Message (org.apache.ignite.plugin.extensions.communication.Message)48 ClusterNode (org.apache.ignite.cluster.ClusterNode)25 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 Ignite (org.apache.ignite.Ignite)10 UUID (java.util.UUID)9 IgniteException (org.apache.ignite.IgniteException)9 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)9 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)8 HashMap (java.util.HashMap)7 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)7 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Collection (java.util.Collection)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)4 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)4