use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class GridTaskFailoverSelfTest method testFailover.
/**
* @throws Exception If test failed.
*/
@SuppressWarnings("unchecked")
public void testFailover() throws Exception {
Ignite ignite = startGrid();
try {
ignite.compute().localDeployTask(GridFailoverTestTask.class, GridFailoverTestTask.class.getClassLoader());
ComputeTaskFuture<?> fut = ignite.compute().execute(GridFailoverTestTask.class.getName(), null);
assert fut != null;
fut.get();
assert false : "Should never be reached due to exception thrown.";
} catch (ClusterTopologyException e) {
info("Received correct exception: " + e);
} finally {
stopGrid();
}
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class IgniteBinaryMetadataUpdateNodeRestartTest method testNodeRestart.
/**
* @throws Exception If failed.
*/
public void testNodeRestart() throws Exception {
for (int i = 0; i < 10; i++) {
log.info("Iteration: " + i);
client = false;
startGridsMultiThreaded(SRVS);
client = true;
startGrid(SRVS);
final AtomicBoolean stop = new AtomicBoolean();
try {
IgniteInternalFuture<?> restartFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!stop.get()) {
log.info("Start node.");
startGrid(SRVS + CLIENTS);
log.info("Stop node.");
stopGrid(SRVS + CLIENTS);
}
return null;
}
}, "restart-thread");
final AtomicInteger idx = new AtomicInteger();
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int threadIdx = idx.getAndIncrement();
int node = threadIdx % (SRVS + CLIENTS);
Ignite ignite = ignite(node);
log.info("Started thread: " + ignite.name());
Thread.currentThread().setName("update-thread-" + threadIdx + "-" + ignite.name());
IgniteCache<Object, Object> cache1 = ignite.cache(ATOMIC_CACHE);
IgniteCache<Object, Object> cache2 = ignite.cache(TX_CACHE);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (!stop.get()) {
try {
cache1.put(new TestClass1(true), create(rnd.nextInt(20) + 1));
cache1.invoke(new TestClass1(true), new TestEntryProcessor(rnd.nextInt(20) + 1));
cache2.put(new TestClass1(true), create(rnd.nextInt(20) + 1));
cache2.invoke(new TestClass1(true), new TestEntryProcessor(rnd.nextInt(20) + 1));
} catch (CacheException | IgniteException e) {
log.info("Error: " + e);
if (X.hasCause(e, ClusterTopologyException.class)) {
ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
if (cause.retryReadyFuture() != null)
cause.retryReadyFuture().get();
}
}
}
return null;
}
}, 10, "update-thread");
U.sleep(5_000);
stop.set(true);
restartFut.get();
fut.get();
} finally {
stop.set(true);
stopAllGrids();
}
}
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class IgniteBenchmarkUtils method doInTransaction.
/**
* @param igniteTx Ignite transaction.
* @param txConcurrency Transaction concurrency.
* @param clo Closure.
* @return Result of closure execution.
* @throws Exception If failed.
*/
public static <T> T doInTransaction(IgniteTransactions igniteTx, TransactionConcurrency txConcurrency, TransactionIsolation txIsolation, Callable<T> clo) throws Exception {
while (true) {
try (Transaction tx = igniteTx.txStart(txConcurrency, txIsolation)) {
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) {
e.retryReadyFuture().get();
} catch (TransactionRollbackException | TransactionOptimisticException ignore) {
// Safe to retry right away.
}
}
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class WebSessionFilter method handleCacheOperationException.
/**
* Handles cache operation exception.
* @param e Exception
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
void handleCacheOperationException(Exception e) {
IgniteFuture<?> retryFut = null;
if (e instanceof IllegalStateException) {
initCache();
return;
} else if (X.hasCause(e, IgniteClientDisconnectedException.class)) {
IgniteClientDisconnectedException cause = X.cause(e, IgniteClientDisconnectedException.class);
assert cause != null : e;
retryFut = cause.reconnectFuture();
} else if (X.hasCause(e, ClusterTopologyException.class)) {
ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
assert cause != null : e;
retryFut = cause.retryReadyFuture();
}
if (retryFut != null) {
try {
retryFut.get(retriesTimeout);
} catch (IgniteException retryErr) {
throw new IgniteException("Failed to wait for retry: " + retryErr);
}
}
}
Aggregations