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;
}
}
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;
}
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;
}
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));
}
}
}
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;
}
Aggregations