Search in sources :

Example 11 with ClusterTopologyException

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);
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Example 12 with ClusterTopologyException

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

Example 13 with ClusterTopologyException

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;
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TransactionHeuristicException(org.apache.ignite.transactions.TransactionHeuristicException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) C1(org.apache.ignite.internal.util.typedef.C1) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) ComputeTaskCancelledException(org.apache.ignite.compute.ComputeTaskCancelledException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 14 with ClusterTopologyException

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());
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteException(org.apache.ignite.IgniteException) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) IgniteEvents(org.apache.ignite.IgniteEvents) IgniteException(org.apache.ignite.IgniteException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) JobEvent(org.apache.ignite.events.JobEvent) Event(org.apache.ignite.events.Event) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) UUID(java.util.UUID)

Example 15 with ClusterTopologyException

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 + ']');
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(org.apache.ignite.transactions.Transaction) IGNITE_CACHE_RETRIES_COUNT(org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Aggregations

ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)19 Ignite (org.apache.ignite.Ignite)9 IgniteException (org.apache.ignite.IgniteException)8 CacheException (javax.cache.CacheException)7 Transaction (org.apache.ignite.transactions.Transaction)6 HashMap (java.util.HashMap)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 UUID (java.util.UUID)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 TransactionRollbackException (org.apache.ignite.transactions.TransactionRollbackException)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Random (java.util.Random)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2