use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class CacheAffinityCallSelfTest method testAffinityCallNoServerNode.
/**
* @throws Exception If failed.
*/
public void testAffinityCallNoServerNode() throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-1741");
startGridsMultiThreaded(SRVS + 1);
final Integer key = 1;
final Ignite client = grid(SRVS);
assertTrue(client.configuration().isClientMode());
final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int i = 0; i < SRVS; ++i) stopGrid(i, false);
return null;
}
});
try {
while (!fut.isDone()) client.compute().affinityCall(CACHE_NAME, key, new CheckCallable(key, null));
} catch (ClusterTopologyException e) {
log.info("Expected error: " + e);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class IgniteCacheNearRestartRollbackSelfTest method updateCache.
/**
* Updates the cache or rollback the update.
*
* @param ignite Ignite instance to use.
* @param newVal the new value to put to the entries
* @param invoke whether to use invokeAll() or putAll()
* @param rollback whether to rollback the changes or commit
* @param keys Collection of keys to update.
*/
private void updateCache(Ignite ignite, int newVal, boolean invoke, boolean rollback, Set<Integer> keys) {
final IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
if (rollback) {
while (true) {
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
updateEntries(cache, newVal, invoke, keys);
tx.rollback();
break;
} catch (CacheException e) {
if (e.getCause() instanceof ClusterTopologyException) {
ClusterTopologyException topEx = (ClusterTopologyException) e.getCause();
topEx.retryReadyFuture().get();
} else
throw e;
} catch (ClusterTopologyException e) {
IgniteFuture<?> fut = e.retryReadyFuture();
fut.get();
} catch (TransactionRollbackException ignore) {
// Safe to retry right away.
}
}
} else
updateEntries(cache, newVal, invoke, keys);
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class IgniteClientReconnectMassiveShutdownTest method massiveServersShutdown.
/**
* @param stopType How tp stop node.
* @throws Exception If any error occurs.
*/
private void massiveServersShutdown(final StopType stopType) throws Exception {
clientMode = false;
startGridsMultiThreaded(GRID_CNT);
clientMode = true;
startGridsMultiThreaded(GRID_CNT, CLIENT_GRID_CNT);
final AtomicBoolean done = new AtomicBoolean();
// Starting a cache dynamically.
Ignite client = grid(GRID_CNT);
assertTrue(client.configuration().isClientMode());
final CacheConfiguration<String, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
cfg.setCacheMode(PARTITIONED);
cfg.setAtomicityMode(TRANSACTIONAL);
cfg.setBackups(2);
IgniteCache<String, Integer> cache = client.getOrCreateCache(cfg);
assertNotNull(cache);
HashMap<String, Integer> put = new HashMap<>();
// Load some data.
for (int i = 0; i < 10_000; i++) put.put(String.valueOf(i), i);
cache.putAll(put);
// Preparing client nodes and starting cache operations from them.
final BlockingQueue<Integer> clientIdx = new LinkedBlockingQueue<>();
for (int i = GRID_CNT; i < GRID_CNT + CLIENT_GRID_CNT; i++) clientIdx.add(i);
final CountDownLatch latch = new CountDownLatch(CLIENT_GRID_CNT);
IgniteInternalFuture<?> clientsFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
int idx = clientIdx.take();
Ignite ignite = grid(idx);
Thread.currentThread().setName("client-thread-" + ignite.name());
assertTrue(ignite.configuration().isClientMode());
IgniteCache<String, Integer> cache = ignite.getOrCreateCache(cfg);
assertNotNull(cache);
IgniteTransactions txs = ignite.transactions();
Random rand = new Random();
latch.countDown();
while (!done.get()) {
try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(String.valueOf(rand.nextInt(10_000)), rand.nextInt(50_000));
tx.commit();
} catch (ClusterTopologyException ex) {
ex.retryReadyFuture().get();
} catch (IgniteException | CacheException e) {
if (X.hasCause(e, IgniteClientDisconnectedException.class)) {
IgniteClientDisconnectedException cause = X.cause(e, IgniteClientDisconnectedException.class);
assert cause != null;
cause.reconnectFuture().get();
} else if (X.hasCause(e, ClusterTopologyException.class)) {
ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
assert cause != null;
cause.retryReadyFuture().get();
} else
throw e;
}
}
return null;
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
}, CLIENT_GRID_CNT, "client-thread");
try {
if (!latch.await(30, SECONDS)) {
log.warning("Failed to wait for for clients start.");
U.dumpThreads(log);
fail("Failed to wait for for clients start.");
}
// Killing a half of server nodes.
final int srvsToKill = GRID_CNT / 2;
final BlockingQueue<Integer> victims = new LinkedBlockingQueue<>();
for (int i = 0; i < srvsToKill; i++) victims.add(i);
final BlockingQueue<Integer> assassins = new LinkedBlockingQueue<>();
for (int i = srvsToKill; i < GRID_CNT; i++) assassins.add(i);
IgniteInternalFuture<?> srvsShutdownFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Thread.sleep(5_000);
Ignite assassin = grid(assassins.take());
assertFalse(assassin.configuration().isClientMode());
Ignite victim = grid(victims.take());
assertFalse(victim.configuration().isClientMode());
log.info("Kill node [node=" + victim.name() + ", from=" + assassin.name() + ']');
switch(stopType) {
case CLOSE:
victim.close();
break;
case FAIL_EVENT:
UUID nodeId = victim.cluster().localNode().id();
assassin.configuration().getDiscoverySpi().failNode(nodeId, null);
break;
case SIMULATE_FAIL:
((TcpDiscoverySpi) victim.configuration().getDiscoverySpi()).simulateNodeFailure();
break;
default:
fail();
}
return null;
}
}, assassins.size(), "kill-thread");
srvsShutdownFut.get();
Thread.sleep(15_000);
done.set(true);
clientsFut.get();
awaitPartitionMapExchange();
for (int k = 0; k < 10_000; k++) {
String key = String.valueOf(k);
Object val = cache.get(key);
for (int i = srvsToKill; i < GRID_CNT; i++) assertEquals(val, ignite(i).cache(DEFAULT_CACHE_NAME).get(key));
}
} finally {
done.set(true);
}
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class GridCommonAbstractTest method doInTransaction.
/**
* @param ignite Ignite instance.
* @param concurrency Transaction concurrency.
* @param isolation Transaction isolation.
* @param clo Closure.
* @return Result of closure execution.
* @throws Exception If failed.
*/
protected static <T> T doInTransaction(Ignite ignite, TransactionConcurrency concurrency, TransactionIsolation isolation, Callable<T> clo) throws Exception {
while (true) {
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
T res = clo.call();
tx.commit();
return res;
} catch (CacheException e) {
if (e.getCause() instanceof ClusterTopologyException) {
ClusterTopologyException topEx = (ClusterTopologyException) e.getCause();
topEx.retryReadyFuture().get();
} else
throw e;
} catch (ClusterTopologyException e) {
IgniteFuture<?> fut = e.retryReadyFuture();
fut.get();
} catch (TransactionRollbackException ignore) {
// Safe to retry right away.
}
}
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class IgniteComputeTopologyExceptionTest method testCorrectException.
/**
* @throws Exception If failed.
*/
public void testCorrectException() throws Exception {
Ignite ignite = ignite(0);
IgniteCompute comp = ignite.compute(ignite.cluster().forRemotes()).withNoFailover();
stopGrid(1);
try {
comp.call(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
fail("Should not be called.");
return null;
}
});
fail();
} catch (ClusterTopologyException e) {
log.info("Expected exception: " + e);
}
}
Aggregations