Search in sources :

Example 1 with FailureHandler

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

the class FailureProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    FailureHandler hnd = ctx.config().getFailureHandler();
    if (hnd == null)
        hnd = getDefaultFailureHandler();
    reserveBuf = new byte[IgniteSystemProperties.getInteger(IGNITE_FAILURE_HANDLER_RESERVE_BUFFER_SIZE, DFLT_FAILURE_HANDLER_RESERVE_BUFFER_SIZE)];
    assert hnd != null;
    this.hnd = hnd;
    U.quietAndInfo(log, "Configured failure handler: [hnd=" + hnd + ']');
}
Also used : FailureHandler(org.apache.ignite.failure.FailureHandler) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) AbstractFailureHandler(org.apache.ignite.failure.AbstractFailureHandler) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler)

Example 2 with FailureHandler

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

the class GridCacheContinuousQueryNodesFilteringTest method testNodeWithAttributeFailure.

/**
 * Test that node matched by filter and having filter instantiation problems fails for sure.
 *
 * @throws Exception if failed.
 */
@Test
public void testNodeWithAttributeFailure() throws Exception {
    try (Ignite node1 = startNodeWithCache()) {
        CountDownLatch latch = new CountDownLatch(1);
        FailureHandler failHnd = new TestFailureHandler(false, latch);
        IgniteConfiguration node2Cfg = getConfiguration("node2", true, null).setFailureHandler(failHnd);
        try (Ignite node2 = startGrid(node2Cfg)) {
            assertTrue("Failure handler hasn't been invoked on the joined node.", latch.await(5, TimeUnit.SECONDS));
        }
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestFailureHandler(org.apache.ignite.failure.TestFailureHandler) FailureHandler(org.apache.ignite.failure.FailureHandler) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) TestFailureHandler(org.apache.ignite.failure.TestFailureHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with FailureHandler

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

the class PlatformConfigurationUtils method writeIgniteConfiguration.

/**
 * Writes Ignite configuration.
 *
 * @param w Writer.
 * @param cfg Configuration.
 */
@SuppressWarnings("deprecation")
public static void writeIgniteConfiguration(BinaryRawWriter w, IgniteConfiguration cfg) {
    assert w != null;
    assert cfg != null;
    w.writeBoolean(true);
    w.writeBoolean(cfg.isClientMode());
    w.writeIntArray(cfg.getIncludeEventTypes());
    w.writeBoolean(true);
    w.writeLong(cfg.getMetricsExpireTime());
    w.writeBoolean(true);
    w.writeInt(cfg.getMetricsHistorySize());
    w.writeBoolean(true);
    w.writeLong(cfg.getMetricsLogFrequency());
    w.writeBoolean(true);
    w.writeLong(cfg.getMetricsUpdateFrequency());
    w.writeBoolean(true);
    w.writeInt(cfg.getNetworkSendRetryCount());
    w.writeBoolean(true);
    w.writeLong(cfg.getNetworkSendRetryDelay());
    w.writeBoolean(true);
    w.writeLong(cfg.getNetworkTimeout());
    w.writeString(cfg.getWorkDirectory());
    w.writeString(cfg.getLocalHost());
    w.writeBoolean(true);
    w.writeBoolean(cfg.isDaemon());
    w.writeBoolean(true);
    w.writeLong(cfg.getFailureDetectionTimeout());
    w.writeBoolean(true);
    w.writeLong(cfg.getClientFailureDetectionTimeout());
    w.writeBoolean(true);
    w.writeLong(cfg.getLongQueryWarningTimeout());
    w.writeBoolean(true);
    w.writeBoolean(cfg.isActiveOnStart());
    w.writeBoolean(true);
    w.writeBoolean(cfg.isAuthenticationEnabled());
    w.writeBoolean(true);
    w.writeLong(cfg.getMvccVacuumFrequency());
    w.writeBoolean(true);
    w.writeInt(cfg.getMvccVacuumThreadCount());
    if (cfg.getSystemWorkerBlockedTimeout() != null) {
        w.writeBoolean(true);
        w.writeLong(cfg.getSystemWorkerBlockedTimeout());
    } else {
        w.writeBoolean(false);
    }
    w.writeBoolean(true);
    w.writeInt(cfg.getSqlQueryHistorySize());
    w.writeBoolean(true);
    w.writeBoolean(cfg.isPeerClassLoadingEnabled());
    w.writeBoolean(true);
    w.writeInt(getAsyncContinuationExecutorMode(cfg.getAsyncContinuationExecutor()));
    if (cfg.getSqlSchemas() == null)
        w.writeInt(0);
    else {
        w.writeInt(cfg.getSqlSchemas().length);
        for (String schema : cfg.getSqlSchemas()) w.writeString(schema);
    }
    w.writeObject(cfg.getConsistentId());
    // Thread pools.
    w.writeBoolean(true);
    w.writeInt(cfg.getPublicThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getStripedPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getServiceThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getSystemThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getAsyncCallbackPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getManagementThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getDataStreamerThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getUtilityCacheThreadPoolSize());
    w.writeBoolean(true);
    w.writeInt(cfg.getQueryThreadPoolSize());
    CacheConfiguration[] cacheCfg = cfg.getCacheConfiguration();
    if (cacheCfg != null) {
        w.writeInt(cacheCfg.length);
        for (CacheConfiguration ccfg : cacheCfg) writeCacheConfiguration(w, ccfg);
    } else
        w.writeInt(0);
    writeDiscoveryConfiguration(w, cfg.getDiscoverySpi());
    writeEncryptionConfiguration(w, cfg.getEncryptionSpi());
    CommunicationSpi comm = cfg.getCommunicationSpi();
    if (comm instanceof TcpCommunicationSpi) {
        w.writeBoolean(true);
        TcpCommunicationSpi tcp = (TcpCommunicationSpi) comm;
        w.writeInt(tcp.getAckSendThreshold());
        w.writeInt(tcp.getConnectionsPerNode());
        w.writeLong(tcp.getConnectTimeout());
        w.writeBoolean(tcp.isDirectBuffer());
        w.writeBoolean(tcp.isDirectSendBuffer());
        w.writeBoolean(tcp.isFilterReachableAddresses());
        w.writeLong(tcp.getIdleConnectionTimeout());
        w.writeString(tcp.getLocalAddress());
        w.writeInt(tcp.getLocalPort());
        w.writeInt(tcp.getLocalPortRange());
        w.writeLong(tcp.getMaxConnectTimeout());
        w.writeInt(tcp.getMessageQueueLimit());
        w.writeInt(tcp.getReconnectCount());
        w.writeInt(tcp.getSelectorsCount());
        w.writeLong(tcp.getSelectorSpins());
        w.writeInt(tcp.getSharedMemoryPort());
        w.writeInt(tcp.getSlowClientQueueLimit());
        w.writeInt(tcp.getSocketReceiveBuffer());
        w.writeInt(tcp.getSocketSendBuffer());
        w.writeLong(tcp.getSocketWriteTimeout());
        w.writeBoolean(tcp.isTcpNoDelay());
        w.writeInt(tcp.getUnacknowledgedMessagesBufferSize());
        w.writeBoolean(tcp.isUsePairedConnections());
    } else
        w.writeBoolean(false);
    BinaryConfiguration bc = cfg.getBinaryConfiguration();
    if (bc != null) {
        // binary config exists
        w.writeBoolean(true);
        // compact footer is set
        w.writeBoolean(true);
        w.writeBoolean(bc.isCompactFooter());
        w.writeBoolean(bc.getNameMapper() instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper) (bc.getNameMapper())).isSimpleName());
    } else
        w.writeBoolean(false);
    Map<String, ?> attrs = cfg.getUserAttributes();
    if (attrs != null) {
        w.writeInt(attrs.size());
        for (Map.Entry<String, ?> e : attrs.entrySet()) {
            w.writeString(e.getKey());
            w.writeObject(e.getValue());
        }
    } else
        w.writeInt(0);
    AtomicConfiguration atomic = cfg.getAtomicConfiguration();
    if (atomic != null) {
        w.writeBoolean(true);
        w.writeInt(atomic.getAtomicSequenceReserveSize());
        w.writeInt(atomic.getBackups());
        writeEnumInt(w, atomic.getCacheMode(), AtomicConfiguration.DFLT_CACHE_MODE);
    } else
        w.writeBoolean(false);
    TransactionConfiguration tx = cfg.getTransactionConfiguration();
    if (tx != null) {
        w.writeBoolean(true);
        w.writeInt(tx.getPessimisticTxLogSize());
        writeEnumInt(w, tx.getDefaultTxConcurrency(), TransactionConfiguration.DFLT_TX_CONCURRENCY);
        writeEnumInt(w, tx.getDefaultTxIsolation(), TransactionConfiguration.DFLT_TX_ISOLATION);
        w.writeLong(tx.getDefaultTxTimeout());
        w.writeInt(tx.getPessimisticTxLogLinger());
        w.writeLong(tx.getTxTimeoutOnPartitionMapExchange());
        w.writeLong(tx.getDeadlockTimeout());
    } else
        w.writeBoolean(false);
    EventStorageSpi evtStorageSpi = cfg.getEventStorageSpi();
    if (evtStorageSpi == null)
        w.writeByte((byte) 0);
    else if (evtStorageSpi instanceof NoopEventStorageSpi)
        w.writeByte((byte) 1);
    else if (evtStorageSpi instanceof MemoryEventStorageSpi) {
        w.writeByte((byte) 2);
        w.writeLong(((MemoryEventStorageSpi) evtStorageSpi).getExpireCount());
        w.writeLong(((MemoryEventStorageSpi) evtStorageSpi).getExpireAgeMs());
    }
    writeMemoryConfiguration(w, cfg.getMemoryConfiguration());
    writeSqlConnectorConfiguration(w, cfg.getSqlConnectorConfiguration());
    writeClientConnectorConfiguration(w, cfg.getClientConnectorConfiguration());
    w.writeBoolean(cfg.getClientConnectorConfiguration() != null);
    writePersistentStoreConfiguration(w, cfg.getPersistentStoreConfiguration());
    writeDataStorageConfiguration(w, cfg.getDataStorageConfiguration());
    writeSslContextFactory(w, cfg.getSslContextFactory());
    FailureHandler failureHnd = cfg.getFailureHandler();
    if (failureHnd instanceof NoOpFailureHandler) {
        w.writeBoolean(true);
        w.writeByte((byte) 0);
    } else if (failureHnd instanceof StopNodeFailureHandler) {
        w.writeBoolean(true);
        w.writeByte((byte) 1);
    } else if (failureHnd instanceof StopNodeOrHaltFailureHandler) {
        w.writeBoolean(true);
        w.writeByte((byte) 2);
        w.writeBoolean(((StopNodeOrHaltFailureHandler) failureHnd).tryStop());
        w.writeLong(((StopNodeOrHaltFailureHandler) failureHnd).timeout());
    } else
        w.writeBoolean(false);
    ExecutorConfiguration[] execCfgs = cfg.getExecutorConfiguration();
    if (execCfgs != null) {
        w.writeInt(execCfgs.length);
        for (ExecutorConfiguration execCfg : execCfgs) {
            w.writeString(execCfg.getName());
            w.writeInt(execCfg.getSize());
        }
    } else
        w.writeInt(0);
    w.writeString(cfg.getIgniteHome());
    w.writeLong(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getInit());
    w.writeLong(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax());
}
Also used : NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) FailureHandler(org.apache.ignite.failure.FailureHandler) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) EventStorageSpi(org.apache.ignite.spi.eventstorage.EventStorageSpi) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) MemoryEventStorageSpi(org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi) MemoryEventStorageSpi(org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) ExecutorConfiguration(org.apache.ignite.configuration.ExecutorConfiguration) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) PlatformDotNetBinaryConfiguration(org.apache.ignite.platform.dotnet.PlatformDotNetBinaryConfiguration) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PlatformCacheConfiguration(org.apache.ignite.configuration.PlatformCacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 4 with FailureHandler

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

the class IgniteWalFormatFileFailoverTest method failureHandler.

/**
 * @param gridIdx Grid index.
 * @return Failure handler configured for grid with given index.
 */
private TestFailureHandler failureHandler(int gridIdx) {
    FailureHandler hnd = grid(gridIdx).configuration().getFailureHandler();
    assertTrue(hnd instanceof TestFailureHandler);
    return (TestFailureHandler) hnd;
}
Also used : TestFailureHandler(org.apache.ignite.failure.TestFailureHandler) FailureHandler(org.apache.ignite.failure.FailureHandler) TestFailureHandler(org.apache.ignite.failure.TestFailureHandler)

Example 5 with FailureHandler

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

the class DistributedProcessCoordinatorLeftTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setLocalEventListeners(Collections.singletonMap(event -> {
        nodeLeftLatch.countDown();
        try {
            msgSendLatch.await();
        } catch (InterruptedException e) {
            fail("Unexpected interrupt.");
        }
        return false;
    }, new int[] { EVT_NODE_LEFT, EVT_NODE_FAILED }));
    cfg.setFailureHandler(new FailureHandler() {

        @Override
        public boolean onFailure(Ignite ignite, FailureContext failureCtx) {
            failure.set(true);
            return false;
        }
    });
    return cfg;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) G(org.apache.ignite.internal.util.typedef.G) DistributedProcess(org.apache.ignite.internal.util.distributed.DistributedProcess) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) TEST_PROCESS(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.TEST_PROCESS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FailureHandler(org.apache.ignite.failure.FailureHandler) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) FailureContext(org.apache.ignite.failure.FailureContext) Collections(java.util.Collections) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) FailureContext(org.apache.ignite.failure.FailureContext) FailureHandler(org.apache.ignite.failure.FailureHandler) Ignite(org.apache.ignite.Ignite)

Aggregations

FailureHandler (org.apache.ignite.failure.FailureHandler)7 Ignite (org.apache.ignite.Ignite)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 FailureContext (org.apache.ignite.failure.FailureContext)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Random (java.util.Random)1 UUID (java.util.UUID)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1