Search in sources :

Example 1 with GridNearCacheAdapter

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

the class IgniteTxHandler method invalidateNearEntry.

/**
 * @param cacheCtx Context.
 * @param key Key
 * @param ver Version.
 * @throws IgniteCheckedException If invalidate failed.
 */
private void invalidateNearEntry(GridCacheContext cacheCtx, KeyCacheObject key, GridCacheVersion ver) throws IgniteCheckedException {
    GridNearCacheAdapter near = cacheCtx.isNear() ? cacheCtx.near() : cacheCtx.dht().near();
    GridCacheEntryEx nearEntry = near.peekEx(key);
    if (nearEntry != null)
        nearEntry.invalidate(ver);
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter)

Example 2 with GridNearCacheAdapter

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

the class CacheGetEntryAbstractTest method compareVersionWithPrimaryNode.

/**
 * @param e Entry.
 * @param cache Cache.
 * @throws Exception If failed.
 */
private void compareVersionWithPrimaryNode(CacheEntry<Integer, ?> e, IgniteCache<Integer, TestValue> cache) throws Exception {
    CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
    if (cfg.getCacheMode() != LOCAL) {
        Ignite prim = primaryNode(e.getKey(), cache.getName());
        GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal) prim).internalCache(cache.getName());
        if (cfg.getNearConfiguration() != null)
            cacheAdapter = ((GridNearCacheAdapter) cacheAdapter).dht();
        IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects();
        CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
        GridCacheEntryEx mapEntry = cacheAdapter.entryEx(cacheObjects.toCacheKeyObject(cacheObjCtx, cacheAdapter.context(), e.getKey(), true));
        mapEntry.unswap();
        assertNotNull("No entry for key: " + e.getKey(), mapEntry);
        assertEquals(mapEntry.version(), e.version());
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 3 with GridNearCacheAdapter

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

the class GridCacheQueryInternalKeysSelfTest method testInternalKeysPreloading.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
@Test
public void testInternalKeysPreloading() throws Exception {
    try {
        IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
        for (int i = 0; i < ENTRY_CNT; i++) cache.put(new GridCacheQueueHeaderKey("queue" + i), 1);
        // Start additional node.
        startGrid(GRID_CNT);
        for (int i = 0; i < ENTRY_CNT; i++) {
            GridCacheQueueHeaderKey internalKey = new GridCacheQueueHeaderKey("queue" + i);
            Collection<ClusterNode> nodes = grid(0).affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(internalKey);
            for (ClusterNode n : nodes) {
                Ignite g = findGridForNodeId(n.id());
                assertNotNull(g);
                assertTrue("Affinity node doesn't contain internal key [key=" + internalKey + ", node=" + n + ']', ((GridNearCacheAdapter) ((IgniteKernal) g).internalCache(DEFAULT_CACHE_NAME)).dht().containsKey(internalKey));
            }
        }
    } finally {
        stopGrid(GRID_CNT);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) GridCacheQueueHeaderKey(org.apache.ignite.internal.processors.datastructures.GridCacheQueueHeaderKey) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 4 with GridNearCacheAdapter

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

the class IgnitePutAllUpdateNonPreloadedPartitionSelfTest method testPessimistic.

/**
 * @throws Exception If failed.
 */
@Test
public void testPessimistic() throws Exception {
    backups = 2;
    startGrids(GRID_CNT - 1);
    try {
        for (int i = 0; i < GRID_CNT - 1; i++) grid(i).cache(DEFAULT_CACHE_NAME).rebalance().get();
        startGrid(GRID_CNT - 1);
        IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
        final int keyCnt = 100;
        try (Transaction tx = grid(0).transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            for (int k = 0; k < keyCnt; k++) cache.get(k);
            for (int k = 0; k < keyCnt; k++) cache.put(k, k);
            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());
                }
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) 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) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with GridNearCacheAdapter

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

the class GridCacheTtlManager method expire.

/**
 * Processes specified amount of expired entries.
 *
 * @param amount Limit of processed entries by single call, {@code -1} for no limit.
 * @return {@code True} if unprocessed expired entries remains.
 */
public boolean expire(int amount) {
    // TTL manager is not initialized or eagerTtl disabled for cache.
    if (!eagerTtlEnabled)
        return false;
    assert cctx != null;
    long now = U.currentTimeMillis();
    try {
        if (pendingEntries != null) {
            GridNearCacheAdapter nearCache = cctx.near();
            GridCacheVersion obsoleteVer = null;
            int limit = (-1 != amount) ? amount : pendingEntries.sizex();
            for (int cnt = limit; cnt > 0; cnt--) {
                EntryWrapper e = pendingEntries.firstx();
                if (e == null || e.expireTime > now)
                    // All expired entries are processed.
                    break;
                if (pendingEntries.remove(e)) {
                    if (obsoleteVer == null)
                        obsoleteVer = cctx.cache().nextVersion();
                    GridNearCacheEntry nearEntry = nearCache.peekExx(e.key);
                    if (nearEntry != null)
                        expireC.apply(nearEntry, obsoleteVer);
                }
            }
        }
        if (!cctx.affinityNode())
            return false;
        if (!hasPendingEntries || nextCleanTime > U.currentTimeMillis())
            return false;
        boolean more = cctx.offheap().expire(dhtCtx, expireC, amount);
        if (more)
            return true;
        // There is nothing to clean, so the next clean up can be postponed.
        nextCleanTime = U.currentTimeMillis() + unwindThrottlingTimeout;
        if (amount != -1 && pendingEntries != null) {
            EntryWrapper e = pendingEntries.firstx();
            return e != null && e.expireTime <= now;
        }
    } catch (GridDhtInvalidPartitionException e) {
        if (log.isDebugEnabled())
            log.debug("Partition became invalid during rebalancing (will ignore): " + e.partition());
        return false;
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to process entry expiration: " + e, e);
    } catch (IgniteException e) {
        if (e.hasCause(NodeStoppingException.class)) {
            if (log.isDebugEnabled())
                log.debug("Failed to expire because node is stopped: " + e);
        } else
            throw e;
    }
    return false;
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) IgniteException(org.apache.ignite.IgniteException)

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 IgniteException (org.apache.ignite.IgniteException)4 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)4 Transaction (org.apache.ignite.transactions.Transaction)4 UUID (java.util.UUID)3 GridNearCacheEntry (org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 Test (org.junit.Test)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