use of org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException in project ignite by apache.
the class GridDistributedCacheAdapter method removeAll.
/**
* {@inheritDoc}
*/
@Override
public void removeAll() throws IgniteCheckedException {
try {
AffinityTopologyVersion topVer;
boolean retry;
CacheOperationContext opCtx = ctx.operationContextPerCall();
boolean skipStore = opCtx != null && opCtx.skipStore();
boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
do {
retry = false;
topVer = ctx.affinity().affinityTopologyVersion();
// Send job to all data nodes.
Collection<ClusterNode> nodes = ctx.grid().cluster().forDataNodes(name()).nodes();
if (!nodes.isEmpty()) {
ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
retry = !ctx.kernalContext().task().execute(new RemoveAllTask(ctx.name(), topVer, skipStore, keepBinary), null).get();
}
} while (ctx.affinity().affinityTopologyVersion().compareTo(topVer) != 0 || retry);
} catch (ClusterGroupEmptyCheckedException ignore) {
if (log.isDebugEnabled())
log.debug("All remote nodes left while cache remove [cacheName=" + name() + "]");
}
}
use of org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException in project ignite by apache.
the class GridTaskWorker method body.
/**
* Maps this task's jobs to nodes and sends them out.
*/
@SuppressWarnings({ "unchecked" })
@Override
protected void body() {
evtLsnr.onTaskStarted(this);
try {
// Use either user task or deployed one.
if (task == null) {
assert taskCls != null;
assert ComputeTask.class.isAssignableFrom(taskCls);
try {
task = newTask((Class<? extends ComputeTask<T, R>>) taskCls);
} catch (IgniteCheckedException e) {
// If cannot instantiate task, then assign internal flag based
// on information available.
internal = dep.internalTask(null, taskCls);
recordTaskEvent(EVT_TASK_STARTED, "Task started.");
throw e;
}
}
internal = ses.isInternal();
recordTaskEvent(EVT_TASK_STARTED, "Task started.");
initializeSpis();
ses.setClassLoader(dep.classLoader());
// Nodes are ignored by affinity tasks.
final List<ClusterNode> shuffledNodes = affCacheIds == null ? getTaskTopology() : Collections.<ClusterNode>emptyList();
// Load balancer.
ComputeLoadBalancer balancer = ctx.loadBalancing().getLoadBalancer(ses, shuffledNodes);
continuous = ctx.resource().isAnnotationPresent(dep, task, TaskContinuousMapperResource.class);
if (log.isDebugEnabled())
log.debug("Injected task resources [continuous=" + continuous + ']');
// Inject resources.
ctx.resource().inject(dep, task, ses, balancer, mapper);
Map<? extends ComputeJob, ClusterNode> mappedJobs = U.wrapThreadLoader(dep.classLoader(), new Callable<Map<? extends ComputeJob, ClusterNode>>() {
@Override
public Map<? extends ComputeJob, ClusterNode> call() {
return task.map(shuffledNodes, arg);
}
});
if (log.isDebugEnabled())
log.debug("Mapped task jobs to nodes [jobCnt=" + (mappedJobs != null ? mappedJobs.size() : 0) + ", mappedJobs=" + mappedJobs + ", ses=" + ses + ']');
if (F.isEmpty(mappedJobs)) {
synchronized (mux) {
// Check if some jobs are sent from continuous mapper.
if (F.isEmpty(jobRes))
throw new IgniteCheckedException("Task map operation produced no mapped jobs: " + ses);
}
} else
processMappedJobs(mappedJobs);
synchronized (mux) {
lockRespProc = false;
}
processDelayedResponses();
} catch (ClusterGroupEmptyCheckedException e) {
U.warn(log, "Failed to map task jobs to nodes (topology projection is empty): " + ses);
finishTask(null, e);
} catch (IgniteException | IgniteCheckedException e) {
if (!fut.isCancelled()) {
if (!(e instanceof VisorClusterGroupEmptyException))
U.error(log, "Failed to map task jobs to nodes: " + ses, e);
finishTask(null, e);
} else if (log.isDebugEnabled())
log.debug("Failed to map task jobs to nodes due to task cancellation: " + ses);
}// Catch throwable to protect against bad user code.
catch (Throwable e) {
String errMsg = "Failed to map task jobs to nodes due to undeclared user exception" + " [cause=" + e.getMessage() + ", ses=" + ses + "]";
U.error(log, errMsg, e);
finishTask(null, new ComputeUserUndeclaredException(errMsg, e));
if (e instanceof Error)
throw e;
}
}
use of org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException in project ignite by apache.
the class GridCacheUtils method retryTopologySafe.
/**
* @param c Closure to retry.
* @throws IgniteCheckedException If failed.
* @return Closure result.
*/
public static <S> S retryTopologySafe(final Callable<S> c) throws IgniteCheckedException {
IgniteCheckedException err = null;
for (int i = 0; i < GridCacheAdapter.MAX_RETRIES; i++) {
try {
return c.call();
} catch (ClusterGroupEmptyCheckedException | ClusterTopologyServerNotFoundException e) {
throw e;
} catch (TransactionRollbackException e) {
if (i + 1 == GridCacheAdapter.MAX_RETRIES)
throw e;
U.sleep(1);
} catch (IgniteCheckedException e) {
if (i + 1 == GridCacheAdapter.MAX_RETRIES)
throw e;
if (X.hasCause(e, ClusterTopologyCheckedException.class)) {
ClusterTopologyCheckedException topErr = e.getCause(ClusterTopologyCheckedException.class);
if (topErr instanceof ClusterGroupEmptyCheckedException || topErr instanceof ClusterTopologyServerNotFoundException)
throw e;
// IGNITE-1948: remove this check when the issue is fixed
if (topErr.retryReadyFuture() != null)
topErr.retryReadyFuture().get();
else
U.sleep(1);
} else if (X.hasCause(e, IgniteTxRollbackCheckedException.class, CachePartialUpdateCheckedException.class))
U.sleep(1);
else
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IgniteCheckedException(e);
}
}
// Should never happen.
throw err;
}
use of org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException in project ignite by apache.
the class GridTaskWorker method getTaskTopology.
/**
* @return Topology for this task.
* @throws IgniteCheckedException Thrown in case of any error.
*/
private List<ClusterNode> getTaskTopology() throws IgniteCheckedException {
Collection<UUID> top = ses.getTopology();
Collection<? extends ClusterNode> subgrid = top != null ? ctx.discovery().nodes(top) : ctx.discovery().allNodes();
int size = subgrid.size();
if (size == 0)
throw new ClusterGroupEmptyCheckedException("Topology projection is empty.");
List<ClusterNode> shuffledNodes = new ArrayList<>(size);
for (ClusterNode node : subgrid) shuffledNodes.add(node);
if (shuffledNodes.size() > 1)
// Shuffle nodes prior to giving them to user.
Collections.shuffle(shuffledNodes);
// Load balancer.
return shuffledNodes;
}
use of org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException in project ignite by apache.
the class GridFutureAdapterSelfTest method checkChaining.
/**
* @param exec Executor for chain callback.
* @throws Exception If failed.
*/
@SuppressWarnings("ErrorNotRethrown")
private void checkChaining(ExecutorService exec) throws Exception {
final CX1<IgniteInternalFuture<Object>, Object> passThrough = new CX1<IgniteInternalFuture<Object>, Object>() {
@Override
public Object applyx(IgniteInternalFuture<Object> f) throws IgniteCheckedException {
return f.get();
}
};
GridFutureAdapter<Object> fut = new GridFutureAdapter<>();
IgniteInternalFuture<Object> chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
assertFalse(fut.isDone());
assertFalse(chain.isDone());
try {
chain.get(20);
fail("Expects timeout exception.");
} catch (IgniteFutureTimeoutCheckedException e) {
info("Expected timeout exception: " + e.getMessage());
}
fut.onDone("result");
assertEquals("result", chain.get(1));
// Test exception re-thrown.
fut = new GridFutureAdapter<>();
chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
fut.onDone(new ClusterGroupEmptyCheckedException("test exception"));
try {
chain.get();
fail("Expects failed with exception.");
} catch (ClusterGroupEmptyCheckedException e) {
info("Expected exception: " + e.getMessage());
}
// Test error re-thrown.
fut = new GridFutureAdapter<>();
chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
try {
fut.onDone(new StackOverflowError("test error"));
if (exec == null)
fail("Expects failed with error.");
} catch (StackOverflowError e) {
info("Expected error: " + e.getMessage());
}
try {
chain.get();
fail("Expects failed with error.");
} catch (StackOverflowError e) {
info("Expected error: " + e.getMessage());
}
}
Aggregations