Search in sources :

Example 51 with IgniteEx

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

the class CacheRebalancingSelfTest method testRebalanceFuture.

/**
 * @throws Exception If failed.
 */
public void testRebalanceFuture() throws Exception {
    IgniteEx ig0 = startGrid(0);
    startGrid(1);
    IgniteCache<Object, Object> cache = ig0.cache(DEFAULT_CACHE_NAME);
    IgniteFuture fut1 = cache.rebalance();
    fut1.get();
    startGrid(2);
    IgniteFuture fut2 = cache.rebalance();
    assert internalFuture(fut2) != internalFuture(fut1);
    fut2.get();
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteFuture(org.apache.ignite.lang.IgniteFuture)

Example 52 with IgniteEx

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

the class CacheRebalancingSelfTest method testDisableRebalancing.

/**
 * Test local cache size with and without rebalancing in case or topology change.
 *
 * @throws Exception If failed.
 */
public void testDisableRebalancing() throws Exception {
    IgniteEx ig0 = startGrid(0);
    IgniteEx ig1 = startGrid(1);
    startGrid(2);
    ig1.rebalanceEnabled(false);
    Random r = new Random();
    int totalKeysCnt = 10240;
    final Set<Integer> keys = new HashSet<>();
    while (keys.size() < totalKeysCnt) keys.add(r.nextInt());
    IgniteCache<Integer, Integer> cache = ig0.getOrCreateCache(REBALANCE_TEST_CACHE_NAME);
    for (Integer next : keys) cache.put(next, 1);
    testLocalCacheSize(ig0, 0, totalKeysCnt);
    int before_ig1 = testLocalCacheSize(ig1, 0, totalKeysCnt);
    stopGrid(2);
    testLocalCacheSize(ig0, totalKeysCnt, null);
    testLocalCacheSize(ig1, before_ig1, null);
    ig1.rebalanceEnabled(true);
    testLocalCacheSize(ig0, totalKeysCnt, null);
    testLocalCacheSize(ig1, totalKeysCnt, null);
}
Also used : Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) HashSet(java.util.HashSet)

Example 53 with IgniteEx

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

the class AtomicCacheAffinityConfigurationTest method testDefaultAffinity.

/**
 * @throws Exception If failed.
 */
public void testDefaultAffinity() throws Exception {
    try {
        affinityFunction = null;
        startGrids(3);
        for (int i = 0; i < 3; i++) {
            IgniteEx igniteEx = grid(i);
            IgniteAtomicLong atomic = igniteEx.atomicLong("test", 0, true);
            GridCacheContext cctx = GridTestUtils.getFieldValue(atomic, AtomicDataStructureProxy.class, "ctx");
            AffinityFunction aff = cctx.config().getAffinity();
            assertNotNull(aff);
        }
        checkAtomics();
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)

Example 54 with IgniteEx

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

the class AtomicCacheAffinityConfigurationTest method testRendezvousAffinity.

/**
 * @throws Exception If failed.
 */
public void testRendezvousAffinity() throws Exception {
    try {
        affinityFunction = new RendezvousAffinityFunction(false, 10);
        startGrids(3);
        for (int i = 0; i < 3; i++) {
            IgniteEx igniteEx = grid(i);
            IgniteAtomicLong atomic = igniteEx.atomicLong("test", 0, true);
            GridCacheContext cctx = GridTestUtils.getFieldValue(atomic, AtomicDataStructureProxy.class, "ctx");
            AffinityFunction aff = cctx.config().getAffinity();
            assertNotNull(aff);
            assertEquals(aff.partitions(), affinityFunction.partitions());
            assertEquals(aff.getClass(), affinityFunction.getClass());
        }
        checkAtomics();
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)

Example 55 with IgniteEx

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

the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testGetForInitialWrite.

/**
 * @throws Exception if failed.
 */
public void testGetForInitialWrite() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.active(true);
    GridCacheSharedContext<Object, Object> shared = ig.context().cache().context();
    int cacheId = shared.cache().cache(cacheName).context().cacheId();
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) shared.database();
    // Disable integrated checkpoint thread.
    dbMgr.enableCheckpoints(false);
    PageMemory mem = shared.database().dataRegion(null).pageMemory();
    IgniteWriteAheadLogManager wal = shared.wal();
    WALPointer start = wal.log(new CheckpointRecord(null));
    final FullPageId[] initWrites = new FullPageId[10];
    ig.context().cache().context().database().checkpointReadLock();
    try {
        for (int i = 0; i < initWrites.length; i++) initWrites[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId);
        // Check getForInitialWrite methods.
        for (FullPageId fullId : initWrites) {
            long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
            try {
                long pageAddr = mem.writeLock(fullId.groupId(), fullId.pageId(), page);
                try {
                    DataPageIO.VERSIONS.latest().initNewPage(pageAddr, fullId.pageId(), mem.pageSize());
                    for (int i = PageIO.COMMON_HEADER_END + DataPageIO.ITEMS_OFF; i < mem.pageSize(); i++) PageUtils.putByte(pageAddr, i, (byte) 0xAB);
                    PageIO.printPage(pageAddr, mem.pageSize());
                } finally {
                    mem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, true);
                }
            } finally {
                mem.releasePage(fullId.groupId(), fullId.pageId(), page);
            }
        }
        wal.fsync(null);
    } finally {
        ig.context().cache().context().database().checkpointReadUnlock();
        stopAllGrids(false);
    }
    ig = startGrid(0);
    ig.active(true);
    shared = ig.context().cache().context();
    dbMgr = (GridCacheDatabaseSharedManager) shared.database();
    dbMgr.enableCheckpoints(false);
    wal = shared.wal();
    try (PartitionMetaStateRecordExcludeIterator it = new PartitionMetaStateRecordExcludeIterator(wal.replay(start))) {
        it.next();
        for (FullPageId initialWrite : initWrites) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
            assertTrue(String.valueOf(tup.get2()), tup.get2() instanceof PageSnapshot);
            PageSnapshot snap = (PageSnapshot) tup.get2();
            FullPageId actual = snap.fullPageId();
            // there are extra tracking pages, skip them
            if (TrackingPageIO.VERSIONS.latest().trackingPageFor(actual.pageId(), mem.pageSize()) == actual.pageId()) {
                tup = it.next();
                assertTrue(tup.get2() instanceof PageSnapshot);
                actual = ((PageSnapshot) tup.get2()).fullPageId();
            }
            assertEquals(initialWrite, actual);
        }
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)

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