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);
}
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());
}
}
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);
}
}
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();
}
}
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;
}
Aggregations