Search in sources :

Example 41 with FailureContext

use of org.apache.ignite.failure.FailureContext in project ignite by apache.

the class CacheIgniteOutOfMemoryExceptionTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(DATA_REGION_SIZE).setPageEvictionMode(DISABLED).setPersistenceEnabled(false)));
    cfg.setFailureHandler(new AbstractFailureHandler() {

        /**
         * {@inheritDoc}
         */
        @Override
        protected boolean handle(Ignite ignite, FailureContext failureCtx) {
            failure.set(true);
            // Do not invalidate a node context.
            return false;
        }
    });
    cfg.setCacheConfiguration(cacheConfiguration(ATOMIC), cacheConfiguration(TRANSACTIONAL));
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) FailureContext(org.apache.ignite.failure.FailureContext) AbstractFailureHandler(org.apache.ignite.failure.AbstractFailureHandler) Ignite(org.apache.ignite.Ignite)

Example 42 with FailureContext

use of org.apache.ignite.failure.FailureContext in project ignite by apache.

the class DistributedProcess method sendSingleMessage.

/**
 * Sends single node message to coordinator.
 *
 * @param p Process.
 */
private void sendSingleMessage(Process p) {
    assert p.resFut.isDone();
    SingleNodeMessage<R> singleMsg = new SingleNodeMessage<>(p.id, type, p.resFut.result(), (Exception) p.resFut.error());
    UUID crdId = p.crdId;
    if (F.eq(ctx.localNodeId(), crdId))
        onSingleNodeMessageReceived(singleMsg, crdId);
    else {
        try {
            ctx.io().sendToGridTopic(crdId, GridTopic.TOPIC_DISTRIBUTED_PROCESS, singleMsg, SYSTEM_POOL);
        } catch (ClusterTopologyCheckedException e) {
            // The coordinator has failed. The single message will be sent when a new coordinator initialized.
            if (log.isDebugEnabled()) {
                log.debug("Failed to send a single message to coordinator: [crdId=" + crdId + ", processId=" + p.id + ", error=" + e.getMessage() + ']');
            }
        } catch (IgniteCheckedException e) {
            log.error("Unable to send message to coordinator.", e);
            ctx.failure().process(new FailureContext(CRITICAL_ERROR, new Exception("Unable to send message to coordinator.", e)));
        }
    }
}
Also used : CRITICAL_ERROR(org.apache.ignite.failure.FailureType.CRITICAL_ERROR) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FailureContext(org.apache.ignite.failure.FailureContext) UUID(java.util.UUID) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 43 with FailureContext

use of org.apache.ignite.failure.FailureContext in project ignite by apache.

the class IgniteClientRejoinTest method testClientsReconnect.

/**
 * @throws Exception If failed.
 */
@Test
public void testClientsReconnect() throws Exception {
    Ignite srv1 = startGrid("server1");
    crd = ((IgniteKernal) srv1).localNode();
    Ignite srv2 = startGrid("server2");
    block = true;
    List<IgniteInternalFuture<Ignite>> futs = new ArrayList<>();
    final CountDownLatch latch = new CountDownLatch(1);
    final int CLIENTS_NUM = 5;
    for (int i = 0; i < CLIENTS_NUM; i++) {
        final int idx = i;
        IgniteInternalFuture<Ignite> fut = GridTestUtils.runAsync(new Callable<Ignite>() {

            @Override
            public Ignite call() throws Exception {
                latch.await();
                String nodeName = "client" + idx;
                IgniteConfiguration cfg = getConfiguration(nodeName).setFailureHandler(new AbstractFailureHandler() {

                    @Override
                    protected boolean handle(Ignite ignite, FailureContext failureCtx) {
                        // This should _not_ fire when exchange-worker terminates before reconnect.
                        Runtime.getRuntime().halt(Ignition.KILL_EXIT_CODE);
                        return false;
                    }
                });
                return startClientGrid(nodeName, optimize(cfg));
            }
        });
        futs.add(fut);
    }
    GridTestUtils.runAsync(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            latch.countDown();
            Random rnd = new Random();
            U.sleep((rnd.nextInt(15) + 15) * 1000);
            block = false;
            System.out.println(">>> ALLOW connection to coordinator.");
            return true;
        }
    });
    for (IgniteInternalFuture<Ignite> clientFut : futs) {
        Ignite client = clientFut.get();
        IgniteCache<Integer, Integer> cache = client.getOrCreateCache(client.name());
        for (int i = 0; i < 100; i++) cache.put(i, i);
        for (int i = 0; i < 100; i++) assert i == cache.get(i);
    }
    assertEquals(CLIENTS_NUM, srv1.cluster().forClients().nodes().size());
    assertEquals(CLIENTS_NUM, srv2.cluster().forClients().nodes().size());
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) SocketException(java.net.SocketException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) IgniteSpiOperationTimeoutException(org.apache.ignite.spi.IgniteSpiOperationTimeoutException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Random(java.util.Random) FailureContext(org.apache.ignite.failure.FailureContext) AbstractFailureHandler(org.apache.ignite.failure.AbstractFailureHandler) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 44 with FailureContext

use of org.apache.ignite.failure.FailureContext in project ignite by apache.

the class IgnitePdsTaskCancelingTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    cfg.setFailureHandler(new AbstractFailureHandler() {

        @Override
        protected boolean handle(Ignite ignite, FailureContext failureCtx) {
            failure.set(true);
            return true;
        }
    });
    cfg.setCacheConfiguration(new CacheConfiguration().setName(DEFAULT_CACHE_NAME).setAffinity(new RendezvousAffinityFunction(false, NUM_TASKS / 2)));
    cfg.setDataStorageConfiguration(getDataStorageConfiguration());
    // Set the thread pool size according to the NUM_TASKS.
    cfg.setPublicThreadPoolSize(16);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) FailureContext(org.apache.ignite.failure.FailureContext) AbstractFailureHandler(org.apache.ignite.failure.AbstractFailureHandler) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 45 with FailureContext

use of org.apache.ignite.failure.FailureContext in project ignite by apache.

the class FailureProcessorThreadDumpThrottlingTest method testThrottlingPerFailureType.

/**
 * Tests that thread dumps will be throttled per failure type and will be generated again after timeout exceeded.
 */
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE, value = "true")
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE_THROTTLING_TIMEOUT, value = "3000")
public void testThrottlingPerFailureType() throws Exception {
    LogListener dumpLsnr = LogListener.matches(THREAD_DUMP_MSG).times(4).build();
    LogListener throttledLsnr = LogListener.matches("Thread dump is hidden").times(4).build();
    testLog.registerListener(dumpLsnr);
    testLog.registerListener(throttledLsnr);
    IgniteEx ignite = ignite(0);
    FailureContext workerBlockedFailureCtx = new FailureContext(SYSTEM_WORKER_BLOCKED, new Throwable("Failure context error"));
    FailureContext opTimeoutFailureCtx = new FailureContext(SYSTEM_CRITICAL_OPERATION_TIMEOUT, new Throwable("Failure context error"));
    for (int i = 0; i < 2; i++) {
        ignite.context().failure().process(workerBlockedFailureCtx);
        ignite.context().failure().process(opTimeoutFailureCtx);
    }
    U.sleep(3000);
    for (int i = 0; i < 2; i++) {
        ignite.context().failure().process(workerBlockedFailureCtx);
        ignite.context().failure().process(opTimeoutFailureCtx);
    }
    assertTrue(dumpLsnr.check());
    assertTrue(throttledLsnr.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) FailureContext(org.apache.ignite.failure.FailureContext) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

FailureContext (org.apache.ignite.failure.FailureContext)54 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)13 Ignite (org.apache.ignite.Ignite)11 IOException (java.io.IOException)9 AbstractFailureHandler (org.apache.ignite.failure.AbstractFailureHandler)9 IgniteEx (org.apache.ignite.internal.IgniteEx)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 Test (org.junit.Test)9 IgniteException (org.apache.ignite.IgniteException)8 File (java.io.File)6 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)6 StorageException (org.apache.ignite.internal.processors.cache.persistence.StorageException)6 LogListener (org.apache.ignite.testframework.LogListener)5 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)4 ByteBuffer (java.nio.ByteBuffer)3 UUID (java.util.UUID)3 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)3