Search in sources :

Example 11 with GridNearCacheAdapter

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter in project ignite by apache.

the class GridCacheDhtMappingSelfTest method testMapping.

/** @throws Exception If failed. */
public void testMapping() throws Exception {
    int nodeCnt = 5;
    startGridsMultiThreaded(nodeCnt);
    IgniteCache<Integer, Integer> cache = grid(nodeCnt - 1).cache(DEFAULT_CACHE_NAME);
    int kv = 1;
    cache.put(kv, kv);
    int cnt = 0;
    for (int i = 0; i < nodeCnt; i++) {
        Ignite g = grid(i);
        GridDhtCacheAdapter<Integer, Integer> dht = ((GridNearCacheAdapter<Integer, Integer>) ((IgniteKernal) g).<Integer, Integer>internalCache(DEFAULT_CACHE_NAME)).dht();
        if (localPeek(dht, kv) != null) {
            info("Key found on node: " + g.cluster().localNode().id());
            cnt++;
        }
    }
    // Test key should be on primary and backup node only.
    assertEquals(1 + BACKUPS, cnt);
}
Also used : GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) Ignite(org.apache.ignite.Ignite)

Example 12 with GridNearCacheAdapter

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter in project ignite by apache.

the class IgniteTxManager method removeObsolete.

/**
     * @param tx Transaction.
     */
private void removeObsolete(IgniteInternalTx tx) {
    Collection<IgniteTxEntry> entries = tx.local() ? tx.allEntries() : tx.writeEntries();
    for (IgniteTxEntry entry : entries) {
        GridCacheEntryEx cached = entry.cached();
        GridCacheContext cacheCtx = entry.context();
        if (cached == null)
            cached = cacheCtx.cache().peekEx(entry.key());
        if (cached.detached())
            continue;
        try {
            if (cached.obsolete() || cached.markObsoleteIfEmpty(tx.xidVersion()))
                cacheCtx.cache().removeEntry(cached);
            if (!tx.near() && isNearEnabled(cacheCtx)) {
                GridNearCacheAdapter near = cacheCtx.isNear() ? cacheCtx.near() : cacheCtx.dht().near();
                GridNearCacheEntry e = near.peekExx(entry.key());
                if (e != null && e.markObsoleteIfEmpty(tx.xidVersion()))
                    near.removeEntry(e);
            }
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to remove obsolete entry from cache: " + cached, e);
        }
    }
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter)

Example 13 with GridNearCacheAdapter

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter 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 14 with GridNearCacheAdapter

use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter in project ignite by apache.

the class GridCacheVersionMultinodeTest method checkEntryVersion.

/**
     * @param key Key.
     * @throws Exception If failed.
     */
private void checkEntryVersion(String key) throws Exception {
    GridCacheVersion ver = null;
    boolean verified = false;
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal grid = (IgniteKernal) grid(i);
        GridCacheAdapter<Object, Object> cache = grid.context().cache().internalCache(DEFAULT_CACHE_NAME);
        GridCacheEntryEx e;
        if (cache.affinity().isPrimaryOrBackup(grid.localNode(), key)) {
            if (cache instanceof GridNearCacheAdapter)
                cache = ((GridNearCacheAdapter<Object, Object>) cache).dht();
            e = cache.entryEx(key);
            e.unswap();
            assertNotNull(e.rawGet());
        } else
            e = cache.peekEx(key);
        if (e != null) {
            if (ver != null) {
                assertEquals("Non-equal versions for key: " + key, ver, e instanceof GridNearCacheEntry ? ((GridNearCacheEntry) e).dhtVersion() : e.version());
                verified = true;
            } else
                ver = e instanceof GridNearCacheEntry ? ((GridNearCacheEntry) e).dhtVersion() : e.version();
        }
    }
    assertTrue(verified);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter)

Aggregations

GridNearCacheAdapter (org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter)14 IgniteKernal (org.apache.ignite.internal.IgniteKernal)8 Ignite (org.apache.ignite.Ignite)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)4 Transaction (org.apache.ignite.transactions.Transaction)4 UUID (java.util.UUID)3 IgniteException (org.apache.ignite.IgniteException)3 GridNearCacheEntry (org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)2 GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)2 IgniteTxManager (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)2 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)2