Search in sources :

Example 6 with PESSIMISTIC

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;
}
Also used : IntStream(java.util.stream.IntStream) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) Arrays(java.util.Arrays) Transaction(org.apache.ignite.transactions.Transaction) ClusterState(org.apache.ignite.cluster.ClusterState) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteHandle(org.apache.ignite.internal.processors.cache.persistence.wal.filehandle.FileWriteHandle) ByteBuffer(java.nio.ByteBuffer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) FileIODecorator(org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator) IGNITE_PDS_SKIP_CHECKPOINT_ON_NODE_STOP(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.IGNITE_PDS_SKIP_CHECKPOINT_ON_NODE_STOP) Parameterized(org.junit.runners.Parameterized) G(org.apache.ignite.internal.util.typedef.G) WALMode(org.apache.ignite.configuration.WALMode) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) OpenOption(java.nio.file.OpenOption) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) File(java.io.File) IgniteCache(org.apache.ignite.IgniteCache) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) DFLT_BUSYWAIT_SLEEP_INTERVAL(org.apache.ignite.testframework.GridTestUtils.DFLT_BUSYWAIT_SLEEP_INTERVAL) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) MappedByteBuffer(java.nio.MappedByteBuffer) CacheMode(org.apache.ignite.cache.CacheMode) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest)

Example 7 with PESSIMISTIC

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());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Affinity(org.apache.ignite.cache.affinity.Affinity) Transaction(org.apache.ignite.transactions.Transaction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) Factory(javax.cache.configuration.Factory) IgniteKernal(org.apache.ignite.internal.IgniteKernal) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) CachePeekMode(org.apache.ignite.cache.CachePeekMode) FailureHandler(org.apache.ignite.failure.FailureHandler) Test(org.junit.Test) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) SortedEvictionPolicy(org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicy) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) SortedEvictionPolicyFactory(org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicyFactory) CountDownLatch(java.util.concurrent.CountDownLatch) EvictionPolicy(org.apache.ignite.cache.eviction.EvictionPolicy) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) IgniteTransactions(org.apache.ignite.IgniteTransactions) EvictableEntry(org.apache.ignite.cache.eviction.EvictableEntry) IgniteKernal(org.apache.ignite.internal.IgniteKernal) LogListener(org.apache.ignite.testframework.LogListener) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteTransactions(org.apache.ignite.IgniteTransactions) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with PESSIMISTIC

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());
}
Also used : Arrays(java.util.Arrays) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) Transaction(org.apache.ignite.transactions.Transaction) Set(java.util.Set) IgniteEx(org.apache.ignite.internal.IgniteEx) Scope(org.apache.ignite.spi.tracing.Scope) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SpanData(io.opencensus.trace.export.SpanData) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) TX(org.apache.ignite.spi.tracing.Scope.TX) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) SpanId(io.opencensus.trace.SpanId) SAMPLING_RATE_NEVER(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_NEVER) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Collections(java.util.Collections) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) Transaction(org.apache.ignite.transactions.Transaction) SpanData(io.opencensus.trace.export.SpanData) IgniteEx(org.apache.ignite.internal.IgniteEx) SpanId(io.opencensus.trace.SpanId) Test(org.junit.Test)

Example 9 with PESSIMISTIC

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());
}
Also used : Arrays(java.util.Arrays) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) Transaction(org.apache.ignite.transactions.Transaction) Set(java.util.Set) IgniteEx(org.apache.ignite.internal.IgniteEx) Scope(org.apache.ignite.spi.tracing.Scope) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SpanData(io.opencensus.trace.export.SpanData) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) TX(org.apache.ignite.spi.tracing.Scope.TX) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) SpanId(io.opencensus.trace.SpanId) SAMPLING_RATE_NEVER(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_NEVER) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Collections(java.util.Collections) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) SpanData(io.opencensus.trace.export.SpanData) IgniteEx(org.apache.ignite.internal.IgniteEx) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) Test(org.junit.Test)

Example 10 with PESSIMISTIC

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());
}
Also used : Arrays(java.util.Arrays) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SpanType(org.apache.ignite.internal.processors.tracing.SpanType) Transaction(org.apache.ignite.transactions.Transaction) Set(java.util.Set) IgniteEx(org.apache.ignite.internal.IgniteEx) Scope(org.apache.ignite.spi.tracing.Scope) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SpanData(io.opencensus.trace.export.SpanData) OpenCensusTracingSpi(org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi) TX(org.apache.ignite.spi.tracing.Scope.TX) SAMPLING_RATE_ALWAYS(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS) TracingConfigurationParameters(org.apache.ignite.spi.tracing.TracingConfigurationParameters) TracingSpi(org.apache.ignite.spi.tracing.TracingSpi) SpanId(io.opencensus.trace.SpanId) SAMPLING_RATE_NEVER(org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_NEVER) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Collections(java.util.Collections) TracingConfigurationCoordinates(org.apache.ignite.spi.tracing.TracingConfigurationCoordinates) SpanData(io.opencensus.trace.export.SpanData) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)20 Transaction (org.apache.ignite.transactions.Transaction)20 PESSIMISTIC (org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC)20 Test (org.junit.Test)20 Collectors (java.util.stream.Collectors)16 IgniteCache (org.apache.ignite.IgniteCache)12 Arrays (java.util.Arrays)11 List (java.util.List)11 Set (java.util.Set)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 Ignite (org.apache.ignite.Ignite)11 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)11 Collections (java.util.Collections)10 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)10 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)10 G (org.apache.ignite.internal.util.typedef.G)10 REPEATABLE_READ (org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ)10 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9