Search in sources :

Example 1 with ClusterGroupEmptyCheckedException

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() + "]");
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException)

Example 2 with ClusterGroupEmptyCheckedException

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;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeTask(org.apache.ignite.compute.ComputeTask) ComputeUserUndeclaredException(org.apache.ignite.compute.ComputeUserUndeclaredException) TaskContinuousMapperResource(org.apache.ignite.resources.TaskContinuousMapperResource) ComputeJob(org.apache.ignite.compute.ComputeJob) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) ComputeLoadBalancer(org.apache.ignite.compute.ComputeLoadBalancer) VisorClusterGroupEmptyException(org.apache.ignite.internal.visor.util.VisorClusterGroupEmptyException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ClusterGroupEmptyCheckedException

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;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) GridDistributedLockCancelledException(org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) CacheAtomicUpdateTimeoutException(org.apache.ignite.cache.CacheAtomicUpdateTimeoutException) IgniteException(org.apache.ignite.IgniteException) CacheWriterException(javax.cache.integration.CacheWriterException) CacheException(javax.cache.CacheException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 4 with ClusterGroupEmptyCheckedException

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 5 with ClusterGroupEmptyCheckedException

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());
    }
}
Also used : ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CX1(org.apache.ignite.internal.util.typedef.CX1)

Aggregations

ClusterGroupEmptyCheckedException (org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 CacheException (javax.cache.CacheException)1 CacheWriterException (javax.cache.integration.CacheWriterException)1 CacheAtomicUpdateTimeoutException (org.apache.ignite.cache.CacheAtomicUpdateTimeoutException)1 CachePartialUpdateException (org.apache.ignite.cache.CachePartialUpdateException)1 CacheServerNotFoundException (org.apache.ignite.cache.CacheServerNotFoundException)1 ComputeJob (org.apache.ignite.compute.ComputeJob)1 ComputeLoadBalancer (org.apache.ignite.compute.ComputeLoadBalancer)1 ComputeTask (org.apache.ignite.compute.ComputeTask)1 ComputeUserUndeclaredException (org.apache.ignite.compute.ComputeUserUndeclaredException)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1