use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class CacheExchangeMergeTest method checkExchanges.
/**
* @param node Node.
* @param vers Expected exchange versions.
*/
private void checkExchanges(Ignite node, long... vers) {
IgniteKernal node0 = (IgniteKernal) node;
List<AffinityTopologyVersion> expVers = new ArrayList<>();
for (long ver : vers) expVers.add(new AffinityTopologyVersion(ver));
List<AffinityTopologyVersion> doneVers = new ArrayList<>();
List<GridDhtPartitionsExchangeFuture> futs = node0.context().cache().context().exchange().exchangeFutures();
for (int i = futs.size() - 1; i >= 0; i--) {
GridDhtPartitionsExchangeFuture fut = futs.get(i);
if (!fut.isMerged() && fut.exchangeDone() && fut.firstEvent().type() != EVT_DISCOVERY_CUSTOM_EVT) {
AffinityTopologyVersion resVer = fut.topologyVersion();
Assert.assertNotNull(resVer);
doneVers.add(resVer);
}
}
assertEquals(expVers, doneVers);
for (CacheGroupContext grpCtx : node0.context().cache().cacheGroups()) {
for (AffinityTopologyVersion ver : grpCtx.affinity().cachedVersions()) {
if (ver.minorTopologyVersion() > 0)
continue;
assertTrue("Unexpected version [ver=" + ver + ", exp=" + expVers + ']', expVers.contains(ver));
}
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testRandomOperations.
/**
* @throws Exception If failed.
*/
@Test
public void testRandomOperations() throws Exception {
forceSrvMode = true;
final int MAX_SRVS = 10;
final int MAX_CLIENTS = 10;
final int MAX_CACHES = 15;
List<String> srvs = new ArrayList<>();
List<String> clients = new ArrayList<>();
int srvIdx = 0;
int clientIdx = 0;
int cacheIdx = 0;
List<String> caches = new ArrayList<>();
long seed = System.currentTimeMillis();
Random rnd = new Random(seed);
log.info("Random seed: " + seed);
long topVer = 0;
for (int i = 0; i < 100; i++) {
int op = i == 0 ? 0 : rnd.nextInt(7);
log.info("Iteration [iter=" + i + ", op=" + op + ']');
switch(op) {
case 0:
{
if (srvs.size() < MAX_SRVS) {
srvIdx++;
String srvName = "server-" + srvIdx;
log.info("Start server: " + srvName);
if (rnd.nextBoolean()) {
cacheIdx++;
String cacheName = "join-cache-" + cacheIdx;
log.info("Cache for joining node: " + cacheName);
cacheClosure(rnd, caches, cacheName, srvs, srvIdx);
} else
cacheClosure(rnd, caches, DEFAULT_CACHE_NAME, srvs, srvIdx);
startNode(srvName, ++topVer, false);
srvs.add(srvName);
} else
log.info("Skip start server.");
break;
}
case 1:
{
if (srvs.size() > 1) {
String srvName = srvs.get(rnd.nextInt(srvs.size()));
log.info("Stop server: " + srvName);
stopNode(srvName, ++topVer);
srvs.remove(srvName);
} else
log.info("Skip stop server.");
break;
}
case 2:
{
if (clients.size() < MAX_CLIENTS) {
clientIdx++;
String clientName = "client-" + clientIdx;
log.info("Start client: " + clientName);
if (rnd.nextBoolean()) {
cacheIdx++;
String cacheName = "join-cache-" + cacheIdx;
log.info("Cache for joining node: " + cacheName);
cacheClosure(rnd, caches, cacheName, srvs, srvIdx);
} else
cacheClosure(rnd, caches, DEFAULT_CACHE_NAME, srvs, srvIdx);
startNode(clientName, ++topVer, true);
clients.add(clientName);
} else
log.info("Skip start client.");
break;
}
case 3:
{
if (clients.size() > 1) {
String clientName = clients.get(rnd.nextInt(clients.size()));
log.info("Stop client: " + clientName);
stopNode(clientName, ++topVer);
clients.remove(clientName);
} else
log.info("Skip stop client.");
break;
}
case 4:
{
if (!caches.isEmpty()) {
String cacheName = caches.get(rnd.nextInt(caches.size()));
Ignite node = randomNode(rnd, srvs, clients);
log.info("Destroy cache [cache=" + cacheName + ", node=" + node.name() + ']');
node.destroyCache(cacheName);
caches.remove(cacheName);
} else
log.info("Skip destroy cache.");
break;
}
case 5:
{
if (caches.size() < MAX_CACHES) {
cacheIdx++;
String cacheName = "cache-" + cacheIdx;
Ignite node = randomNode(rnd, srvs, clients);
log.info("Create cache [cache=" + cacheName + ", node=" + node.name() + ']');
node.createCache(randomCacheConfiguration(rnd, cacheName, srvs, srvIdx));
calculateAffinity(topVer);
caches.add(cacheName);
} else
log.info("Skip create cache.");
break;
}
case 6:
{
if (!caches.isEmpty()) {
for (int j = 0; j < 3; j++) {
String cacheName = caches.get(rnd.nextInt(caches.size()));
for (int k = 0; k < 3; k++) {
Ignite node = randomNode(rnd, srvs, clients);
log.info("Get/closes cache [cache=" + cacheName + ", node=" + node.name() + ']');
node.cache(cacheName).close();
}
}
} else
log.info("Skip get/close cache.");
break;
}
default:
fail();
}
IgniteKernal node = (IgniteKernal) grid(srvs.get(0));
checkAffinity(srvs.size() + clients.size(), node.context().cache().context().exchange().readyAffinityVersion(), false);
}
srvIdx++;
String srvName = "server-" + srvIdx;
log.info("Start server: " + srvName);
cacheClosure(rnd, caches, DEFAULT_CACHE_NAME, srvs, srvIdx);
startNode(srvName, ++topVer, false);
srvs.add(srvName);
checkAffinity(srvs.size() + clients.size(), topVer(topVer, 1), true);
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheRebalancingSyncSelfTest method testSimpleRebalancing.
/**
* @throws Exception If failed.
*/
@Test
public void testSimpleRebalancing() throws Exception {
IgniteKernal ignite = (IgniteKernal) startGrid(0);
generateData(ignite, 0, 0);
log.info("Preloading started.");
long start = System.currentTimeMillis();
startGrid(1);
awaitPartitionMapExchange(true, true, null, true);
checkPartitionMapExchangeFinished();
awaitPartitionMessagesAbsent();
stopGrid(0);
awaitPartitionMapExchange(true, true, null, true);
checkPartitionMapExchangeFinished();
awaitPartitionMessagesAbsent();
startGrid(2);
awaitPartitionMapExchange(true, true, null, true);
checkPartitionMapExchangeFinished();
awaitPartitionMessagesAbsent();
stopGrid(2);
awaitPartitionMapExchange(true, true, null, true);
checkPartitionMapExchangeFinished();
awaitPartitionMessagesAbsent();
long spend = (System.currentTimeMillis() - start) / 1000;
checkData(grid(1), 0, 0);
log.info("Spend " + spend + " seconds to rebalance entries.");
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class TxRollbackAsyncTest method testSynchronousRollback0.
/**
* @param holdLockNode Node holding the write lock.
* @param tryLockNode Node trying to acquire lock.
* @param useTimeout {@code True} if need to start tx with timeout.
* @throws Exception If failed.
*/
private void testSynchronousRollback0(Ignite holdLockNode, final Ignite tryLockNode, final boolean useTimeout) throws Exception {
final GridFutureAdapter<Void> keyLocked = new GridFutureAdapter<>();
CountDownLatch waitCommit = new CountDownLatch(1);
// Used for passing tx instance to rollback thread.
IgniteInternalFuture<?> lockFut = lockInTx(holdLockNode, keyLocked, waitCommit, 0);
keyLocked.get();
final int txCnt = SF.applyLB(250, 25);
final IgniteKernal k = (IgniteKernal) tryLockNode;
final GridCacheSharedContext<Object, Object> ctx = k.context().cache().context();
final GridCacheContext<Object, Object> cctx = ctx.cacheContext(CU.cacheId(CACHE_NAME));
GridFutureAdapter<Transaction> txReadyFut = new GridFutureAdapter<>();
long seed = System.currentTimeMillis();
Random r = new Random(seed);
log.info("Running: node0=" + holdLockNode.cluster().localNode().consistentId() + ", node1=" + tryLockNode.cluster().localNode().consistentId() + ", useTimeout=" + useTimeout + ", seed=" + seed);
IgniteInternalFuture<?> txFut = multithreadedAsync(new Runnable() {
@Override
public void run() {
for (int i = 0; i < txCnt; i++) {
GridNearTxLocal tx0 = ctx.tm().threadLocalTx(cctx);
assertTrue(tx0 == null || tx0.state() == ROLLED_BACK);
try (Transaction tx = tryLockNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, useTimeout ? 50 : 0, 1)) {
txReadyFut.onDone(tx);
// Will block on lock request until rolled back asynchronously.
Object o = tryLockNode.cache(CACHE_NAME).getAndPut(0, 0);
// If rolled back by close, previous get will return null.
assertNull(o);
} catch (Exception ignore) {
// If rolled back by rollback, previous get will throw an exception.
}
}
txReadyFut.onDone((Transaction) null);
}
}, 1, "tx-get-thread");
IgniteInternalFuture<?> rollbackFut = multithreadedAsync(new Runnable() {
@Override
public void run() {
Set<IgniteUuid> rolledBackVers = new HashSet<>();
int proc = 1;
while (true) {
try {
Transaction tx = txReadyFut.get();
txReadyFut.reset();
if (tx == null)
break;
// Wait a bit to reduce chance of rolling back empty transactions.
doSleep(r.nextInt(15));
if (rolledBackVers.contains(tx.xid()))
fail("Rollback version is expected");
try {
if (proc % 2 == 0)
tx.rollback();
else
tx.close();
} catch (IgniteException e) {
log.warning("Got exception while rolling back a transaction", e);
}
rolledBackVers.add(tx.xid());
if (proc % 100 == 0)
log.info("Rolled back: " + proc);
proc++;
} catch (IgniteCheckedException e) {
fail(e.getMessage());
}
}
}
}, 1, "tx-rollback-thread");
rollbackFut.get();
txFut.get();
log.info("All transactions are rolled back: holdLockNode=" + holdLockNode + ", tryLockNode=" + tryLockNode);
waitCommit.countDown();
lockFut.get();
assertEquals(0, holdLockNode.cache(CACHE_NAME).get(0));
checkFutures();
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class TxOptimisticPrepareOnUnstableTopologyTest method doPrepareOnUnstableTopology.
/**
* @param keys Keys.
* @param testClient Test client.
* @param isolation Isolation.
* @param timeout Timeout.
*/
private void doPrepareOnUnstableTopology(int keys, boolean testClient, TransactionIsolation isolation, long timeout) throws Exception {
GridCompoundFuture<Void, Object> compFut = new GridCompoundFuture<>();
AtomicBoolean stopFlag = new AtomicBoolean();
try {
int clientIdx = testClient ? 1 : -1;
try {
for (int i = 0; i < GRID_CNT; i++) {
IgniteEx grid;
if (clientIdx == i)
grid = startClientGrid(i);
else
grid = startGrid(i);
assertEquals(clientIdx == i, grid.configuration().isClientMode().booleanValue());
IgniteInternalFuture<Void> fut = runCacheOperationsAsync(grid, stopFlag, isolation, timeout, keys);
compFut.add(fut);
U.sleep(STARTUP_DELAY);
}
} finally {
stopFlag.set(true);
}
compFut.markInitialized();
compFut.get();
for (int i = 0; i < GRID_CNT; i++) {
IgniteTxManager tm = ((IgniteKernal) grid(i)).internalCache(CACHE_NAME).context().tm();
assertEquals("txMap is not empty: " + i, 0, tm.idMapSize());
}
} finally {
stopAllGrids();
}
}
Aggregations