use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class GridFailoverTaskWithPredicateSelfTest method testJobNotFailedOverWithStaticProjection.
/**
* Tests that in case of failover our predicate is intersected with projection
* (logical AND is performed).
*
* @throws Exception If error happens.
*/
public void testJobNotFailedOverWithStaticProjection() throws Exception {
failed.set(false);
routed.set(false);
try {
Ignite ignite1 = startGrid(NODE1);
Ignite ignite2 = startGrid(NODE2);
Ignite ignite3 = startGrid(NODE3);
assert ignite1 != null;
assert ignite2 != null;
assert ignite3 != null;
// Get projection only for first 2 nodes.
ClusterGroup nodes = ignite1.cluster().forNodeIds(Arrays.asList(ignite1.cluster().localNode().id(), ignite2.cluster().localNode().id()));
// On failover NODE3 shouldn't be taken into account.
Integer res = (Integer) compute(nodes.forPredicate(p)).withTimeout(10000).execute(JobFailTask.class.getName(), "1");
assert res == 1;
} catch (ClusterTopologyException ignored) {
failed.set(true);
} finally {
assertTrue(failed.get());
assertFalse(routed.get());
stopGrid(NODE1);
stopGrid(NODE2);
stopGrid(NODE3);
}
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class GridTaskWorker method onNodeLeft.
/**
* @param nodeId Node ID.
*/
void onNodeLeft(UUID nodeId) {
Collection<GridJobExecuteResponse> resList = null;
synchronized (mux) {
// First check if job cares about future responses.
if (state != State.WAITING)
return;
if (jobRes != null) {
for (GridJobResultImpl jr : jobRes.values()) {
if (!jr.hasResponse() && jr.getNode().id().equals(nodeId)) {
if (log.isDebugEnabled())
log.debug("Creating fake response because node left grid [job=" + jr.getJob() + ", nodeId=" + nodeId + ']');
// Artificial response in case if a job is waiting for a response from
// non-existent node.
GridJobExecuteResponse fakeRes = new GridJobExecuteResponse(nodeId, ses.getId(), jr.getJobContext().getJobId(), null, null, null, null, null, null, false, null);
fakeRes.setFakeException(new ClusterTopologyException("Node has left grid: " + nodeId));
if (resList == null)
resList = new ArrayList<>();
resList.add(fakeRes);
}
}
}
}
if (resList == null)
return;
// Simulate responses without holding synchronization.
for (GridJobExecuteResponse res : resList) {
if (log.isDebugEnabled())
log.debug("Simulating fake response from left node [res=" + res + ", nodeId=" + nodeId + ']');
onResponse(res);
}
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class IgniteUtils method exceptionConverters.
/**
* Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
*
* @return Exception converters.
*/
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
}
});
m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureCancelledException(e.getMessage(), e);
}
});
m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureTimeoutException(e.getMessage(), e);
}
});
m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ClusterGroupEmptyException(e.getMessage(), e);
}
});
m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
if (checked.retryReadyFuture() != null)
topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
return topEx;
}
});
m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteDeploymentException(e.getMessage(), e);
}
});
m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskTimeoutException(e.getMessage(), e);
}
});
m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskCancelledException(e.getMessage(), e);
}
});
m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionRollbackException(e.getMessage(), e);
}
});
m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionHeuristicException(e.getMessage(), e);
}
});
m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
if (e.getCause() instanceof TransactionDeadlockException)
return new TransactionTimeoutException(e.getMessage(), e.getCause());
return new TransactionTimeoutException(e.getMessage(), e);
}
});
m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionOptimisticException(e.getMessage(), e);
}
});
m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
}
});
return m;
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class GridEventConsumeSelfTest method testMultithreadedWithNodeRestart.
/**
* @throws Exception If failed.
*/
public void testMultithreadedWithNodeRestart() throws Exception {
final AtomicBoolean stop = new AtomicBoolean();
final BlockingQueue<IgniteBiTuple<Integer, UUID>> queue = new LinkedBlockingQueue<>();
final Collection<UUID> started = new GridConcurrentHashSet<>();
final Collection<UUID> stopped = new GridConcurrentHashSet<>();
final Random rnd = new Random();
IgniteInternalFuture<?> starterFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int i = 0; i < CONSUME_CNT; i++) {
int idx = rnd.nextInt(GRID_CNT);
try {
IgniteEvents evts = grid(idx).events();
UUID consumeId = evts.remoteListenAsync(new P2<UUID, Event>() {
@Override
public boolean apply(UUID uuid, Event evt) {
return true;
}
}, null, EVT_JOB_STARTED).get(3000);
started.add(consumeId);
queue.add(F.t(idx, consumeId));
} catch (ClusterTopologyException ignored) {
// No-op.
}
U.sleep(10);
}
stop.set(true);
return null;
}
}, 8, "consume-starter");
IgniteInternalFuture<?> stopperFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!stop.get()) {
IgniteBiTuple<Integer, UUID> t = queue.poll(1, SECONDS);
if (t == null)
continue;
int idx = t.get1();
UUID consumeId = t.get2();
try {
IgniteEvents evts = grid(idx).events();
evts.stopRemoteListenAsync(consumeId).get(3000);
stopped.add(consumeId);
} catch (ClusterTopologyException ignored) {
// No-op.
}
}
return null;
}
}, 4, "consume-stopper");
IgniteInternalFuture<?> nodeRestarterFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!stop.get()) {
startGrid("anotherGrid");
stopGrid("anotherGrid");
}
return null;
}
}, 1, "node-restarter");
IgniteInternalFuture<?> jobRunnerFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!stop.get()) {
int idx = rnd.nextInt(GRID_CNT);
try {
grid(idx).compute().runAsync(F.noop()).get(3000);
} catch (IgniteException ignored) {
// Ignore all job execution related errors.
}
}
return null;
}
}, 1, "job-runner");
starterFut.get();
stopperFut.get();
nodeRestarterFut.get();
jobRunnerFut.get();
IgniteBiTuple<Integer, UUID> t;
while ((t = queue.poll()) != null) {
int idx = t.get1();
UUID consumeId = t.get2();
grid(idx).events().stopRemoteListenAsync(consumeId).get(3000);
stopped.add(consumeId);
}
Collection<UUID> notStopped = F.lose(started, true, stopped);
assertEquals("Not stopped IDs: " + notStopped, 0, notStopped.size());
}
use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.
the class IgfsUtils method doInTransactionWithRetries.
/**
* Performs an operation with transaction with retries.
*
* @param cache Cache to do the transaction on.
* @param clo Closure.
* @return Result of closure execution.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public static <T> T doInTransactionWithRetries(IgniteInternalCache cache, IgniteOutClosureX<T> clo) throws IgniteCheckedException {
assert cache != null;
int attempts = 0;
while (attempts < MAX_CACHE_TX_RETRIES) {
try (Transaction tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) {
T res = clo.applyx();
tx.commit();
return res;
} catch (IgniteException | IgniteCheckedException e) {
ClusterTopologyException cte = X.cause(e, ClusterTopologyException.class);
if (cte != null)
((IgniteFutureImpl) cte.retryReadyFuture()).internalFuture().getUninterruptibly();
else
throw U.cast(e);
}
attempts++;
}
throw new IgniteCheckedException("Failed to perform operation since max number of attempts " + "exceeded. [maxAttempts=" + MAX_CACHE_TX_RETRIES + ']');
}
Aggregations