Search in sources :

Example 1 with FailureContext

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

the class GridDhtLocalPartition method casState.

/**
 * @param state Current aggregated value.
 * @param toState State to switch to.
 * @return {@code true} if cas succeeds.
 */
private boolean casState(long state, GridDhtPartitionState toState) {
    if (grp.persistenceEnabled() && grp.walEnabled()) {
        synchronized (this) {
            GridDhtPartitionState prevState = state();
            boolean updated = this.state.compareAndSet(state, setPartState(state, toState));
            if (updated) {
                assert toState != EVICTED || reservations() == 0 : this;
                try {
                    // Optimization: do not log OWNING -> OWNING.
                    if (prevState == OWNING && toState == LOST)
                        return true;
                    // Log LOST partitions as OWNING.
                    ctx.wal().log(new PartitionMetaStateRecord(grp.groupId(), id, toState == LOST ? OWNING : toState, 0));
                } catch (IgniteCheckedException e) {
                    U.error(log, "Failed to log partition state change to WAL.", e);
                    ctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
                }
                if (log.isDebugEnabled())
                    log.debug("Partition changed state [grp=" + grp.cacheOrGroupName() + ", p=" + id + ", prev=" + prevState + ", to=" + toState + "]");
            }
            return updated;
        }
    } else {
        GridDhtPartitionState prevState = state();
        boolean updated = this.state.compareAndSet(state, setPartState(state, toState));
        if (updated) {
            assert toState != EVICTED || reservations() == 0 : this;
            if (log.isDebugEnabled())
                log.debug("Partition changed state [grp=" + grp.cacheOrGroupName() + ", p=" + id + ", prev=" + prevState + ", to=" + toState + "]");
        }
        return updated;
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) FailureContext(org.apache.ignite.failure.FailureContext)

Example 2 with FailureContext

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

the class IgniteExchangeLatchManagerDiscoHistoryTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TcpDiscoveryIpFinder ipFinder = ((TcpDiscoverySpi) cfg.getDiscoverySpi()).getIpFinder();
    int topHistSize = victim ? TOPOLOGY_HISTORY_SIZE : TcpDiscoverySpi.DFLT_TOP_HISTORY_SIZE;
    CustomTcpDiscoverySpi discoSpi = new CustomTcpDiscoverySpi(topHistSize, ipFinder);
    cfg.setDiscoverySpi(discoSpi);
    if (victim) {
        cfg.setFailureHandler(new AbstractFailureHandler() {

            /**
             * {@inheritDoc}
             */
            @Override
            protected boolean handle(Ignite ignite, FailureContext failureCtx) {
                cpFailureCtx.compareAndSet(null, failureCtx);
                // Invalidate kernel context.
                return true;
            }
        });
        cfg.setLifecycleBeans(lifecycleBean);
        disco = discoSpi;
    }
    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) TcpDiscoveryIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 3 with FailureContext

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

the class OutOfMemoryVolatileRegionTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    cfg.setDataStorageConfiguration(new DataStorageConfiguration().setPageSize(4096).setSystemDataRegionConfiguration(new SystemDataRegionConfiguration().setInitialSize(DATA_REGION_SIZE).setMaxSize(DATA_REGION_SIZE)).setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true).setMetricsEnabled(true)));
    cfg.setFailureHandler(new AbstractFailureHandler() {

        /**
         * {@inheritDoc}
         */
        @Override
        protected boolean handle(Ignite ignite, FailureContext failureCtx) {
            failure = 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) SystemDataRegionConfiguration(org.apache.ignite.configuration.SystemDataRegionConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) SystemDataRegionConfiguration(org.apache.ignite.configuration.SystemDataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) FailureContext(org.apache.ignite.failure.FailureContext) AbstractFailureHandler(org.apache.ignite.failure.AbstractFailureHandler) Ignite(org.apache.ignite.Ignite)

Example 4 with FailureContext

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

the class IgniteTxHandler method finishDhtLocal.

/**
 * @param nodeId Node ID initiated commit.
 * @param locTx Optional local transaction.
 * @param req Finish request.
 * @return Finish future.
 */
private IgniteInternalFuture<IgniteInternalTx> finishDhtLocal(UUID nodeId, @Nullable GridNearTxLocal locTx, GridNearTxFinishRequest req) {
    GridCacheVersion dhtVer = ctx.tm().mappedVersion(req.version());
    GridDhtTxLocal tx = null;
    if (dhtVer == null) {
        if (log.isDebugEnabled())
            log.debug("Received transaction finish request for unknown near version (was lock explicit?): " + req);
    } else
        tx = ctx.tm().tx(dhtVer);
    if (tx != null) {
        tx.mvccSnapshot(req.mvccSnapshot());
        req.txState(tx.txState());
    }
    if (tx == null && locTx != null && !req.commit()) {
        U.warn(log, "DHT local tx not found for near local tx rollback " + "[req=" + req + ", dhtVer=" + dhtVer + ", tx=" + locTx + ']');
        return null;
    }
    if (tx == null && !req.explicitLock()) {
        assert locTx == null : "DHT local tx should never be lost for near local tx: " + locTx;
        U.warn(txFinishMsgLog, "Received finish request for completed transaction (the message may be too late) [" + "txId=" + req.version() + ", dhtTxId=" + dhtVer + ", node=" + nodeId + ", commit=" + req.commit() + ']');
        // Always send finish response.
        GridCacheMessage res = new GridNearTxFinishResponse(req.partition(), req.version(), req.threadId(), req.futureId(), req.miniId(), new IgniteTxRollbackCheckedException("Transaction has been already completed or not started yet."));
        try {
            ctx.io().send(nodeId, res, req.policy());
            if (txFinishMsgLog.isDebugEnabled()) {
                txFinishMsgLog.debug("Sent near finish response for completed tx [txId=" + req.version() + ", dhtTxId=" + dhtVer + ", node=" + nodeId + ']');
            }
        } catch (Throwable e) {
            // Double-check.
            if (ctx.discovery().node(nodeId) == null) {
                if (txFinishMsgLog.isDebugEnabled()) {
                    txFinishMsgLog.debug("Failed to send near finish response for completed tx, node failed [" + "txId=" + req.version() + ", dhtTxId=" + dhtVer + ", node=" + nodeId + ']');
                }
            } else {
                U.error(txFinishMsgLog, "Failed to send near finish response for completed tx, node failed [" + "txId=" + req.version() + ", dhtTxId=" + dhtVer + ", node=" + nodeId + ", req=" + req + ", res=" + res + ']', e);
            }
            if (e instanceof Error)
                throw (Error) e;
        }
        return null;
    }
    try {
        assert tx != null : "Transaction is null for near finish request [nodeId=" + nodeId + ", req=" + req + "]";
        assert req.syncMode() != null : req;
        tx.syncMode(req.syncMode());
        tx.nearFinishFutureId(req.futureId());
        tx.nearFinishMiniId(req.miniId());
        tx.storeEnabled(req.storeEnabled());
        if (!tx.markFinalizing(USER_FINISH)) {
            if (log.isDebugEnabled())
                log.debug("Will not finish transaction (it is handled by another thread) [commit=" + req.commit() + ", tx=" + tx + ']');
            return null;
        }
        if (req.commit()) {
            IgniteInternalFuture<IgniteInternalTx> commitFut = tx.commitDhtLocalAsync();
            // Only for error logging.
            commitFut.listen(CU.errorLogger(log));
            return commitFut;
        } else {
            IgniteInternalFuture<IgniteInternalTx> rollbackFut = tx.rollbackDhtLocalAsync();
            // Only for error logging.
            rollbackFut.listen(CU.errorLogger(log));
            return rollbackFut;
        }
    } catch (Throwable e) {
        try {
            if (tx != null) {
                tx.commitError(e);
                tx.systemInvalidate(true);
                try {
                    IgniteInternalFuture<IgniteInternalTx> res = tx.rollbackDhtLocalAsync();
                    // Only for error logging.
                    res.listen(CU.errorLogger(log));
                    return res;
                } catch (Throwable e1) {
                    e.addSuppressed(e1);
                }
                tx.logTxFinishErrorSafe(log, req.commit(), e);
            }
            if (e instanceof Error)
                throw (Error) e;
            return new GridFinishedFuture<>(e);
        } finally {
            ctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
        }
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridDhtTxLocal(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocal) FailureContext(org.apache.ignite.failure.FailureContext) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) GridNearTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse)

Example 5 with FailureContext

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

the class CacheNoAffinityExchangeTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
    cfg.setDiscoverySpi(new TestDiscoverySpi().setIpFinder(IP_FINDER));
    cfg.setClusterStateOnStart(INACTIVE);
    cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(200 * 1024 * 1024)));
    if (cfg.isClientMode()) {
        TestRecordingCommunicationSpi customSpi = clientCommSpi;
        if (customSpi != null)
            cfg.setCommunicationSpi(customSpi);
        // It is necessary to ensure that client always connects to grid(0).
        ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(CLIENT_IP_FINDER);
        if (startClientCaches) {
            CacheConfiguration<Integer, Integer> txCfg = new CacheConfiguration<Integer, Integer>().setName(PARTITIONED_TX_CLIENT_CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setAffinity(new RendezvousAffinityFunction(false, 32)).setBackups(2);
            cfg.setCacheConfiguration(txCfg);
        }
    }
    cfg.setFailureHandler(new AbstractFailureHandler() {

        /**
         * {@inheritDoc}
         */
        @Override
        protected boolean handle(Ignite ignite, FailureContext failureCtx) {
            errs.put(ignite.configuration().getIgniteInstanceName(), failureCtx.error());
            return false;
        }
    });
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) FailureContext(org.apache.ignite.failure.FailureContext) AbstractFailureHandler(org.apache.ignite.failure.AbstractFailureHandler) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Ignite(org.apache.ignite.Ignite) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

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