Search in sources :

Example 6 with MvccSnapshotResponse

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

the class CacheMvccTransactionsTest method testGetVersionRequestFailover.

/**
 * @throws Exception If failed.
 */
@Test
public void testGetVersionRequestFailover() throws Exception {
    final int NODES = 5;
    testSpi = true;
    startGridsMultiThreaded(NODES - 1);
    client = true;
    Ignite client = startGrid(NODES - 1);
    final List<String> cacheNames = new ArrayList<>();
    final Map<Integer, Integer> vals = new HashMap<>();
    for (int i = 0; i < 100; i++) vals.put(i, i);
    for (CacheConfiguration ccfg : cacheConfigurations()) {
        ccfg.setName("cache-" + cacheNames.size());
        ccfg.setNodeFilter(new TestCacheNodeExcludingFilter(getTestIgniteInstanceName(0)));
        cacheNames.add(ccfg.getName());
        IgniteCache cache = client.createCache(ccfg);
        try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            writeAllByMode(cache, vals, PUT, INTEGER_CODEC);
            tx.commit();
        }
    }
    final AtomicInteger nodeIdx = new AtomicInteger(1);
    final AtomicBoolean done = new AtomicBoolean();
    try {
        IgniteInternalFuture getFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Ignite node = ignite(nodeIdx.getAndIncrement());
                int cnt = 0;
                while (!done.get()) {
                    for (String cacheName : cacheNames) {
                        // TODO IGNITE-6754 add SQL and SCAN support.
                        Map<Integer, Integer> res = readAllByMode(node.cache(cacheName), vals.keySet(), GET, INTEGER_CODEC);
                        assertEquals(vals, res);
                    }
                    cnt++;
                }
                log.info("Finished [node=" + node.name() + ", cnt=" + cnt + ']');
                return null;
            }
        }, NODES - 1, "get-thread");
        doSleep(1000);
        TestRecordingCommunicationSpi crdSpi = TestRecordingCommunicationSpi.spi(ignite(0));
        crdSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                return msg instanceof MvccSnapshotResponse;
            }
        });
        crdSpi.waitForBlocked();
        stopGrid(0);
        doSleep(1000);
        done.set(true);
        getFut.get();
    } finally {
        done.set(true);
    }
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) MvccSnapshotResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ClusterNode(org.apache.ignite.cluster.ClusterNode) TestCacheNodeExcludingFilter(org.apache.ignite.internal.processors.cache.distributed.TestCacheNodeExcludingFilter) IgniteCache(org.apache.ignite.IgniteCache) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 7 with MvccSnapshotResponse

use of org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse 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

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