Search in sources :

Example 71 with IgniteEx

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

the class IgniteWalRecoveryTest method testHugeCheckpointRecord.

/**
 * @throws Exception if failed.
 */
public void testHugeCheckpointRecord() throws Exception {
    try {
        final IgniteEx ignite = startGrid(1);
        ignite.active(true);
        for (int i = 0; i < 50; i++) {
            CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>("cache-" + i);
            // We can get 'too many open files' with default number of partitions.
            ccfg.setAffinity(new RendezvousAffinityFunction(false, 128));
            IgniteCache<Object, Object> cache = ignite.getOrCreateCache(ccfg);
            cache.put(i, i);
        }
        final long endTime = System.currentTimeMillis() + 30_000;
        IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Random rnd = ThreadLocalRandom.current();
                while (U.currentTimeMillis() < endTime) {
                    IgniteCache<Object, Object> cache = ignite.cache("cache-" + rnd.nextInt(50));
                    cache.put(rnd.nextInt(50_000), rnd.nextInt());
                }
                return null;
            }
        }, 16, "put-thread");
        while (System.currentTimeMillis() < endTime) {
            ignite.context().cache().context().database().wakeupForCheckpoint("test").get();
            U.sleep(500);
        }
        fut.get();
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 72 with IgniteEx

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

the class IgniteWalRecoveryTest method testWalBig.

/**
 * @throws Exception if failed.
 */
public void testWalBig() throws Exception {
    IgniteEx ignite = startGrid(1);
    ignite.active(true);
    IgniteCache<Object, Object> cache = ignite.cache("partitioned");
    Random rnd = new Random();
    Map<Integer, IndexedObject> map = new HashMap<>();
    for (int i = 0; i < 10_000; i++) {
        if (i % 1000 == 0)
            X.println(" >> " + i);
        int k = rnd.nextInt(300_000);
        IndexedObject v = new IndexedObject(rnd.nextInt(10_000));
        cache.put(k, v);
        map.put(k, v);
    }
    // Check.
    for (Integer k : map.keySet()) assertEquals(map.get(k), cache.get(k));
    stopGrid(1);
    ignite = startGrid(1);
    ignite.active(true);
    cache = ignite.cache("partitioned");
    // Check.
    for (Integer k : map.keySet()) assertEquals(map.get(k), cache.get(k));
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 73 with IgniteEx

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

the class IgniteWalRecoveryTest method testMetastorageRemove.

/**
 * @throws Exception If fail.
 */
public void testMetastorageRemove() throws Exception {
    try {
        int cnt = 400;
        IgniteEx ignite0 = (IgniteEx) startGrid("node1");
        ignite0.active(true);
        GridCacheSharedContext<Object, Object> sharedCtx0 = ignite0.context().cache().context();
        MetaStorage storage = sharedCtx0.database().metaStorage();
        assert storage != null;
        for (int i = 0; i < cnt; i++) {
            sharedCtx0.database().checkpointReadLock();
            try {
                storage.putData(String.valueOf(i), new byte[] { 1, 2, 3 });
            } finally {
                sharedCtx0.database().checkpointReadUnlock();
            }
        }
        for (int i = 0; i < 10; i++) {
            sharedCtx0.database().checkpointReadLock();
            try {
                storage.removeData(String.valueOf(i));
            } finally {
                sharedCtx0.database().checkpointReadUnlock();
            }
        }
        for (int i = 10; i < cnt; i++) {
            byte[] d1 = storage.getData(String.valueOf(i));
            assertEquals(3, d1.length);
            assertEquals(1, d1[0]);
            assertEquals(2, d1[1]);
            assertEquals(3, d1[2]);
        }
    } finally {
        stopAllGrids();
    }
}
Also used : MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 74 with IgniteEx

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

the class IgniteWalRecoveryTest method testMetastorageUpdate.

/**
 * @throws Exception If fail.
 */
public void testMetastorageUpdate() throws Exception {
    try {
        int cnt = 2000;
        IgniteEx ignite0 = (IgniteEx) startGrid("node1");
        ignite0.active(true);
        GridCacheSharedContext<Object, Object> sharedCtx0 = ignite0.context().cache().context();
        MetaStorage storage = sharedCtx0.database().metaStorage();
        assert storage != null;
        for (int i = 0; i < cnt; i++) {
            sharedCtx0.database().checkpointReadLock();
            try {
                storage.putData(String.valueOf(i), new byte[] { 1, 2, 3 });
            } finally {
                sharedCtx0.database().checkpointReadUnlock();
            }
        }
        for (int i = 0; i < cnt; i++) {
            sharedCtx0.database().checkpointReadLock();
            try {
                storage.putData(String.valueOf(i), new byte[] { 2, 2, 3, 4 });
            } finally {
                sharedCtx0.database().checkpointReadUnlock();
            }
        }
        for (int i = 0; i < cnt; i++) {
            byte[] d1 = storage.getData(String.valueOf(i));
            assertEquals(4, d1.length);
            assertEquals(2, d1[0]);
            assertEquals(2, d1[1]);
            assertEquals(3, d1[2]);
        }
    } finally {
        stopAllGrids();
    }
}
Also used : MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 75 with IgniteEx

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

the class IgniteWalRecoveryTest method testRecoveryLargeNoCheckpoint.

/**
 * @throws Exception if failed.
 */
public void testRecoveryLargeNoCheckpoint() throws Exception {
    try {
        IgniteEx ctrlGrid = startGrid(0);
        fork = true;
        IgniteEx cacheGrid = startGrid(1);
        ctrlGrid.active(true);
        ctrlGrid.compute(ctrlGrid.cluster().forRemotes()).run(new LargeLoadRunnable(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 < 1000; i++) {
            final long[] data = new long[LARGE_ARR_SIZE];
            Arrays.fill(data, i);
            final long[] loaded = (long[]) cache.get(i);
            Assert.assertArrayEquals(data, loaded);
        }
    } finally {
        stopAllGrids();
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) IgniteEx(org.apache.ignite.internal.IgniteEx) 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