Search in sources :

Example 11 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 12 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)

Example 13 with Message

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

the class GridH2ValueMessageFactory method fillArray.

/**
 * @param src Source iterator.
 * @param dst Array to fill with values.
 * @param ctx Kernal context.
 * @return Filled array.
 * @throws IgniteCheckedException If failed.
 */
public static Value[] fillArray(Iterator<? extends Message> src, Value[] dst, GridKernalContext ctx) throws IgniteCheckedException {
    for (int i = 0; i < dst.length; i++) {
        Message msg = src.next();
        dst[i] = ((GridH2ValueMessage) msg).value(ctx);
    }
    return dst;
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message)

Example 14 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 15 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) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) GridCacheGroupIdMessage(org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) Ignite(org.apache.ignite.Ignite)

Aggregations

Message (org.apache.ignite.plugin.extensions.communication.Message)56 ClusterNode (org.apache.ignite.cluster.ClusterNode)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)14 IgniteException (org.apache.ignite.IgniteException)11 UUID (java.util.UUID)9 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)9 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)9 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)8 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)8 ArrayList (java.util.ArrayList)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)7 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)7 HashMap (java.util.HashMap)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6 Collection (java.util.Collection)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5