Search in sources :

Example 26 with GridDhtCacheEntry

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry in project ignite by apache.

the class IgnitePutAllLargeBatchSelfTest method checkPutAll.

/**
 * @throws Exception If failed.
 */
private void checkPutAll(TransactionConcurrency concurrency, boolean nearEnabled) throws Exception {
    this.nearEnabled = nearEnabled;
    startGrids(GRID_CNT);
    awaitPartitionMapExchange();
    try {
        IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
        int keyCnt = 200;
        for (int i = 0; i < keyCnt; i++) cache.put(i, i);
        // Create readers if near cache is enabled.
        for (int g = 1; g < 2; g++) {
            for (int i = 30; i < 70; i++) ((IgniteKernal) grid(g)).getCache(DEFAULT_CACHE_NAME).get(i);
        }
        info(">>> Starting test tx.");
        try (Transaction tx = grid(0).transactions().txStart(concurrency, TransactionIsolation.REPEATABLE_READ)) {
            Map<Integer, Integer> map = new LinkedHashMap<>();
            for (int i = 0; i < keyCnt; i++) map.put(i, i * i);
            cache.getAll(map.keySet());
            cache.putAll(map);
            tx.commit();
        }
        // Check that no stale transactions left and all locks are released.
        for (int g = 0; g < GRID_CNT; g++) {
            IgniteKernal k = (IgniteKernal) grid(g);
            GridCacheAdapter<Object, Object> cacheAdapter = k.context().cache().internalCache(DEFAULT_CACHE_NAME);
            assertEquals(0, cacheAdapter.context().tm().idMapSize());
            for (int i = 0; i < keyCnt; i++) {
                if (cacheAdapter.isNear()) {
                    GridDhtCacheEntry entry = (GridDhtCacheEntry) ((GridNearCacheAdapter<Object, Object>) cacheAdapter).dht().peekEx(i);
                    if (entry != null) {
                        assertFalse(entry.lockedByAny());
                        assertTrue(entry.localCandidates().isEmpty());
                        assertTrue(entry.remoteMvccSnapshot().isEmpty());
                    }
                }
                GridCacheEntryEx entry = cacheAdapter.peekEx(i);
                if (entry != null) {
                    assertFalse(entry.lockedByAny());
                    assertTrue(entry.localCandidates().isEmpty());
                    assertTrue(entry.remoteMvccSnapshot().isEmpty());
                }
            }
        }
        for (int g = 0; g < GRID_CNT; g++) {
            IgniteCache<Object, Object> checkCache = grid(g).cache(DEFAULT_CACHE_NAME);
            ClusterNode checkNode = grid(g).localNode();
            for (int i = 0; i < keyCnt; i++) {
                if (grid(g).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(checkNode, i))
                    assertEquals(i * i, checkCache.localPeek(i, CachePeekMode.PRIMARY, CachePeekMode.BACKUP));
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) LinkedHashMap(java.util.LinkedHashMap) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) Transaction(org.apache.ignite.transactions.Transaction) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter)

Example 27 with GridDhtCacheEntry

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry in project ignite by apache.

the class GridCacheNearMultiNodeSelfTest method testOptimisticWriteThrough.

/**
 * Test Optimistic repeatable read write-through.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings({ "ConstantConditions" })
@Test
public void testOptimisticWriteThrough() throws Exception {
    IgniteCache<Integer, String> near = jcache(0);
    if (transactional()) {
        try (Transaction tx = grid(0).transactions().txStart(OPTIMISTIC, REPEATABLE_READ, 0, 0)) {
            near.put(2, "2");
            String s = near.getAndPut(3, "3");
            assertNotNull(s);
            assertEquals("3", s);
            assertEquals("2", near.get(2));
            assertEquals("3", near.get(3));
            GridDhtCacheEntry entry = (GridDhtCacheEntry) dht(primaryGrid(2)).peekEx(2);
            if (entry != null)
                assertNull("Unexpected entry: " + entry, entry.rawGet());
            assertNotNull(localPeek(dht(primaryGrid(3)), 3));
            tx.commit();
        }
    } else {
        near.put(2, "2");
        String s = near.getAndPut(3, "3");
        assertNotNull(s);
        assertEquals("3", s);
    }
    assertEquals("2", near.localPeek(2));
    assertEquals("3", near.localPeek(3));
    assertEquals("2", localPeek(dht(primaryGrid(2)), 2));
    assertEquals("3", localPeek(dht(primaryGrid(3)), 3));
    assertEquals(2, near.localSize(CachePeekMode.ALL));
    assertEquals(2, near.localSize(CachePeekMode.ALL));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) Transaction(org.apache.ignite.transactions.Transaction) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)27 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)16 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)13 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)11 ArrayList (java.util.ArrayList)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)9 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)9 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)9 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)8 CacheStorePartialUpdateException (org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException)7 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)6 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)6 GridCacheUpdateAtomicResult (org.apache.ignite.internal.processors.cache.GridCacheUpdateAtomicResult)6 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException)6 IgniteException (org.apache.ignite.IgniteException)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 IgniteOutOfMemoryException (org.apache.ignite.internal.mem.IgniteOutOfMemoryException)5