Search in sources :

Example 61 with IgniteEx

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

the class IgniteWalHistoryReservationsTest method testNodeLeftDuringExchange.

/**
 * @throws Exception If failed.
 */
public void testNodeLeftDuringExchange() throws Exception {
    System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0");
    final int entryCnt = 10_000;
    final int initGridCnt = 4;
    final Ignite ig0 = startGrids(initGridCnt);
    ig0.active(true);
    IgniteCache<Object, Object> cache = ig0.cache("cache1");
    for (int k = 0; k < entryCnt; k++) cache.put(k, k);
    forceCheckpoint();
    Lock lock = cache.lock(0);
    lock.lock();
    try {
        GridTestUtils.runAsync(new Runnable() {

            @Override
            public void run() {
                try {
                    startGrid(initGridCnt);
                } catch (Exception e) {
                    fail(e.getMessage());
                }
            }
        });
        boolean reserved = GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                for (int g = 0; g < initGridCnt; g++) {
                    IgniteEx ig = grid(g);
                    FileWriteAheadLogManager wal = (FileWriteAheadLogManager) ig.context().cache().context().wal();
                    Object reservationStorage = GridTestUtils.getFieldValue(wal, "reservationStorage");
                    synchronized (reservationStorage) {
                        Map reserved = GridTestUtils.getFieldValue(reservationStorage, "reserved");
                        if (reserved.isEmpty())
                            return false;
                    }
                }
                return true;
            }
        }, 10_000);
        assert reserved;
        stopGrid(Integer.toString(initGridCnt - 1), true, false);
    } finally {
        lock.unlock();
    }
    boolean released = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (int g = 0; g < initGridCnt - 1; g++) {
                IgniteEx ig = grid(g);
                FileWriteAheadLogManager wal = (FileWriteAheadLogManager) ig.context().cache().context().wal();
                Object reservationStorage = GridTestUtils.getFieldValue(wal, "reservationStorage");
                synchronized (reservationStorage) {
                    Map reserved = GridTestUtils.getFieldValue(reservationStorage, "reserved");
                    if (!reserved.isEmpty())
                        return false;
                }
            }
            return true;
        }
    }, 10_000);
    assert released;
    awaitPartitionMapExchange();
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Lock(java.util.concurrent.locks.Lock) IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) Ignite(org.apache.ignite.Ignite) Map(java.util.Map)

Example 62 with IgniteEx

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

the class IgniteWalRecoveryPPCTest method testDynamicallyStartedNonPersistentCache.

/**
 */
public void testDynamicallyStartedNonPersistentCache() throws Exception {
    try {
        IgniteEx ignite = startGrid(1);
        ignite.active(true);
        IgniteCache<Integer, Object> dynamicPersistent = ignite.getOrCreateCache(new CacheConfiguration<Integer, Object>().setAtomicityMode(CacheAtomicityMode.ATOMIC).setRebalanceMode(CacheRebalanceMode.SYNC).setName("dynamicPersistent").setAffinity(new RendezvousAffinityFunction(false, 32)));
        IgniteCache<Integer, Object> dynamicVolatile = ignite.getOrCreateCache(new CacheConfiguration<Integer, Object>().setAtomicityMode(CacheAtomicityMode.ATOMIC).setRebalanceMode(CacheRebalanceMode.SYNC).setDataRegionName(MEM_PLC_NO_PDS).setName("dynamicVolatile").setAffinity(new RendezvousAffinityFunction(false, 32)));
        for (int i = 0; i < 10_000; i++) {
            dynamicPersistent.put(i, new IndexedObject(i));
            dynamicVolatile.put(i, new IndexedObject(i + 1));
        }
        stopGrid(1);
        ignite = startGrid(1);
        ignite.active(true);
        dynamicPersistent = ignite.cache("dynamicPersistent");
        dynamicVolatile = ignite.cache("dynamicVolatile");
        for (int i = 0; i < 10_000; i++) assertEquals(new IndexedObject(i), dynamicPersistent.get(i));
        assertNull(dynamicVolatile);
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 63 with IgniteEx

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

the class IgniteWalRecoverySeveralRestartsTest method testWalRecoverySeveralRestarts.

/**
 * @throws Exception if failed.
 */
public void testWalRecoverySeveralRestarts() throws Exception {
    try {
        IgniteEx ignite = startGrid(1);
        ignite.active(true);
        Random locRandom = ThreadLocalRandom.current();
        try (IgniteDataStreamer<Integer, IndexedObject> dataLdr = ignite.dataStreamer(cacheName)) {
            for (int i = 0; i < KEYS_COUNT; ++i) {
                if (i % (KEYS_COUNT / 100) == 0)
                    info("Loading " + i * 100 / KEYS_COUNT + "%");
                dataLdr.addData(i, new IndexedObject(i));
            }
        }
        int size = ignite.cache(cacheName).size();
        for (int restartCnt = 0; restartCnt < 5; ++restartCnt) {
            stopGrid(1, true);
            info("Restart #" + restartCnt);
            U.sleep(500);
            ignite = startGrid(1);
            ignite.active(true);
            IgniteCache<Integer, IndexedObject> cache = ignite.cache(cacheName);
            assertEquals(size, cache.size());
            info("Restart #" + restartCnt);
            for (int i = 0; i < KEYS_COUNT / 100; ++i) {
                assertNotNull(cache.get(locRandom.nextInt(KEYS_COUNT / 100)));
                cache.put(locRandom.nextInt(KEYS_COUNT / 100), new IndexedObject(locRandom.nextInt(KEYS_COUNT / 100)));
            }
            cache.put(KEYS_COUNT + restartCnt, new IndexedObject(KEYS_COUNT + restartCnt));
            // Check recovery for partition meta pages.
            size = cache.size();
        }
    } finally {
        stopAllGrids();
    }
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 64 with IgniteEx

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

the class IgniteWalRecoveryTest method testMetastorageLargeArray.

/**
 * @throws Exception If fail.
 */
public void testMetastorageLargeArray() throws Exception {
    try {
        int cnt = 5000;
        int arraySize = 32_768;
        IgniteEx ignite = (IgniteEx) startGrid("node1");
        ignite.active(true);
        GridCacheSharedContext<Object, Object> sharedCtx = ignite.context().cache().context();
        MetaStorage storage = sharedCtx.database().metaStorage();
        for (int i = 0; i < cnt; i++) {
            byte[] b1 = new byte[arraySize];
            for (int k = 0; k < arraySize; k++) {
                b1[k] = (byte) (k % 100);
            }
            sharedCtx.database().checkpointReadLock();
            try {
                storage.putData(String.valueOf(i), b1);
            } finally {
                sharedCtx.database().checkpointReadUnlock();
            }
        }
        for (int i = 0; i < cnt; i++) {
            byte[] d2 = storage.getData(String.valueOf(i));
            assertEquals(arraySize, d2.length);
            for (int k = 0; k < arraySize; k++) {
                assertEquals((byte) (k % 100), d2[k]);
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 65 with IgniteEx

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

the class IgniteWalRecoveryTest method testSwitchClassLoader.

/**
 * @throws Exception If fail.
 */
public void testSwitchClassLoader() throws Exception {
    try {
        final IgniteEx igniteEx = startGrid(1);
        // CustomDiscoveryMessage will trigger service tasks
        startGrid(2);
        igniteEx.active(true);
        IgniteCache<Integer, EnumVal> cache = igniteEx.cache("partitioned");
        // Creates LoadCacheJobV2
        // cache.loadCache(null);
        final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
        final ClassLoader newCl = getExternalClassLoader();
        Thread.currentThread().setContextClassLoader(newCl);
        for (int i = 0; i < 10; i++) cache.put(i, i % 2 == 0 ? EnumVal.VAL1 : EnumVal.VAL2);
        for (int i = 0; i < 10; i++) assert cache.containsKey(i);
        // Invokes ClearTask with new class loader
        cache.clear();
        Thread.currentThread().setContextClassLoader(oldCl);
        for (int i = 0; i < 10; i++) cache.put(i, i % 2 == 0 ? EnumVal.VAL1 : EnumVal.VAL2);
        for (int i = 0; i < 10; i++) assert cache.containsKey(i);
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx)

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