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