Search in sources :

Example 1 with TransactionConfiguration

use of org.apache.ignite.configuration.TransactionConfiguration in project ignite by apache.

the class ReplicatedAtomicCacheGetsDistributionTest method transactionConfiguration.

/**
 * @return Transaction configuration.
 */
protected TransactionConfiguration transactionConfiguration() {
    TransactionConfiguration txCfg = new TransactionConfiguration();
    txCfg.setDefaultTxIsolation(transactionIsolation());
    txCfg.setDefaultTxConcurrency(transactionConcurrency());
    return txCfg;
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration)

Example 2 with TransactionConfiguration

use of org.apache.ignite.configuration.TransactionConfiguration in project ignite by apache.

the class GridCacheAdapter method txStart.

/**
 * {@inheritDoc}
 */
@Override
public Transaction txStart(TransactionConcurrency concurrency, TransactionIsolation isolation) {
    A.notNull(concurrency, "concurrency");
    A.notNull(isolation, "isolation");
    TransactionConfiguration cfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
    return txStart(concurrency, isolation, cfg.getDefaultTxTimeout(), 0);
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration)

Example 3 with TransactionConfiguration

use of org.apache.ignite.configuration.TransactionConfiguration in project ignite by apache.

the class GridCacheAdapter method syncOp.

/**
 * @param op Cache operation.
 * @param <T> Return type.
 * @return Operation result.
 * @throws IgniteCheckedException If operation failed.
 */
@SuppressWarnings({ "ErrorNotRethrown", "AssignmentToCatchBlockParameter" })
@Nullable
private <T> T syncOp(SyncOp<T> op) throws IgniteCheckedException {
    checkJta();
    awaitLastFut();
    GridNearTxLocal tx = checkCurrentTx();
    if (tx == null || tx.implicit()) {
        TransactionConfiguration tCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
        CacheOperationContext opCtx = ctx.operationContextPerCall();
        int retries = opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES;
        for (int i = 0; i < retries; i++) {
            tx = ctx.tm().newTx(true, op.single(), ctx.systemTx() ? ctx : null, ctx.mvccEnabled() ? PESSIMISTIC : OPTIMISTIC, ctx.mvccEnabled() ? REPEATABLE_READ : READ_COMMITTED, tCfg.getDefaultTxTimeout(), !ctx.skipStore(), ctx.mvccEnabled(), 0, null, false);
            assert tx != null;
            try {
                T t = op.op(tx);
                assert tx.done() : "Transaction is not done: " + tx;
                return t;
            } catch (IgniteInterruptedCheckedException | IgniteTxHeuristicCheckedException | NodeStoppingException | IgniteConsistencyViolationException e) {
                throw e;
            } catch (IgniteCheckedException e) {
                if (!(e instanceof IgniteTxRollbackCheckedException)) {
                    try {
                        tx.rollback();
                        if (!(e instanceof TransactionCheckedException))
                            e = new IgniteTxRollbackCheckedException("Transaction has been rolled back: " + tx.xid(), e);
                    } catch (IgniteCheckedException | AssertionError | RuntimeException e1) {
                        U.error(log, "Failed to rollback transaction (cache may contain stale locks): " + CU.txString(tx), e1);
                        if (e != e1)
                            e.addSuppressed(e1);
                    }
                }
                if (X.hasCause(e, ClusterTopologyCheckedException.class) && i != retries - 1) {
                    ClusterTopologyCheckedException topErr = e.getCause(ClusterTopologyCheckedException.class);
                    if (!(topErr instanceof ClusterTopologyServerNotFoundException)) {
                        AffinityTopologyVersion topVer = tx.topologyVersion();
                        assert topVer != null && topVer.topologyVersion() > 0 : tx;
                        AffinityTopologyVersion awaitVer = new AffinityTopologyVersion(topVer.topologyVersion() + 1, 0);
                        ctx.shared().exchange().affinityReadyFuture(awaitVer).get();
                        continue;
                    }
                }
                throw e;
            } catch (RuntimeException e) {
                try {
                    tx.rollback();
                } catch (IgniteCheckedException | AssertionError | RuntimeException e1) {
                    U.error(log, "Failed to rollback transaction " + CU.txString(tx), e1);
                }
                throw e;
            } finally {
                ctx.tm().resetContext();
                if (ctx.isNear())
                    ctx.near().dht().context().tm().resetContext();
            }
        }
        // Should not happen.
        throw new IgniteCheckedException("Failed to perform cache operation (maximum number of retries exceeded).");
    } else
        return op.op(tx);
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) IGNITE_CACHE_RETRIES_COUNT(org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT) LT(org.apache.ignite.internal.util.typedef.internal.LT) TransactionCheckedException(org.apache.ignite.internal.transactions.TransactionCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with TransactionConfiguration

use of org.apache.ignite.configuration.TransactionConfiguration in project ignite by apache.

the class IgniteTransactionsImpl method txStart.

/**
 * {@inheritDoc}
 */
@Override
public Transaction txStart(TransactionConcurrency concurrency, TransactionIsolation isolation) {
    A.notNull(concurrency, "concurrency");
    A.notNull(isolation, "isolation");
    TransactionConfiguration cfg = CU.transactionConfiguration(null, cctx.kernalContext().config());
    return txStart0(concurrency, isolation, cfg.getDefaultTxTimeout(), 0, null).proxy();
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration)

Example 5 with TransactionConfiguration

use of org.apache.ignite.configuration.TransactionConfiguration in project ignite by apache.

the class CacheGetsDistributionAbstractTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TransactionConfiguration txCfg = new TransactionConfiguration().setDefaultTxIsolation(transactionIsolation()).setDefaultTxConcurrency(transactionConcurrency());
    cfg.setTransactionConfiguration(txCfg);
    return cfg;
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration)

Aggregations

TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)40 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)11 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)7 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)4 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)4 StopNodeFailureHandler (org.apache.ignite.failure.StopNodeFailureHandler)4 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)4 HashMap (java.util.HashMap)3 Transaction (javax.transaction.Transaction)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 Test (org.junit.Test)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 TransactionManager (javax.transaction.TransactionManager)2 IGNITE_CACHE_RETRIES_COUNT (org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT)2 BinaryBasicNameMapper (org.apache.ignite.binary.BinaryBasicNameMapper)2 AtomicConfiguration (org.apache.ignite.configuration.AtomicConfiguration)2