Search in sources :

Example 6 with GridDhtTxFinishRequest

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

the class IgniteTxCachePrimarySyncTest method singleKeyCommit.

/**
 * @param client Node executing cache operation.
 * @param ccfg Cache configuration.
 * @param c Cache update closure.
 * @throws Exception If failed.
 */
private void singleKeyCommit(Ignite client, final CacheConfiguration<Object, Object> ccfg, IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
    Ignite ignite = ignite(0);
    assertNotSame(ignite, client);
    TestRecordingCommunicationSpi commSpiClient = (TestRecordingCommunicationSpi) client.configuration().getCommunicationSpi();
    TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
    IgniteCache<Object, Object> cache = ignite.cache(ccfg.getName());
    final Integer key = primaryKey(cache);
    cache.remove(key);
    waitKeyRemoved(ccfg.getName(), key);
    IgniteCache<Object, Object> clientCache = client.cache(ccfg.getName());
    commSpiClient.record(GridNearTxFinishRequest.class);
    commSpi0.record(GridDhtTxFinishRequest.class);
    commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return msg instanceof GridDhtTxFinishRequest;
        }
    });
    c.apply(key, clientCache);
    assertEquals(key, cache.localPeek(key));
    U.sleep(50);
    boolean nearCache = ((IgniteCacheProxy) clientCache).context().isNear();
    for (int i = 1; i < NODES; i++) {
        Ignite node = ignite(i);
        if (nearCache && node == client && !node.affinity(ccfg.getName()).isPrimaryOrBackup(node.cluster().localNode(), key))
            assertEquals("Invalid value for node: " + i, key, ignite(i).cache(DEFAULT_CACHE_NAME).localPeek(key));
        else
            assertNull("Invalid value for node: " + i, ignite(i).cache(DEFAULT_CACHE_NAME).localPeek(key));
    }
    commSpi0.stopBlock(true);
    waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
    List<Object> msgs = commSpiClient.recordedMessages(true);
    assertEquals(1, msgs.size());
    GridNearTxFinishRequest req = (GridNearTxFinishRequest) msgs.get(0);
    assertEquals(PRIMARY_SYNC, req.syncMode());
    msgs = commSpi0.recordedMessages(true);
    assertEquals(ccfg.getBackups(), msgs.size());
    clientCache.remove(key);
    waitKeyRemoved(ccfg.getName(), key);
    c.apply(key, clientCache);
    waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest)

Example 7 with GridDhtTxFinishRequest

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

the class TxRecoveryWithConcurrentRollbackTest method doTestRecoveryNotBreakingTxAtomicityOnNearAndPrimaryFail.

/**
 * Stop near and primary node after primary tx is rolled back with enabled persistence.
 * <p>
 * Expected result: after restarting a primary node all partitions are consistent.
 */
private void doTestRecoveryNotBreakingTxAtomicityOnNearAndPrimaryFail(CacheWriteSynchronizationMode syncMode) throws Exception {
    backups = 2;
    persistence = true;
    this.syncMode = syncMode;
    final IgniteEx node0 = startGrids(3);
    node0.cluster().state(ACTIVE);
    final Ignite client = startGrid("client");
    final IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
    final Integer pk = primaryKey(grid(1).cache(DEFAULT_CACHE_NAME));
    IgniteInternalFuture<Void> fut = null;
    List<IgniteInternalTx> tx0 = null;
    List<IgniteInternalTx> tx2 = null;
    try (final Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
        cache.put(pk, Boolean.TRUE);
        TransactionProxyImpl p = (TransactionProxyImpl) tx;
        p.tx().prepare(true);
        tx0 = txs(grid(0));
        tx2 = txs(grid(2));
        spi(grid(1)).blockMessages((node, msg) -> msg instanceof GridDhtTxFinishRequest);
        fut = runAsync(() -> {
            spi(grid(1)).waitForBlocked(2);
            client.close();
            grid(1).close();
            return null;
        });
        tx.rollback();
    } catch (Exception e) {
    // No-op.
    }
    fut.get();
    final IgniteInternalTx tx_0 = tx0.get(0);
    tx_0.finishFuture().get();
    final IgniteInternalTx tx_2 = tx2.get(0);
    tx_2.finishFuture().get();
    assertPartitionsSame(idleVerify(grid(0), DEFAULT_CACHE_NAME));
    startGrid(1);
    awaitPartitionMapExchange();
    assertPartitionsSame(idleVerify(grid(0), DEFAULT_CACHE_NAME));
}
Also used : GridDhtTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite)

Aggregations

GridDhtTxFinishRequest (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest)7 Ignite (org.apache.ignite.Ignite)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 Message (org.apache.ignite.plugin.extensions.communication.Message)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 GridNearTxFinishRequest (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest)2 Transaction (org.apache.ignite.transactions.Transaction)2 File (java.io.File)1 File.separatorChar (java.io.File.separatorChar)1