use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testTxConfigurationSamplingRateNeverPreventsTxTracing.
/**
* Ensure that in case of sampling rate equals to 0.0 (Never) no transactions are traced.
*
* @throws Exception If Failed.
*/
@Test
public void testTxConfigurationSamplingRateNeverPreventsTxTracing() throws Exception {
IgniteEx client = startGrid("client");
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_NEVER).build());
client.transactions().txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
Set<String> unexpectedTxSpanNames = Arrays.stream(SpanType.values()).filter(spanType -> spanType.scope() == TX).map(SpanType::spanName).collect(Collectors.toSet());
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> unexpectedTxSpanNames.contains(span.getName())).collect(Collectors.toList());
assertTrue(gotSpans.isEmpty());
}
use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testThatScopeSpecificConfigurationIsUsedIfLabelSpecificNotFound.
/**
* Ensure that scope specific configuration is used if corresponding label specific not found.
*
* @throws Exception If Failed.
*/
@Test
public void testThatScopeSpecificConfigurationIsUsedIfLabelSpecificNotFound() throws Exception {
IgniteEx client = startGrid("client");
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_ALWAYS).build());
client.transactions().withLabel("label1").txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> SpanType.TX.spanName().equals(span.getName())).collect(Collectors.toList());
assertEquals(1, gotSpans.size());
}
use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testTxConfigurationSamplingRateAlwaysEnablesTxTracing.
/**
* Ensure that in case of sampling rate equals to 1.0 (Always) transactions are successfully traced.
*
* @throws Exception If Failed.
*/
@Test
public void testTxConfigurationSamplingRateAlwaysEnablesTxTracing() throws Exception {
IgniteEx client = startGrid("client");
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_ALWAYS).build());
client.transactions().txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> SpanType.TX.spanName().equals(span.getName())).collect(Collectors.toList());
assertEquals(1, gotSpans.size());
}
use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class GridCommandHandlerTest method testKillHangingRemoteTransactions.
/**
* Simulate uncommitted backup transactions and test rolling back using utility.
*/
@Test
public void testKillHangingRemoteTransactions() throws Exception {
final int cnt = 3;
startGridsMultiThreaded(cnt);
Ignite[] clients = new Ignite[] { startGrid("client1"), startGrid("client2"), startGrid("client3"), startGrid("client4") };
clients[0].getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setBackups(2).setAtomicityMode(TRANSACTIONAL).setWriteSynchronizationMode(FULL_SYNC).setAffinity(new RendezvousAffinityFunction(false, 64)));
awaitPartitionMapExchange();
for (Ignite client : clients) {
assertTrue(client.configuration().isClientMode());
assertNotNull(client.cache(DEFAULT_CACHE_NAME));
}
LongAdder progress = new LongAdder();
AtomicInteger idx = new AtomicInteger();
int tc = clients.length;
CountDownLatch lockLatch = new CountDownLatch(1);
CountDownLatch commitLatch = new CountDownLatch(1);
Ignite prim = primaryNode(0L, DEFAULT_CACHE_NAME);
TestRecordingCommunicationSpi primSpi = TestRecordingCommunicationSpi.spi(prim);
primSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message message) {
return message instanceof GridDhtTxFinishRequest;
}
});
Set<IgniteUuid> xidSet = new GridConcurrentHashSet<>();
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
int id = idx.getAndIncrement();
Ignite client = clients[id];
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED, 0, 1)) {
xidSet.add(tx.xid());
IgniteCache<Long, Long> cache = client.cache(DEFAULT_CACHE_NAME);
if (id != 0)
U.awaitQuiet(lockLatch);
cache.invoke(0L, new IncrementClosure(), null);
if (id == 0) {
lockLatch.countDown();
U.awaitQuiet(commitLatch);
// Wait until candidates will enqueue.
doSleep(500);
}
tx.commit();
} catch (Exception e) {
assertTrue(X.hasCause(e, TransactionTimeoutException.class));
}
progress.increment();
}
}, tc, "invoke-thread");
U.awaitQuiet(lockLatch);
commitLatch.countDown();
primSpi.waitForBlocked(clients.length);
// Unblock only finish messages from clients from 2 to 4.
primSpi.stopBlock(true, blockedMsg -> {
GridIoMessage iom = blockedMsg.ioMessage();
Message m = iom.message();
if (m instanceof GridDhtTxFinishRequest) {
GridDhtTxFinishRequest r = (GridDhtTxFinishRequest) m;
return !r.nearNodeId().equals(clients[0].cluster().localNode().id());
}
return true;
});
// Wait until queue is stable
for (Ignite ignite : G.allGrids()) {
if (ignite.configuration().isClientMode())
continue;
Collection<IgniteInternalTx> txs = ((IgniteEx) ignite).context().cache().context().tm().activeTransactions();
waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (IgniteInternalTx tx : txs) if (!tx.local()) {
IgniteTxEntry entry = tx.writeEntries().iterator().next();
GridCacheEntryEx cached = entry.cached();
Collection<GridCacheMvccCandidate> candidates = cached.remoteMvccSnapshot();
if (candidates.size() != clients.length)
return false;
}
return true;
}
}, 10_000);
}
CommandHandler h = new CommandHandler();
// Check listing.
validate(h, map -> {
for (int i = 0; i < cnt; i++) {
IgniteEx grid = grid(i);
// Skip primary.
if (grid.localNode().id().equals(prim.cluster().localNode().id()))
continue;
VisorTxTaskResult res = map.get(grid.localNode());
List<VisorTxInfo> infos = res.getInfos().stream().filter(info -> xidSet.contains(info.getNearXid())).collect(Collectors.toList());
// Validate queue length on backups.
assertEquals(clients.length, infos.size());
}
}, "--tx");
// Check kill.
validate(h, map -> {
// No-op.
}, "--tx", "--kill");
// Wait for all remote txs to finish.
for (Ignite ignite : G.allGrids()) {
if (ignite.configuration().isClientMode())
continue;
Collection<IgniteInternalTx> txs = ((IgniteEx) ignite).context().cache().context().tm().activeTransactions();
for (IgniteInternalTx tx : txs) if (!tx.local())
tx.finishFuture().get();
}
// Unblock finish message from client1.
primSpi.stopBlock(true);
fut.get();
Long cur = (Long) clients[0].cache(DEFAULT_CACHE_NAME).get(0L);
assertEquals(tc - 1, cur.longValue());
checkUserFutures();
}
use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class TxRollbackOnTimeoutTest method testRollbackOnNearNodeLeft.
/**
* Tests that transactions from near node that has left are rolled back on server nodes.
*
* @throws Exception If failed.
*/
@Test
public void testRollbackOnNearNodeLeft() throws Exception {
Ignite client = startClient();
Integer pk0 = primaryKey(grid(0).cache(CACHE_NAME));
Integer pk1 = primaryKey(grid(1).cache(CACHE_NAME));
CountDownLatch locked = new CountDownLatch(1);
CountDownLatch blocked = new CountDownLatch(1);
IgniteInternalFuture<Void> fut = runAsync(new Callable<Void>() {
@Override
public Void call() {
try (Transaction tx0 = client.transactions().txStart()) {
client.cache(CACHE_NAME).put(pk0, 0);
locked.countDown();
awaitQuiet(blocked);
tx0.commit();
} catch (Exception ignored) {
// No-op.
}
return null;
}
});
IgniteInternalFuture fut2 = runAsync(new Runnable() {
@Override
public void run() {
try (Transaction tx1 = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 1000, 0)) {
awaitQuiet(locked);
client.cache(CACHE_NAME).put(pk1, 1);
spi(client).blockMessages((node, msg) -> msg instanceof GridNearTxFinishRequest);
spi(grid(0)).blockMessages((node, msg) -> msg instanceof GridNearLockResponse);
client.cache(CACHE_NAME).put(pk0, 1);
fail();
} catch (Exception e) {
assertTrue(X.hasCause(e, TransactionTimeoutException.class));
}
}
});
spi(client).waitForBlocked();
spi(grid(0)).waitForBlocked();
fut2.get();
client.close();
spi(grid(0)).stopBlock();
blocked.countDown();
fut.get();
for (int i = 0; i < GRID_CNT; i++) assertTrue(grid(i).context().cache().context().tm().activeTransactions().isEmpty());
}
Aggregations