Search in sources :

Example 1 with MvccProcessor

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

the class GridNearTxLocal method requestSnapshot.

/**
 * Requests version on coordinator.
 *
 * @return Future to wait for result.
 */
public IgniteInternalFuture<MvccSnapshot> requestSnapshot() {
    if (isRollbackOnly())
        return new GridFinishedFuture<>(rollbackException());
    MvccSnapshot mvccSnapshot0 = mvccSnapshot;
    if (mvccSnapshot0 != null)
        return new GridFinishedFuture<>(mvccSnapshot0);
    MvccProcessor prc = cctx.coordinators();
    MvccCoordinator crd = prc.currentCoordinator();
    synchronized (this) {
        this.crdVer = crd.version();
    }
    if (crd.local())
        mvccSnapshot0 = prc.requestWriteSnapshotLocal();
    if (mvccSnapshot0 == null) {
        MvccSnapshotFuture fut = new MvccTxSnapshotFuture();
        prc.requestWriteSnapshotAsync(crd, fut);
        return fut;
    }
    GridFutureAdapter<MvccSnapshot> fut = new GridFutureAdapter<>();
    onResponse0(mvccSnapshot0, fut);
    return fut;
}
Also used : MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) MvccCoordinator(org.apache.ignite.internal.processors.cache.mvcc.MvccCoordinator) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) MvccProcessor(org.apache.ignite.internal.processors.cache.mvcc.MvccProcessor) MvccSnapshotFuture(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshotFuture)

Example 2 with MvccProcessor

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

the class GridExchangeFreeSwitchTest method testNoTransactionsWaitAtNodeLeft.

/**
 * Checks that transaction can be continued on node left and there is no waiting for it's completion in case
 * baseline was not changed and cluster was fully rebalanced.
 */
private void testNoTransactionsWaitAtNodeLeft(int backups, PartitionLossPolicy lossPlc) throws Exception {
    persistence = true;
    String cacheName = "partitioned";
    try {
        cacheC = new IgniteClosure<String, CacheConfiguration<?, ?>[]>() {

            @Override
            public CacheConfiguration<?, ?>[] apply(String igniteInstanceName) {
                CacheConfiguration<?, ?> ccfg = new CacheConfiguration<>();
                ccfg.setName(cacheName);
                ccfg.setWriteSynchronizationMode(FULL_SYNC);
                ccfg.setBackups(backups);
                ccfg.setPartitionLossPolicy(lossPlc);
                ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
                ccfg.setAffinity(new Map4PartitionsTo4NodesAffinityFunction());
                return new CacheConfiguration[] { ccfg };
            }
        };
        int nodes = 4;
        startGridsMultiThreaded(nodes);
        AtomicLong singleCnt = new AtomicLong();
        AtomicLong fullCnt = new AtomicLong();
        startPmeMessagesCounting(nodes, singleCnt, fullCnt);
        Random r = new Random();
        Ignite candidate;
        MvccProcessor proc;
        int nodeToStop;
        do {
            nodeToStop = r.nextInt(nodes);
            candidate = grid(nodeToStop);
            proc = ((IgniteEx) candidate).context().coordinators();
        } while (// MVCC coordinator fail always breaks transactions, excluding.
        proc.mvccEnabled() && proc.currentCoordinator().local());
        Ignite failed = candidate;
        int multiplicator = 3;
        AtomicInteger key_from = new AtomicInteger();
        CountDownLatch readyLatch = new CountDownLatch((backups > 0 ? 6 : 3) * multiplicator);
        CountDownLatch failedLatch = new CountDownLatch(1);
        IgniteCache<Integer, Integer> failedCache = failed.getOrCreateCache(cacheName);
        int nodeToStop0 = nodeToStop;
        IgniteInternalFuture<?> checkRebalanced = runAsync(() -> {
            try {
                failedLatch.await();
            } catch (Exception e) {
                fail("Should not happen [exception=" + e + "]");
            }
            for (int i = 0; i < nodes; i++) {
                if (i != nodeToStop0) {
                    GridDhtPartitionsExchangeFuture lastFinishedFut = grid(i).cachex(cacheName).context().shared().exchange().lastFinishedFuture();
                    assertTrue(lastFinishedFut.rebalanced());
                    assertTrue(lastFinishedFut.topologyVersion().equals(new AffinityTopologyVersion(nodes + 1, 0)));
                }
            }
        });
        IgniteInternalFuture<?> nearThenNearFut = multithreadedAsync(() -> {
            try {
                List<Integer> keys = nearKeys(failedCache, 2, key_from.addAndGet(100));
                Integer key0 = keys.get(0);
                Integer key1 = keys.get(1);
                Ignite primary = primaryNode(key0, cacheName);
                assertNotSame(failed, primary);
                IgniteCache<Integer, Integer> primaryCache = primary.getOrCreateCache(cacheName);
                try (Transaction tx = primary.transactions().txStart()) {
                    primaryCache.put(key0, key0);
                    readyLatch.countDown();
                    failedLatch.await();
                    checkRebalanced.get();
                    primaryCache.put(key1, key1);
                    tx.commit();
                }
                assertEquals(key0, primaryCache.get(key0));
                assertEquals(key1, primaryCache.get(key1));
            } catch (Exception e) {
                fail("Should not happen [exception=" + e + "]");
            }
        }, multiplicator);
        IgniteInternalFuture<?> primaryThenPrimaryFut = backups > 0 ? multithreadedAsync(() -> {
            try {
                List<Integer> keys = primaryKeys(failedCache, 2, key_from.addAndGet(100));
                Integer key0 = keys.get(0);
                Integer key1 = keys.get(1);
                Ignite backup = backupNode(key0, cacheName);
                assertNotSame(failed, backup);
                IgniteCache<Integer, Integer> backupCache = backup.getOrCreateCache(cacheName);
                try (Transaction tx = backup.transactions().txStart()) {
                    backupCache.put(key0, key0);
                    readyLatch.countDown();
                    failedLatch.await();
                    checkRebalanced.get();
                    try {
                        backupCache.put(key1, key1);
                        fail("Should not happen");
                    } catch (Exception ignored) {
                    // Transaction broken because of primary left.
                    }
                }
            } catch (Exception e) {
                fail("Should not happen [exception=" + e + "]");
            }
        }, multiplicator) : new GridFinishedFuture<>();
        IgniteInternalFuture<?> nearThenPrimaryFut = multithreadedAsync(() -> {
            try {
                Integer key0 = nearKeys(failedCache, 1, key_from.addAndGet(100)).get(0);
                Integer key1 = primaryKeys(failedCache, 1, key_from.addAndGet(100)).get(0);
                Ignite primary = primaryNode(key0, cacheName);
                assertNotSame(failed, primary);
                IgniteCache<Integer, Integer> primaryCache = primary.getOrCreateCache(cacheName);
                try (Transaction tx = primary.transactions().txStart()) {
                    primaryCache.put(key0, key0);
                    readyLatch.countDown();
                    failedLatch.await();
                    checkRebalanced.get();
                    try {
                        primaryCache.put(key1, key1);
                        fail("Should not happen");
                    } catch (Exception ignored) {
                    // Transaction broken because of primary left.
                    }
                }
            } catch (Exception e) {
                fail("Should not happen [exception=" + e + "]");
            }
        }, multiplicator);
        IgniteInternalFuture<?> nearThenBackupFut = backups > 0 ? multithreadedAsync(() -> {
            try {
                Integer key0 = nearKeys(failedCache, 1, key_from.addAndGet(100)).get(0);
                Integer key1 = backupKeys(failedCache, 1, key_from.addAndGet(100)).get(0);
                Ignite primary = primaryNode(key0, cacheName);
                assertNotSame(failed, primary);
                IgniteCache<Integer, Integer> primaryCache = primary.getOrCreateCache(cacheName);
                try (Transaction tx = primary.transactions().txStart()) {
                    primaryCache.put(key0, key0);
                    readyLatch.countDown();
                    failedLatch.await();
                    checkRebalanced.get();
                    primaryCache.put(key1, key1);
                    tx.commit();
                }
                assertEquals(key0, primaryCache.get(key0));
                assertEquals(key1, primaryCache.get(key1));
            } catch (Exception e) {
                fail("Should not happen [exception=" + e + "]");
            }
        }, multiplicator) : new GridFinishedFuture<>();
        IgniteInternalFuture<?> primaryThenNearFut = multithreadedAsync(() -> {
            try {
                Integer key0 = primaryKeys(failedCache, 1, key_from.addAndGet(100)).get(0);
                Integer key1 = nearKeys(failedCache, 1, key_from.addAndGet(100)).get(0);
                Ignite primary = primaryNode(key1, cacheName);
                assertNotSame(failed, primary);
                IgniteCache<Integer, Integer> primaryCache = primary.getOrCreateCache(cacheName);
                try (Transaction tx = primary.transactions().txStart()) {
                    primaryCache.put(key0, key0);
                    readyLatch.countDown();
                    failedLatch.await();
                    checkRebalanced.get();
                    primaryCache.put(key1, key1);
                    try {
                        tx.commit();
                        fail("Should not happen");
                    } catch (Exception ignored) {
                    // Transaction broken because of primary left.
                    }
                }
            } catch (Exception e) {
                fail("Should not happen [exception=" + e + "]");
            }
        }, multiplicator);
        IgniteInternalFuture<?> primaryThenPrimaryWithSameKeyFut = backups > 0 ? multithreadedAsync(() -> {
            try {
                List<Integer> keys = primaryKeys(failedCache, 2, key_from.addAndGet(100));
                Integer key0 = keys.get(0);
                Ignite backup = backupNode(key0, cacheName);
                assertNotSame(failed, backup);
                IgniteCache<Integer, Integer> backupCache = backup.getOrCreateCache(cacheName);
                try (Transaction tx = backup.transactions().txStart()) {
                    backupCache.put(key0, key0);
                    readyLatch.countDown();
                    failedLatch.await();
                    checkRebalanced.get();
                    try {
                        backupCache.put(key0, key0 + 1);
                        fail("Should not happen");
                    } catch (Exception ignored) {
                    // Transaction broken because of primary left.
                    }
                }
            } catch (Exception e) {
                fail("Should not happen [exception=" + e + "]");
            }
        }, multiplicator) : new GridFinishedFuture<>();
        readyLatch.await();
        // Stopping node.
        failed.close();
        awaitPartitionMapExchange();
        failedLatch.countDown();
        nearThenNearFut.get();
        primaryThenPrimaryFut.get();
        nearThenPrimaryFut.get();
        nearThenBackupFut.get();
        primaryThenNearFut.get();
        primaryThenPrimaryWithSameKeyFut.get();
        int pmeFreeCnt = 0;
        for (Ignite ignite : G.allGrids()) {
            assertEquals(nodes + 1, ignite.cluster().topologyVersion());
            ExchangeContext ctx = ((IgniteEx) ignite).context().cache().context().exchange().lastFinishedFuture().context();
            if (ctx.exchangeFreeSwitch())
                pmeFreeCnt++;
        }
        assertEquals(nodes - 1, pmeFreeCnt);
        assertEquals(0, singleCnt.get());
        assertEquals(0, fullCnt.get());
    } finally {
        persistence = false;
    }
}
Also used : Random(java.util.Random) Ignite(org.apache.ignite.Ignite) ArrayList(java.util.ArrayList) List(java.util.List) ExchangeContext(org.apache.ignite.internal.processors.cache.ExchangeContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) MvccProcessor(org.apache.ignite.internal.processors.cache.mvcc.MvccProcessor)

Aggregations

MvccProcessor (org.apache.ignite.internal.processors.cache.mvcc.MvccProcessor)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 ExchangeContext (org.apache.ignite.internal.processors.cache.ExchangeContext)1 GridDhtPartitionsExchangeFuture (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture)1 MvccCoordinator (org.apache.ignite.internal.processors.cache.mvcc.MvccCoordinator)1 MvccSnapshot (org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot)1 MvccSnapshotFuture (org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshotFuture)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1 Transaction (org.apache.ignite.transactions.Transaction)1