use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteDynamicCacheStartStopConcurrentTest method checkTopologyVersion.
/**
* @param topVer Expected version.
*/
private void checkTopologyVersion(AffinityTopologyVersion topVer) {
for (int i = 0; i < NODES; i++) {
IgniteKernal ignite = (IgniteKernal) ignite(i);
assertEquals(ignite.name(), topVer, ignite.context().discovery().topologyVersionEx());
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteTxMultiNodeAbstractTest method nearEntry.
/**
* @param nodeId Node ID.
* @param key Key.
* @return Near entry.
*/
@Nullable
private static GridCacheEntryEx nearEntry(UUID nodeId, Object key) {
Ignite g = G.ignite(nodeId);
GridNearCacheAdapter<Object, Integer> near = ((IgniteKernal) g).<Object, Integer>internalCache(DEFAULT_CACHE_NAME).context().near();
return near.peekEx(key);
}
use of org.apache.ignite.internal.IgniteKernal 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.IgniteKernal in project ignite by apache.
the class IgniteTxAbstractTest method checkCommit.
/**
* @param concurrency Concurrency.
* @param isolation Isolation.
* @throws Exception If check failed.
*/
protected void checkCommit(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
int gridIdx = RAND.nextInt(gridCount());
Ignite ignite = grid(gridIdx);
if (isTestDebug())
debug("Checking commit on grid: " + ignite.cluster().localNode().id());
for (int i = 0; i < iterations(); i++) {
IgniteCache<Integer, String> cache = jcache(gridIdx);
try (Transaction tx = ignite(gridIdx).transactions().txStart(concurrency, isolation, 0, 0)) {
int prevKey = -1;
for (Integer key : getKeys()) {
// Make sure we have the same locking order for all concurrent transactions.
assert key >= prevKey : "key: " + key + ", prevKey: " + prevKey;
if (isTestDebug()) {
AffinityFunction aff = cache.getConfiguration(CacheConfiguration.class).getAffinity();
int part = aff.partition(key);
debug("Key affinity [key=" + key + ", partition=" + part + ", affinity=" + U.toShortString(ignite(gridIdx).affinity(DEFAULT_CACHE_NAME).mapPartitionToPrimaryAndBackups(part)) + ']');
}
String val = Integer.toString(key);
switch(getOp()) {
case READ:
{
if (isTestDebug())
debug("Reading key [key=" + key + ", i=" + i + ']');
val = cache.get(key);
if (isTestDebug())
debug("Read value for key [key=" + key + ", val=" + val + ']');
break;
}
case WRITE:
{
if (isTestDebug())
debug("Writing key and value [key=" + key + ", val=" + val + ", i=" + i + ']');
cache.put(key, val);
break;
}
case REMOVE:
{
if (isTestDebug())
debug("Removing key [key=" + key + ", i=" + i + ']');
cache.remove(key);
break;
}
default:
{
assert false;
}
}
}
tx.commit();
if (isTestDebug())
debug("Committed transaction [i=" + i + ", tx=" + tx + ']');
} catch (TransactionOptimisticException e) {
if (!(concurrency == OPTIMISTIC && isolation == SERIALIZABLE)) {
log.error("Unexpected error: " + e, e);
throw e;
}
} catch (CacheException e) {
MvccFeatureChecker.assertMvccWriteConflict(e);
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
Transaction tx = ignite(gridIdx).transactions().tx();
assertNull("Thread should not have transaction upon completion", tx);
if (printMemoryStats()) {
if (cntr.getAndIncrement() % 100 == 0)
// Print transaction memory stats.
((IgniteKernal) grid(gridIdx)).internalCache(DEFAULT_CACHE_NAME).context().tm().printMemoryStats();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteDynamicClientCacheStartSelfTest method checkNoCache.
/**
* @param ignite Node.
* @param cacheName Cache name.
* @throws Exception If failed.
*/
private void checkNoCache(Ignite ignite, final String cacheName) throws Exception {
GridCacheAdapter<Object, Object> cache = ((IgniteKernal) ignite).context().cache().internalCache(cacheName);
assertNull("Unexpected cache on node " + ignite.name(), cache);
final ClusterNode node = ((IgniteKernal) ignite).localNode();
for (Ignite ignite0 : Ignition.allGrids()) {
final GridDiscoveryManager disco = ((IgniteKernal) ignite0).context().discovery();
if (ignite0 == ignite)
assertFalse(ignite0.name(), disco.cacheNode(node, cacheName));
else {
assertTrue(ignite0.name(), GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return !disco.cacheNode(node, cacheName);
}
}, 5000));
}
assertFalse(disco.cacheAffinityNode(node, cacheName));
assertFalse(disco.cacheNearNode(node, cacheName));
}
}
Aggregations