use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class TxWithSmallTimeoutAndContentionOneKeyTest method test.
/**
* https://issues.apache.org/jira/browse/IGNITE-9042
*
* @throws Exception If failed.
*/
@Test
public void test() throws Exception {
Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-10455", MvccFeatureChecker.forcedMvcc());
startGrids(4);
IgniteEx igClient = startClientGrid(getConfiguration("client").setConsistentId("Client"));
igClient.cluster().active(true);
AtomicBoolean stop = new AtomicBoolean(false);
IgniteCache<Integer, Long> cache = igClient.cache(DEFAULT_CACHE_NAME);
int threads = 1;
int keyId = 0;
CountDownLatch finishLatch = new CountDownLatch(threads);
AtomicLong cnt = new AtomicLong();
IgniteInternalFuture<Long> f = runMultiThreadedAsync(() -> {
IgniteTransactions txMgr = igClient.transactions();
while (!stop.get()) {
long newVal = cnt.getAndIncrement();
TransactionConcurrency concurrency = transactionConcurrency();
TransactionIsolation transactionIsolation = transactionIsolation();
try (Transaction tx = txMgr.txStart(concurrency, transactionIsolation, randomTimeOut(), 1)) {
cache.put(keyId, newVal);
tx.commit();
} catch (Throwable e) {
// Ignore.
}
}
finishLatch.countDown();
}, threads, "tx-runner");
runAsync(() -> {
try {
Thread.sleep(TIME_TO_EXECUTE);
} catch (InterruptedException ignore) {
// Ignore.
}
stop.set(true);
});
finishLatch.await();
f.get();
IdleVerifyResultV2 idleVerifyResult = idleVerify(igClient, DEFAULT_CACHE_NAME);
log.info("Current counter value:" + cnt.get());
Long val = cache.get(keyId);
log.info("Last commited value:" + val);
if (idleVerifyResult.hasConflicts()) {
SB sb = new SB();
sb.a("\n");
buildConflicts("Hash conflicts:\n", sb, idleVerifyResult.hashConflicts());
buildConflicts("Counters conflicts:\n", sb, idleVerifyResult.counterConflicts());
System.out.println(sb);
fail();
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class TxPartitionCounterStateWithFilterTest method testAssignCountersInTxWithFilter.
/**
*/
@Test
public void testAssignCountersInTxWithFilter() {
for (Ignite ig : G.allGrids()) {
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
try {
ignite(0).createCache(cacheConfiguration(cacheMode, backups, CacheAtomicityMode.TRANSACTIONAL));
IgniteCache<Integer, Integer> cache = ig.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
int partId = 0;
List<Integer> keys = partitionKeys(cache, partId, 2, 0);
int key = keys.get(0), val = 0;
if (!sameTx)
cache.put(key, val);
try (Transaction tx = ig.transactions().txStart(concurrency, isolation)) {
if (sameTx)
cache.put(key, val);
Object prev = cache.getAndPutIfAbsent(key, val + 1);
assertNotNull(prev);
cache.put(keys.get(1), val);
tx.commit();
}
assertEquals(Integer.valueOf(val), cache.get(key));
assertEquals(Integer.valueOf(val), cache.get(keys.get(1)));
for (Ignite ignite : G.allGrids()) {
if (ignite.configuration().isClientMode())
continue;
PartitionUpdateCounter cntr = counter(partId, ignite.name());
if (cntr != null)
assertEquals("Expecting counter for node=" + ignite.name(), 2, cntr.get());
}
} finally {
ignite(0).destroyCache(DEFAULT_CACHE_NAME);
}
}
}
}
}
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();
Ignite srv = ignite(0);
srv.createCache(cacheConfiguration(backups));
Ignite client1 = startClientGrid(SRVS);
IgniteCache<Object, Object> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());
Ignite client2 = startClientGrid(SRVS + 1);
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);
}
}
}
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();
Ignite srv = ignite(0);
srv.createCache(cacheConfiguration(backups));
Ignite client1 = startClientGrid(SRVS);
IgniteCache<Object, Object> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());
Integer key = primaryKey(srv.cache(DEFAULT_CACHE_NAME));
Ignite client2 = startClientGrid(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++;
}
}
}
use of org.apache.ignite.transactions.TransactionIsolation in project ignite by apache.
the class IgniteTxStoreExceptionAbstractSelfTest method testPutBackupTx.
/**
* @throws Exception If failed.
*/
@Test
public void testPutBackupTx() throws Exception {
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
checkPutTx(true, concurrency, isolation, keyForNode(grid(0).localNode(), BACKUP));
checkPutTx(false, concurrency, isolation, keyForNode(grid(0).localNode(), BACKUP));
}
}
}
Aggregations