Search in sources :

Example 31 with TransactionIsolation

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

the class GridCacheBinaryObjectsAbstractSelfTest method testKeepBinaryTxOverwrite.

/**
 * @throws Exception if failed.
 */
public void testKeepBinaryTxOverwrite() throws Exception {
    if (atomicityMode() != TRANSACTIONAL)
        return;
    IgniteCache<Integer, TestObject> cache = ignite(0).cache(DEFAULT_CACHE_NAME);
    cache.put(0, new TestObject(1));
    for (TransactionConcurrency conc : TransactionConcurrency.values()) {
        for (TransactionIsolation iso : TransactionIsolation.values()) {
            try (Transaction tx = ignite(0).transactions().txStart(conc, iso)) {
                cache.withKeepBinary().get(0);
                cache.invoke(0, new ObjectEntryProcessor());
                tx.commit();
            }
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation)

Example 32 with TransactionIsolation

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

the class CacheLateAffinityAssignmentTest method cacheOperations.

/**
 * @param cache Cache
 */
private void cacheOperations(IgniteCache<Object, Object> cache) {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    final int KEYS = 10_000;
    try {
        cache.get(rnd.nextInt(KEYS));
        cache.put(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.getAndPut(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.remove(rnd.nextInt(KEYS));
        cache.getAndRemove(rnd.nextInt(KEYS));
        cache.remove(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.putIfAbsent(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.replace(rnd.nextInt(KEYS), rnd.nextInt(10));
        cache.replace(rnd.nextInt(KEYS), rnd.nextInt(10), rnd.nextInt(10));
        cache.invoke(rnd.nextInt(KEYS), new TestEntryProcessor(rnd.nextInt(10)));
        if (cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL) {
            IgniteTransactions txs = cache.unwrap(Ignite.class).transactions();
            for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                for (TransactionIsolation isolation : TransactionIsolation.values()) {
                    try (Transaction tx = txs.txStart(concurrency, isolation)) {
                        Integer key = rnd.nextInt(KEYS);
                        cache.getAndPut(key, rnd.nextInt(10));
                        cache.invoke(key + 1, new TestEntryProcessor(rnd.nextInt(10)));
                        cache.get(key + 2);
                        tx.commit();
                    }
                }
            }
        }
    } catch (Exception e) {
        log.info("Cache operation failed: " + e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) IgniteTransactions(org.apache.ignite.IgniteTransactions) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)

Example 33 with TransactionIsolation

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

the class IgniteCacheInvokeReadThroughAbstractTest method invokeReadThrough.

/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
protected void invokeReadThrough(CacheConfiguration ccfg) throws Exception {
    Ignite ignite0 = ignite(0);
    ignite0.createCache(ccfg);
    int key = 0;
    for (Ignite node : G.allGrids()) {
        if (node.configuration().isClientMode() && ccfg.getNearConfiguration() != null)
            node.createNearCache(ccfg.getName(), ccfg.getNearConfiguration());
    }
    for (Ignite node : G.allGrids()) {
        log.info("Test for node: " + node.name());
        IgniteCache<Object, Object> cache = node.cache(ccfg.getName());
        for (int i = 0; i < 50; i++) checkReadThrough(cache, key++, null, null);
        Set<Object> keys = new HashSet<>();
        for (int i = 0; i < 5; i++) keys.add(key++);
        checkReadThroughInvokeAll(cache, keys, null, null);
        keys = new HashSet<>();
        for (int i = 0; i < 100; i++) keys.add(key++);
        checkReadThroughInvokeAll(cache, keys, null, null);
        if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
            for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                for (TransactionIsolation isolation : TransactionIsolation.values()) {
                    log.info("Test tx [concurrency=" + concurrency + ", isolation=" + isolation + ']');
                    for (int i = 0; i < 50; i++) checkReadThrough(cache, key++, concurrency, isolation);
                    keys = new HashSet<>();
                    for (int i = 0; i < 5; i++) keys.add(key++);
                    checkReadThroughInvokeAll(cache, keys, concurrency, isolation);
                    keys = new HashSet<>();
                    for (int i = 0; i < 100; i++) keys.add(key++);
                    checkReadThroughInvokeAll(cache, keys, concurrency, isolation);
                }
            }
            for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                for (TransactionIsolation isolation : TransactionIsolation.values()) {
                    log.info("Test tx2 [concurrency=" + concurrency + ", isolation=" + isolation + ']');
                    for (int i = 0; i < 50; i++) checkReadThroughGetAndInvoke(cache, key++, concurrency, isolation);
                }
            }
        }
    }
    ignite0.cache(ccfg.getName()).removeAll();
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet)

Example 34 with TransactionIsolation

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

the class IgniteOnePhaseCommitNearReadersTest method putReadersUpdate.

/**
 * @param backups Backups number.
 * @throws Exception If failed.
 */
private void putReadersUpdate(int backups) throws Exception {
    final int SRVS = 3;
    startGrids(SRVS);
    awaitPartitionMapExchange();
    client = true;
    Ignite srv = ignite(0);
    srv.createCache(cacheConfiguration(backups));
    Ignite client1 = startGrid(SRVS);
    IgniteCache<Object, Object> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());
    Integer key = primaryKey(srv.cache(DEFAULT_CACHE_NAME));
    Ignite client2 = startGrid(SRVS + 1);
    IgniteCache<Object, Object> cache2 = client2.cache(DEFAULT_CACHE_NAME);
    cache1.put(key, 1);
    cache2.put(key, 2);
    checkCacheData(F.asMap(key, 2), DEFAULT_CACHE_NAME);
    int val = 10;
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            try (Transaction tx = client2.transactions().txStart(concurrency, isolation)) {
                cache2.put(key, val);
                tx.commit();
            }
            checkCacheData(F.asMap(key, val), DEFAULT_CACHE_NAME);
            val++;
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite)

Example 35 with TransactionIsolation

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

the class IgniteOnePhaseCommitNearReadersTest method putReaderUpdatePrimaryFails.

/**
 * @param backups Backups number.
 * @throws Exception If failed.
 */
private void putReaderUpdatePrimaryFails(int backups) throws Exception {
    testSpi = true;
    final int SRVS = 3;
    startGrids(SRVS);
    awaitPartitionMapExchange();
    client = true;
    Ignite srv = ignite(0);
    srv.createCache(cacheConfiguration(backups));
    Ignite client1 = startGrid(SRVS);
    IgniteCache<Object, Object> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());
    Ignite client2 = startGrid(SRVS + 1);
    client = false;
    IgniteCache<Object, Object> cache2 = client2.cache(DEFAULT_CACHE_NAME);
    Integer key = primaryKey(srv.cache(DEFAULT_CACHE_NAME));
    cache1.put(key, 1);
    spi(srv).blockMessages(GridNearTxPrepareResponse.class, client2.name());
    IgniteFuture<?> fut = cache2.putAsync(key, 2);
    U.sleep(1000);
    assertFalse(fut.isDone());
    stopGrid(0);
    fut.get();
    checkCacheData(F.asMap(key, backups == 0 ? null : 2), DEFAULT_CACHE_NAME);
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            srv = startGrid(0);
            awaitPartitionMapExchange(true, true, null);
            key = primaryKey(srv.cache(DEFAULT_CACHE_NAME));
            cache1.put(key, 1);
            spi(srv).blockMessages(GridNearTxPrepareResponse.class, client2.name());
            try (Transaction tx = client2.transactions().txStart(concurrency, isolation)) {
                cache2.putAsync(key, 2);
                fut = tx.commitAsync();
                U.sleep(1000);
                assertFalse(fut.isDone());
                stopGrid(0);
                if (backups == 0)
                    fut.get();
                else {
                    try {
                        fut.get();
                        fail();
                    } catch (TransactionRollbackException ignore) {
                    // Expected.
                    }
                }
            }
            checkCacheData(F.asMap(key, backups == 0 ? null : 1), DEFAULT_CACHE_NAME);
            try (Transaction tx = client2.transactions().txStart(concurrency, isolation)) {
                cache2.putAsync(key, 2);
                tx.commit();
            }
            checkCacheData(F.asMap(key, 2), DEFAULT_CACHE_NAME);
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException)

Aggregations

TransactionIsolation (org.apache.ignite.transactions.TransactionIsolation)52 TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)48 Transaction (org.apache.ignite.transactions.Transaction)29 Ignite (org.apache.ignite.Ignite)21 IgniteTransactions (org.apache.ignite.IgniteTransactions)10 IgniteCache (org.apache.ignite.IgniteCache)7 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 IgniteException (org.apache.ignite.IgniteException)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CacheException (javax.cache.CacheException)2 Transaction (javax.transaction.Transaction)2 TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2