Search in sources :

Example 1 with TransactionMetrics

use of org.apache.ignite.transactions.TransactionMetrics in project ignite by apache.

the class GridCacheTransactionalAbstractMetricsSelfTest method doTestSuspendedTxTimeoutRollbacks.

/**
 * Metrics test for transaction timeout rollback.
 *
 * @param concurrency Concurrency control.
 * @param isolation Isolation level.
 * @throws Exception If failed.
 */
private void doTestSuspendedTxTimeoutRollbacks(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    IgniteTransactions transactions = grid(0).transactions();
    for (int i = 0; i < TX_CNT; i++) {
        Transaction tx = transactions.txStart(concurrency, isolation, TX_TIMEOUT, 0);
        cache.put(1, 1);
        tx.suspend();
        boolean res = GridTestUtils.waitForCondition(() -> tx.state() == ROLLED_BACK, TX_TIMEOUT * 10);
        assertTrue(res);
        tx.close();
    }
    TransactionMetrics txMetrics = transactions.metrics();
    CacheMetrics cacheMetrics = cache.localMetrics();
    assertEquals(0, txMetrics.txCommits());
    assertEquals(0, cacheMetrics.getCacheTxCommits());
    assertEquals(TX_CNT, txMetrics.txRollbacks());
    assertEquals(TX_CNT, cacheMetrics.getCacheTxRollbacks());
    assertTrue(cacheMetrics.getAverageTxRollbackTime() > 0);
    for (int i = 1; i < gridCount(); i++) {
        txMetrics = grid(i).transactions().metrics();
        cacheMetrics = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics();
        assertEquals(0, txMetrics.txCommits());
        assertEquals(0, cacheMetrics.getCacheTxCommits());
        assertEquals(0, txMetrics.txRollbacks());
        assertEquals(0, cacheMetrics.getCacheTxRollbacks());
    }
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Transaction(org.apache.ignite.transactions.Transaction) IgniteTransactions(org.apache.ignite.IgniteTransactions) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics)

Example 2 with TransactionMetrics

use of org.apache.ignite.transactions.TransactionMetrics in project ignite by apache.

the class GridCacheTransactionalAbstractMetricsSelfTest method testRollbacks.

/**
 * @param concurrency Concurrency control.
 * @param isolation Isolation level.
 * @param put Put some data if {@code true}.
 * @throws Exception If failed.
 */
private void testRollbacks(TransactionConcurrency concurrency, TransactionIsolation isolation, boolean put) throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < TX_CNT; i++) {
        Transaction tx = grid(0).transactions().txStart(concurrency, isolation);
        if (put)
            for (int j = 0; j < keyCount(); j++) cache.put(j, j);
        // Waiting 30 ms for metrics. U.currentTimeMillis() method has 10 ms discretization.
        U.sleep(30);
        tx.rollback();
    }
    for (int i = 0; i < gridCount(); i++) {
        TransactionMetrics metrics = grid(i).transactions().metrics();
        CacheMetrics cacheMetrics = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics();
        assertEquals(0, metrics.txCommits());
        assertEquals(0, cacheMetrics.getCacheTxCommits());
        if (i == 0) {
            assertEquals(TX_CNT, metrics.txRollbacks());
            if (put) {
                assertEquals(TX_CNT, cacheMetrics.getCacheTxRollbacks());
                // Expected metric value should be in microseconds.
                assert cacheMetrics.getAverageTxRollbackTime() > 1000 : cacheMetrics.getAverageTxRollbackTime();
            }
        } else {
            assertEquals(0, metrics.txRollbacks());
            assertEquals(0, cacheMetrics.getCacheTxRollbacks());
        }
    }
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Transaction(org.apache.ignite.transactions.Transaction) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics)

Example 3 with TransactionMetrics

use of org.apache.ignite.transactions.TransactionMetrics in project ignite by apache.

the class IgnitePutTxLoadBenchmark method test.

/**
 * {@inheritDoc}
 */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    IgniteTransactions transactions = ignite().transactions();
    long startTime;
    long endTime;
    try (Transaction tx = transactions.txStart(args.txConcurrency(), args.txIsolation())) {
        ArrayList<Long> keyList = new ArrayList<>(args.scaleFactor());
        for (int i = 0; i < args.scaleFactor(); i++) keyList.add(random.nextLong());
        Collections.sort(keyList);
        for (int i = 0; i < args.scaleFactor(); i++) {
            IgniteCache<Object, Object> curCache = cacheList.get(random.nextInt(cacheList.size()));
            curCache.put(keyList.get(i), val);
        }
        startTime = System.currentTimeMillis();
        tx.commit();
        endTime = System.currentTimeMillis();
    }
    TransactionMetrics tm = transactions.metrics();
    if (endTime - startTime > args.getWarningTime())
        BenchmarkUtils.println("Transaction commit time = " + (endTime - startTime));
    if (tm.txRollbacks() > 0 && args.printRollBacks())
        BenchmarkUtils.println("Transaction rollbacks = " + tm.txRollbacks());
    return true;
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) ArrayList(java.util.ArrayList) IgniteTransactions(org.apache.ignite.IgniteTransactions) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics)

Example 4 with TransactionMetrics

use of org.apache.ignite.transactions.TransactionMetrics in project ignite by apache.

the class GridCacheTransactionalAbstractMetricsSelfTest method testCommits.

/**
 * @param concurrency Concurrency control.
 * @param isolation Isolation level.
 * @param put Put some data if {@code true}.
 * @throws Exception If failed.
 */
private void testCommits(TransactionConcurrency concurrency, TransactionIsolation isolation, boolean put) throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < TX_CNT; i++) {
        Transaction tx = grid(0).transactions().txStart(concurrency, isolation);
        if (put)
            for (int j = 0; j < keyCount(); j++) cache.put(j, j);
        // Waiting 30 ms for metrics. U.currentTimeMillis() method has 10 ms discretization.
        U.sleep(30);
        tx.commit();
    }
    for (int i = 0; i < gridCount(); i++) {
        TransactionMetrics metrics = grid(i).transactions().metrics();
        CacheMetrics cacheMetrics = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics();
        if (i == 0) {
            assertEquals(TX_CNT, metrics.txCommits());
            if (put) {
                assertEquals(TX_CNT, cacheMetrics.getCacheTxCommits());
                // Expected metric value should be in microseconds.
                assert cacheMetrics.getAverageTxCommitTime() > 1000 : cacheMetrics.getAverageTxCommitTime();
            }
        } else {
            assertEquals(0, metrics.txCommits());
            assertEquals(0, cacheMetrics.getCacheTxCommits());
        }
        assertEquals(0, metrics.txRollbacks());
        assertEquals(0, cacheMetrics.getCacheTxRollbacks());
    }
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) Transaction(org.apache.ignite.transactions.Transaction) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics)

Example 5 with TransactionMetrics

use of org.apache.ignite.transactions.TransactionMetrics in project ignite by apache.

the class PlatformTransactions method processOutStream.

/**
 * {@inheritDoc}
 */
@Override
public void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
    switch(type) {
        case OP_CACHE_CONFIG_PARAMETERS:
            TransactionConfiguration txCfg = platformCtx.kernalContext().config().getTransactionConfiguration();
            writer.writeInt(txCfg.getDefaultTxConcurrency().ordinal());
            writer.writeInt(txCfg.getDefaultTxIsolation().ordinal());
            writer.writeLong(txCfg.getDefaultTxTimeout());
            writer.writeLong(txCfg.getTxTimeoutOnPartitionMapExchange());
            break;
        case OP_METRICS:
            TransactionMetrics metrics = txs.metrics();
            writer.writeTimestamp(new Timestamp(metrics.commitTime()));
            writer.writeTimestamp(new Timestamp(metrics.rollbackTime()));
            writer.writeInt(metrics.txCommits());
            writer.writeInt(metrics.txRollbacks());
            break;
        case OP_LOCAL_ACTIVE_TX:
            Collection<Transaction> activeTxs = txs.localActiveTransactions();
            PlatformUtils.writeCollection(writer, activeTxs, new PlatformWriterClosure<Transaction>() {

                @Override
                public void write(BinaryRawWriterEx writer, Transaction tx) {
                    writer.writeLong(registerTx(tx));
                    writer.writeInt(tx.concurrency().ordinal());
                    writer.writeInt(tx.isolation().ordinal());
                    writer.writeLong(tx.timeout());
                    writer.writeString(tx.label());
                }
            });
            break;
        default:
            super.processOutStream(type, writer);
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) Transaction(org.apache.ignite.transactions.Transaction) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics) Timestamp(java.sql.Timestamp) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx)

Aggregations

Transaction (org.apache.ignite.transactions.Transaction)5 TransactionMetrics (org.apache.ignite.transactions.TransactionMetrics)5 CacheMetrics (org.apache.ignite.cache.CacheMetrics)3 IgniteTransactions (org.apache.ignite.IgniteTransactions)2 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)1 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)1