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