Search in sources :

Example 66 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteWalRecoveryTest method testRecoveryOnTransactionalAndPartitionedCache.

/**
 * Test recovery from WAL on 3 nodes in case of transactional cache.
 *
 * @throws Exception If fail.
 */
public void testRecoveryOnTransactionalAndPartitionedCache() throws Exception {
    IgniteEx ignite = (IgniteEx) startGrids(3);
    ignite.active(true);
    try {
        final String cacheName = "transactional";
        CacheConfiguration<Object, Object> cacheConfiguration = new CacheConfiguration<>(cacheName).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setAffinity(new RendezvousAffinityFunction(false, 32)).setCacheMode(CacheMode.PARTITIONED).setRebalanceMode(CacheRebalanceMode.SYNC).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(2);
        ignite.createCache(cacheConfiguration);
        IgniteCache<Object, Object> cache = ignite.cache(cacheName);
        Map<Object, Object> map = new HashMap<>();
        final int transactions = 100;
        final int operationsPerTransaction = 40;
        Random random = new Random();
        for (int t = 1; t <= transactions; t++) {
            Transaction tx = ignite.transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.READ_COMMITTED);
            Map<Object, Object> changesInTransaction = new HashMap<>();
            for (int op = 0; op < operationsPerTransaction; op++) {
                int key = random.nextInt(1000) + 1;
                Object value;
                if (random.nextBoolean())
                    value = randomString(random) + key;
                else
                    value = new BigObject(key);
                changesInTransaction.put(key, value);
                cache.put(key, value);
            }
            if (random.nextBoolean()) {
                tx.commit();
                map.putAll(changesInTransaction);
            } else {
                tx.rollback();
            }
            if (t % 50 == 0)
                log.info("Finished transaction " + t);
        }
        stopAllGrids();
        ignite = (IgniteEx) startGrids(3);
        ignite.active(true);
        cache = ignite.cache(cacheName);
        for (Object key : map.keySet()) {
            Object expectedValue = map.get(key);
            Object actualValue = cache.get(key);
            Assert.assertEquals("Unexpected value for key " + key, expectedValue, actualValue);
        }
    } finally {
        stopAllGrids();
    }
}
Also used : HashMap(java.util.HashMap) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 67 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteWalRecoveryTest method testWalSimple.

/**
 * @throws Exception if failed.
 */
public void testWalSimple() throws Exception {
    try {
        IgniteEx ignite = startGrid(1);
        ignite.active(true);
        IgniteCache<Object, Object> cache = ignite.cache("partitioned");
        info(" --> step1");
        for (int i = 0; i < 10_000; i += 2) {
            // X.println(" -> put: " + i);
            cache.put(i, new IndexedObject(i));
        }
        info(" --> step2");
        for (int i = 0; i < 10_000; i += 3) cache.put(i, new IndexedObject(i * 2));
        info(" --> step3");
        for (int i = 0; i < 10_000; i += 7) cache.put(i, new IndexedObject(i * 3));
        info(" --> check1");
        // Check.
        for (int i = 0; i < 10_000; i++) {
            IndexedObject o;
            if (i % 7 == 0)
                o = new IndexedObject(i * 3);
            else if (i % 3 == 0)
                o = new IndexedObject(i * 2);
            else if (i % 2 == 0)
                o = new IndexedObject(i);
            else
                o = null;
            assertEquals(o, cache.get(i));
        }
        stopGrid(1);
        ignite = startGrid(1);
        ignite.active(true);
        cache = ignite.cache("partitioned");
        info(" --> check2");
        // Check.
        for (int i = 0; i < 10_000; i++) {
            IndexedObject o;
            if (i % 7 == 0)
                o = new IndexedObject(i * 3);
            else if (i % 3 == 0)
                o = new IndexedObject(i * 2);
            else if (i % 2 == 0)
                o = new IndexedObject(i);
            else
                o = null;
            assertEquals(o, cache.get(i));
        }
        info(" --> ok");
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 68 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteWalRecoveryTest method testRecoveryNoCheckpoint.

/**
 * @throws Exception if failed.
 */
public void testRecoveryNoCheckpoint() throws Exception {
    try {
        IgniteEx ctrlGrid = startGrid(0);
        fork = true;
        IgniteEx cacheGrid = startGrid(1);
        ctrlGrid.active(true);
        ctrlGrid.compute(ctrlGrid.cluster().forRemotes()).run(new LoadRunnable(false));
        info("Killing remote process...");
        ((IgniteProcessProxy) cacheGrid).kill();
        final IgniteEx g0 = ctrlGrid;
        GridTestUtils.waitForCondition(new PA() {

            /**
             * {@inheritDoc}
             */
            @Override
            public boolean apply() {
                return g0.cluster().nodes().size() == 1;
            }
        }, getTestTimeout());
        fork = false;
        // Now start the grid and verify that updates were restored from WAL.
        cacheGrid = startGrid(1);
        IgniteCache<Object, Object> cache = cacheGrid.cache("partitioned");
        for (int i = 0; i < 10_000; i++) assertEquals(new IndexedObject(i), cache.get(i));
        List<List<?>> res = cache.query(new SqlFieldsQuery("select count(iVal) from IndexedObject")).getAll();
        assertEquals(1, res.size());
        assertEquals(10_000L, res.get(0).get(0));
    } finally {
        stopAllGrids();
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) IgniteEx(org.apache.ignite.internal.IgniteEx) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Example 69 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteWalRecoveryTest method testRandomCrash.

/**
 * @throws Exception if failed.
 */
public void testRandomCrash() throws Exception {
    try {
        IgniteEx ctrlGrid = startGrid(0);
        fork = true;
        IgniteEx cacheGrid = startGrid(1);
        ctrlGrid.active(true);
        IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes());
        rmt.run(new LoadRunnable(false));
        info(">>> Finished cache population.");
        rmt.run(new AsyncLoadRunnable());
        Thread.sleep(20_000);
        info(">>> Killing remote process...");
        ((IgniteProcessProxy) cacheGrid).kill();
        startGrid(1);
        Boolean res = rmt.call(new VerifyCallable());
        assertTrue(res);
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Example 70 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteWalRecoveryTest method testLargeRandomCrash.

/**
 * @throws Exception if failed.
 */
public void testLargeRandomCrash() throws Exception {
    try {
        IgniteEx ctrlGrid = startGrid(0);
        fork = true;
        IgniteEx cacheGrid = startGrid(1);
        ctrlGrid.active(true);
        IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes());
        rmt.run(new LargeLoadRunnable(false));
        info(">>> Finished cache population.");
        rmt.run(new AsyncLargeLoadRunnable());
        Thread.sleep(20_000);
        info(">>> Killing remote process...");
        ((IgniteProcessProxy) cacheGrid).kill();
        startGrid(1);
        Boolean res = rmt.call(new VerifyLargeCallable());
        assertTrue(res);
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)396 Ignite (org.apache.ignite.Ignite)85 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)64 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)60 IgniteException (org.apache.ignite.IgniteException)46 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)37 Transaction (org.apache.ignite.transactions.Transaction)34 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)31 CountDownLatch (java.util.concurrent.CountDownLatch)28 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)27 IgniteCache (org.apache.ignite.IgniteCache)25 Map (java.util.Map)24 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 CacheException (javax.cache.CacheException)19 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)19 UUID (java.util.UUID)18 Callable (java.util.concurrent.Callable)17 List (java.util.List)16 Random (java.util.Random)16