use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class IgniteLogicalRecoveryWithParamsTest method testPartiallyCommitedTx.
/**
* Tests concurrent tx with node stop and further recovery.
*/
private void testPartiallyCommitedTx() throws Exception {
final String cacheName = "recovery";
int itmsCount = 30_000;
AtomicBoolean failFileIO = new AtomicBoolean();
List<Integer> keys;
CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<Integer, Integer>(cacheName).setCacheMode(CacheMode.PARTITIONED).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(backups).setAffinity(new RendezvousAffinityFunction(false, 32));
try {
final IgniteEx srv = (IgniteEx) startGridsMultiThreaded(numSrvNodes);
G.allGrids().forEach(n -> setWalIOFactory(n, failFileIO));
IgniteEx clnt = startClientGrid("client");
TestRecordingCommunicationSpi nearComm = TestRecordingCommunicationSpi.spi(clnt);
srv.cluster().state(ClusterState.ACTIVE);
final IgniteCache cache = clnt.getOrCreateCache(cfg);
final CountDownLatch commitStart = new CountDownLatch(1);
forceCheckpoint();
nearComm.blockMessages((node, msg) -> msg instanceof GridNearTxPrepareRequest);
if (singleNodeTx)
keys = primaryKeys(srv.cache(cacheName), itmsCount, 0);
else
keys = IntStream.range(0, itmsCount).boxed().collect(Collectors.toList());
Thread t = new Thread(() -> {
try (Transaction tx = clnt.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
keys.forEach(k -> cache.put(k, k));
commitStart.countDown();
tx.commit();
}
});
t.start();
commitStart.await();
nearComm.waitForBlocked();
nearComm.stopBlock();
assertTrue(waitForWalUpdates(G.allGrids().stream().filter(g -> !g.configuration().isClientMode()).collect(Collectors.toList())));
} finally {
failFileIO.set(true);
stopAllGrids(true);
assertTrue(G.allGrids().isEmpty());
}
final IgniteEx srv = (IgniteEx) startGridsMultiThreaded(numSrvNodes);
srv.cluster().state(ClusterState.ACTIVE);
IgniteCache<Integer, Integer> cache = srv.cache(cacheName);
int cSize = cache.size();
boolean pr = cache.get(keys.get(0)) == null;
for (int i : keys) {
Object res = cache.get(i);
if (pr != (res == null))
assertEquals("ethalon=" + pr + ", current=" + res + ", key=" + i, pr, res == null);
}
assert (cSize == itmsCount || cSize == 0) : "unexpected cache size: " + cSize;
}
use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class EvictionPolicyFailureHandlerTest method testCacheMapDoesNotContainsWrongEntityAfterTransaction.
/**
* We expect that localPeek produces an exception, but the entry evict returns false because the transaction locks
* this entry. After transaction commit, the entry will be evicted.
*/
@Test
public void testCacheMapDoesNotContainsWrongEntityAfterTransaction() throws Exception {
LogListener lsnr = LogListener.matches(s -> s.contains("The cache entry cannot be touched")).times(1).build();
log.registerListener(lsnr);
IgniteEx node = startGrid(0);
IgniteEx client = startClientGrid(1);
GridCacheAdapter<Object, Object> cache = ((IgniteKernal) node).internalCache(DEFAULT_CACHE_NAME);
cache.put(1, 1);
CountDownLatch locPeekFinished = new CountDownLatch(1);
CountDownLatch txStarted = new CountDownLatch(1);
CountDownLatch txFinished = new CountDownLatch(1);
GridTestUtils.runAsync(() -> {
IgniteCache<Object, Object> cache1 = client.cache(DEFAULT_CACHE_NAME);
IgniteTransactions transactions = client.transactions();
try (Transaction tx = transactions.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache1.put(2.1, 2.4);
txStarted.countDown();
locPeekFinished.await();
tx.commit();
} catch (Exception ignore) {
}
txFinished.countDown();
}, "tx-thread");
txStarted.await();
try {
cache.localPeek(2.1, new CachePeekMode[] { CachePeekMode.ONHEAP });
} catch (Exception ignore) {
}
locPeekFinished.countDown();
assertTrue(lsnr.check(10_000));
txFinished.await();
assertFalse(cache.map().entrySet(cache.context().cacheId()).stream().anyMatch(e -> new Double(2.1).equals(e.key().value(null, false))));
assertEquals(ACTIVE, node.cluster().state());
}
use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testTxTraceIncludesCommunicationTracesInCaseOfCommunicationScopeInTxIncludedScopes.
/**
* Ensure that TX trace does include COMMUNICATION sub-traces in case of COMMUNICATION scope within the set
* of included scopes of the corresponding TX tracing configuration.
*
* @throws Exception If Failed.
*/
@Test
public void testTxTraceIncludesCommunicationTracesInCaseOfCommunicationScopeInTxIncludedScopes() throws Exception {
IgniteEx client = startGrid("client");
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_ALWAYS).withIncludedScopes(Collections.singleton(Scope.COMMUNICATION)).build());
Transaction tx = client.transactions().txStart(PESSIMISTIC, SERIALIZABLE);
client.cache(DEFAULT_CACHE_NAME).put(1, 1);
tx.commit();
handler().flush();
SpanId parentSpanId = handler().allSpans().filter(span -> SpanType.TX_NEAR_PREPARE.spanName().equals(span.getName())).collect(Collectors.toList()).get(0).getContext().getSpanId();
java.util.List<SpanData> gotSpans = handler().allSpans().filter(span -> parentSpanId.equals(span.getParentSpanId()) && SpanType.COMMUNICATION_SOCKET_WRITE.spanName().equals(span.getName())).collect(Collectors.toList());
assertFalse(gotSpans.isEmpty());
}
use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testThatLabelSpecificConfigurationIsUsedWheneverPossible.
/**
* Ensure that label specific configuration is used instead of scope specific if it's possible.
*
* @throws Exception If Failed.
*/
@Test
public void testThatLabelSpecificConfigurationIsUsedWheneverPossible() throws Exception {
IgniteEx client = startGrid("client");
final String txLbToBeTraced = "label1";
final String txLbNotToBeTraced = "label2";
client.tracingConfiguration().set(new TracingConfigurationCoordinates.Builder(TX).withLabel(txLbToBeTraced).build(), new TracingConfigurationParameters.Builder().withSamplingRate(SAMPLING_RATE_ALWAYS).build());
client.transactions().withLabel(txLbToBeTraced).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());
// Not to be traced, cause there's neither tracing configuration with given label
// nor scope specific tx configuration. In that case default tx tracing configuration will be used that
// actually disables tracing.
client.transactions().withLabel(txLbNotToBeTraced).txStart(PESSIMISTIC, SERIALIZABLE).commit();
handler().flush();
gotSpans = handler().allSpans().filter(span -> SpanType.TX.spanName().equals(span.getName())).collect(Collectors.toList());
// Still only one, previously detected, span is expected.
assertEquals(1, gotSpans.size());
}
use of org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC in project ignite by apache.
the class OpenCensusTxTracingConfigurationTest method testThatDefaultConfigurationIsUsedIfScopeSpecificNotFoundAndThatByDefaultTxTracingIsDisabled.
/**
* Ensure that default scope specific configuration is used if there's no neither label specif not custom scope specific ones.
* Also ensure that by default TX tracing is disabled.
*
* @throws Exception If Failed.
*/
@Test
public void testThatDefaultConfigurationIsUsedIfScopeSpecificNotFoundAndThatByDefaultTxTracingIsDisabled() throws Exception {
IgniteEx client = startGrid("client");
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());
assertTrue(gotSpans.isEmpty());
}
Aggregations