Search in sources :

Example 1 with MvccAckRequestTx

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx in project ignite by apache.

the class MvccProcessorImpl method ackTxRollback.

/**
 * {@inheritDoc}
 */
@Override
public void ackTxRollback(MvccVersion updateVer) {
    assert updateVer != null;
    MvccCoordinator crd = curCrd;
    if (crd.disconnected() || crd.version() != updateVer.coordinatorVersion())
        return;
    MvccAckRequestTx msg = new MvccAckRequestTx((long) -1, updateVer.counter());
    msg.skipResponse(true);
    try {
        sendMessage(crd.nodeId(), msg);
    } catch (ClusterTopologyCheckedException e) {
        if (log.isDebugEnabled())
            log.debug("Failed to send tx rollback ack, node left [msg=" + msg + ", node=" + crd.nodeId() + ']');
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to send tx rollback ack [msg=" + msg + ", node=" + crd.nodeId() + ']', e);
    }
}
Also used : MvccAckRequestTx(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 2 with MvccAckRequestTx

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx in project ignite by apache.

the class CacheMvccTransactionsTest method testWaitPreviousTxAck.

/**
 * @throws Exception If failed.
 */
@Test
public void testWaitPreviousTxAck() throws Exception {
    testSpi = true;
    startGrid(0);
    client = true;
    final Ignite ignite = startGrid(1);
    final IgniteCache<Object, Object> cache = ignite.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, 16));
    try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        cache.put(1, 1);
        cache.put(2, 1);
        tx.commit();
    }
    TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(ignite);
    clientSpi.blockMessages((node, msg) -> msg instanceof MvccAckRequestTx);
    IgniteInternalFuture<?> txFut1 = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                cache.put(1, 2);
                tx.commit();
            }
            return null;
        }
    });
    IgniteInternalFuture<?> txFut2 = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                cache.put(2, 3);
                tx.commit();
            }
            // Should see changes made by both tx1 and tx2.
            Map<Object, Object> res = checkAndGetAll(false, cache, F.asSet(1, 2), SCAN, GET);
            assertEquals(2, res.get(1));
            assertEquals(3, res.get(2));
            return null;
        }
    });
    clientSpi.waitForBlocked(2);
    Thread.sleep(1000);
    clientSpi.stopBlock(true);
    txFut1.get();
    txFut2.get();
    Map<Object, Object> res = checkAndGetAll(false, cache, F.asSet(1, 2), SCAN, GET);
    assertEquals(2, res.get(1));
    assertEquals(3, res.get(2));
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) MvccAckRequestTx(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 3 with MvccAckRequestTx

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx in project ignite by apache.

the class CacheMvccTransactionsTest method cleanupWaitsForGet3.

/**
 * @param updates Number of updates.
 * @throws Exception If failed.
 */
private void cleanupWaitsForGet3(int updates) throws Exception {
    /*
        Simulate case when coordinator assigned query version has active transaction,
        query is delayed, after this active transaction finish and the same key is
        updated several more times before query starts.
         */
    testSpi = true;
    client = false;
    startGrids(1);
    client = true;
    final Ignite client = startGrid(1);
    awaitPartitionMapExchange();
    final IgniteCache<Object, Object> cache = client.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, 16));
    final Integer key1 = 1;
    final Integer key2 = 2;
    for (int i = 0; i < updates; i++) {
        try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            cache.put(key1, i);
            cache.put(key2, i);
            tx.commit();
        }
    }
    TestRecordingCommunicationSpi crdSpi = TestRecordingCommunicationSpi.spi(grid(0));
    TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(client);
    clientSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        /**
         */
        private boolean blocked;

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (!blocked && (msg instanceof MvccAckRequestTx)) {
                blocked = true;
                return true;
            }
            return false;
        }
    });
    final IgniteInternalFuture<?> putFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                cache.put(key2, 3);
                tx.commit();
            }
            return null;
        }
    }, "put");
    clientSpi.waitForBlocked();
    for (int i = 0; i < updates; i++) {
        try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            cache.put(key1, i + 3);
            tx.commit();
        }
    }
    // Delay version for getAll.
    crdSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        /**
         */
        private boolean blocked;

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (!blocked && (msg instanceof MvccSnapshotResponse)) {
                blocked = true;
                return true;
            }
            return false;
        }
    });
    final IgniteInternalFuture<?> getFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            final Map<Object, Object> res1 = checkAndGetAll(false, cache, F.asSet(key1, key2), SCAN);
            final Map<Object, Object> res2 = checkAndGetAll(false, cache, F.asSet(key1, key2), GET);
            assertEquals(2, res1.size());
            assertEquals(2, res2.size());
            return null;
        }
    }, "get");
    crdSpi.waitForBlocked();
    clientSpi.stopBlock(true);
    putFut.get();
    for (int i = 0; i < updates; i++) {
        try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            cache.put(key2, i + 4);
            tx.commit();
        }
    }
    crdSpi.stopBlock(true);
    getFut.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Message(org.apache.ignite.plugin.extensions.communication.Message) MvccSnapshotResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) MvccAckRequestTx(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 MvccAckRequestTx (org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 CacheException (javax.cache.CacheException)2 EntryProcessorException (javax.cache.processor.EntryProcessorException)2 Ignite (org.apache.ignite.Ignite)2 IgniteException (org.apache.ignite.IgniteException)2 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)2 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 Transaction (org.apache.ignite.transactions.Transaction)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 MvccSnapshotResponse (org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse)1 Message (org.apache.ignite.plugin.extensions.communication.Message)1 Test (org.junit.Test)1