Search in sources :

Example 1 with READ_COMMITTED

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

the class FunctionalTest method testTransactionsWithLabel.

/**
 * Test transactions with label.
 */
@Test
public void testTransactionsWithLabel() throws Exception {
    try (IgniteEx ignite = (IgniteEx) Ignition.start(Config.getServerConfiguration());
        IgniteClient client = Ignition.startClient(getClientConfiguration())) {
        ClientCache<Integer, String> cache = client.createCache(new ClientCacheConfiguration().setName("cache").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
        SystemView<TransactionView> txsView = ignite.context().systemView().view(TXS_MON_LIST);
        cache.put(0, "value1");
        try (ClientTransaction tx = client.transactions().withLabel("label").txStart()) {
            cache.put(0, "value2");
            assertEquals(1, F.size(txsView.iterator()));
            TransactionView txv = txsView.iterator().next();
            assertEquals("label", txv.label());
            assertEquals("value2", cache.get(0));
        }
        assertEquals("value1", cache.get(0));
        try (ClientTransaction tx = client.transactions().withLabel("label1").withLabel("label2").txStart()) {
            cache.put(0, "value2");
            assertEquals(1, F.size(txsView.iterator()));
            TransactionView txv = txsView.iterator().next();
            assertEquals("label2", txv.label());
            tx.commit();
        }
        assertEquals("value2", cache.get(0));
        // Test concurrent with label and without label transactions.
        try (ClientTransaction tx = client.transactions().withLabel("label").txStart(PESSIMISTIC, READ_COMMITTED)) {
            CyclicBarrier barrier = new CyclicBarrier(2);
            cache.put(0, "value3");
            IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
                try (ClientTransaction tx1 = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
                    cache.put(1, "value3");
                    barrier.await();
                    assertEquals("value2", cache.get(0));
                    barrier.await();
                } catch (InterruptedException | BrokenBarrierException ignore) {
                // No-op.
                }
            });
            barrier.await();
            assertNull(cache.get(1));
            assertEquals(1, F.size(txsView.iterator(), txv -> txv.label() == null));
            assertEquals(1, F.size(txsView.iterator(), txv -> "label".equals(txv.label())));
            barrier.await();
            fut.get();
        }
        // Test nested transactions is not possible.
        try (ClientTransaction tx = client.transactions().withLabel("label1").txStart()) {
            try (ClientTransaction tx1 = client.transactions().txStart()) {
                fail();
            } catch (ClientException expected) {
            // No-op.
            }
            try (ClientTransaction tx1 = client.transactions().withLabel("label2").txStart()) {
                fail();
            } catch (ClientException expected) {
            // No-op.
            }
        }
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ModifiedExpiryPolicy(javax.cache.expiry.ModifiedExpiryPolicy) BinaryObject(org.apache.ignite.binary.BinaryObject) Arrays(java.util.Arrays) AbstractBinaryArraysTest(org.apache.ignite.internal.binary.AbstractBinaryArraysTest) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) Date(java.util.Date) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) TestEnum(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) AccessedExpiryPolicy(javax.cache.expiry.AccessedExpiryPolicy) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) VAL3(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL3) VAL1(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL1) VAL2(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL2) Map(java.util.Map) QueryEntity(org.apache.ignite.cache.QueryEntity) ClientStatus(org.apache.ignite.internal.processors.platform.client.ClientStatus) GridTestUtils.assertThrowsAnyCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause) CyclicBarrier(java.util.concurrent.CyclicBarrier) ImmutableSet(com.google.common.collect.ImmutableSet) CachePeekMode(org.apache.ignite.cache.CachePeekMode) SystemView(org.apache.ignite.spi.systemview.view.SystemView) TransactionView(org.apache.ignite.spi.systemview.view.TransactionView) Set(java.util.Set) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) ClientListenerProcessor(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) IntStream(java.util.stream.IntStream) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) ClientServerError(org.apache.ignite.internal.client.thin.ClientServerError) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) PartitionLossPolicy(org.apache.ignite.cache.PartitionLossPolicy) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ClientProcessorMXBean(org.apache.ignite.mxbean.ClientProcessorMXBean) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Timeout(org.junit.rules.Timeout) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LinkedList(java.util.LinkedList) SimpleEntry(java.util.AbstractMap.SimpleEntry) Duration(javax.cache.expiry.Duration) F(org.apache.ignite.internal.util.typedef.F) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) Iterator(java.util.Iterator) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2) TimeUnit(java.util.concurrent.TimeUnit) Ignition(org.apache.ignite.Ignition) Rule(org.junit.Rule) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) IgniteEx(org.apache.ignite.internal.IgniteEx) TransactionView(org.apache.ignite.spi.systemview.view.TransactionView) AbstractBinaryArraysTest(org.apache.ignite.internal.binary.AbstractBinaryArraysTest) Test(org.junit.Test)

Example 2 with READ_COMMITTED

use of org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED 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 3 with READ_COMMITTED

use of org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED 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();
}
Also used : RandomAccessFile(java.io.RandomAccessFile) BlockedWarmUpConfiguration(org.apache.ignite.internal.processors.cache.warmup.BlockedWarmUpConfiguration) Arrays(java.util.Arrays) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) UnaryOperator(java.util.function.UnaryOperator) GridConcurrentHashSet(org.apache.ignite.internal.client.util.GridConcurrentHashSet) EntryProcessor(javax.cache.processor.EntryProcessor) BooleanSupplier(java.util.function.BooleanSupplier) GridFunc(org.apache.ignite.internal.util.lang.GridFunc) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) REENCRYPTION_RESUME(org.apache.ignite.internal.commandline.encryption.EncryptionSubcommands.REENCRYPTION_RESUME) Matcher(java.util.regex.Matcher) EXIT_CODE_INVALID_ARGUMENTS(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS) Map(java.util.Map) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Path(java.nio.file.Path) GridDhtTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) IgniteCacheGroupsWithRestartsTest(org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) GridClientFactory(org.apache.ignite.internal.client.GridClientFactory) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) VisorFindAndDeleteGarbageInPersistenceTaskResult(org.apache.ignite.internal.visor.cache.VisorFindAndDeleteGarbageInPersistenceTaskResult) Set(java.util.Set) ChangeGlobalStateFinishMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) MASTER_KEY_NAME_2(org.apache.ignite.internal.encryption.AbstractEncryptionTest.MASTER_KEY_NAME_2) IgniteCache(org.apache.ignite.IgniteCache) EXIT_CODE_CONNECTION_FAILED(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_CONNECTION_FAILED) Serializable(java.io.Serializable) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) READ_ONLY_SAFE(org.apache.ignite.cache.PartitionLossPolicy.READ_ONLY_SAFE) REENCRYPTION_SUSPEND(org.apache.ignite.internal.commandline.encryption.EncryptionSubcommands.REENCRYPTION_SUSPEND) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) GridClientImpl(org.apache.ignite.internal.client.impl.GridClientImpl) GridClusterStateProcessor(org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) CACHE_GROUP_KEY_IDS(org.apache.ignite.internal.commandline.encryption.EncryptionSubcommands.CACHE_GROUP_KEY_IDS) EntryProcessorException(javax.cache.processor.EntryProcessorException) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) REENCRYPTION_RATE(org.apache.ignite.internal.commandline.encryption.EncryptionSubcommands.REENCRYPTION_RATE) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) BlockedWarmUpStrategy(org.apache.ignite.internal.processors.cache.warmup.BlockedWarmUpStrategy) ACTIVE_READ_ONLY(org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) REENCRYPTION_STATUS(org.apache.ignite.internal.commandline.encryption.EncryptionSubcommands.REENCRYPTION_STATUS) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) DEFAULT_TARGET_FOLDER(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.DEFAULT_TARGET_FOLDER) Files(java.nio.file.Files) IOException(java.io.IOException) IgniteSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Field(java.lang.reflect.Field) BaselineNode(org.apache.ignite.cluster.BaselineNode) File(java.io.File) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridNearLockResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) AtomicLong(java.util.concurrent.atomic.AtomicLong) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteFinishedFutureImpl(org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) LongMetric(org.apache.ignite.spi.metric.LongMetric) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) CheckpointState(org.apache.ignite.internal.processors.cache.persistence.CheckpointState) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest) SNAPSHOT_METRICS(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNAPSHOT_METRICS) IgniteNodeAttributes(org.apache.ignite.internal.IgniteNodeAttributes) Transaction(org.apache.ignite.transactions.Transaction) CONFIRM_MSG(org.apache.ignite.internal.commandline.CommandHandler.CONFIRM_MSG) GridTestUtils.assertThrows(org.apache.ignite.testframework.GridTestUtils.assertThrows) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) MutableEntry(javax.cache.processor.MutableEntry) CHANGE_CACHE_GROUP_KEY(org.apache.ignite.internal.commandline.encryption.EncryptionSubcommands.CHANGE_CACHE_GROUP_KEY) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) X(org.apache.ignite.internal.util.typedef.X) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) TestStorageUtils.corruptDataEntry(org.apache.ignite.util.TestStorageUtils.corruptDataEntry) DEACTIVATE(org.apache.ignite.internal.commandline.CommandList.DEACTIVATE) IgniteFuture(org.apache.ignite.lang.IgniteFuture) File.separatorChar(java.io.File.separatorChar) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) UUID(java.util.UUID) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl) IGNITE_CLUSTER_NAME(org.apache.ignite.IgniteSystemProperties.IGNITE_CLUSTER_NAME) Collectors(java.util.stream.Collectors) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GRID_NOT_IDLE_MSG(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.GRID_NOT_IDLE_MSG) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) CU(org.apache.ignite.internal.util.typedef.internal.CU) Pattern(java.util.regex.Pattern) ShutdownPolicy(org.apache.ignite.ShutdownPolicy) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) ClusterStateTestUtils(org.apache.ignite.internal.processors.cache.ClusterStateTestUtils) NotNull(org.jetbrains.annotations.NotNull) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) GridJobExecuteResponse(org.apache.ignite.internal.GridJobExecuteResponse) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IntStream(java.util.stream.IntStream) LongAdder(java.util.concurrent.atomic.LongAdder) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteSnapshotManager.resolveSnapshotWorkDirectory(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.resolveSnapshotWorkDirectory) HashMap(java.util.HashMap) Function(java.util.function.Function) WarmUpTestPluginProvider(org.apache.ignite.internal.processors.cache.warmup.WarmUpTestPluginProvider) ToFileDumpProcessor(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.dumpprocessors.ToFileDumpProcessor) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) IGNITE_PDS_SKIP_CHECKPOINT_ON_NODE_STOP(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.IGNITE_PDS_SKIP_CHECKPOINT_ON_NODE_STOP) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) OpenOption(java.nio.file.OpenOption) AbstractSnapshotSelfTest.snp(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.snp) FindAndDeleteGarbageArg(org.apache.ignite.internal.commandline.cache.argument.FindAndDeleteGarbageArg) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) EXIT_CODE_UNEXPECTED_ERROR(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) TimeUnit(java.util.concurrent.TimeUnit) BitSet(java.util.BitSet) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) ChangeGlobalStateFinishMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GridDhtTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridConcurrentHashSet(org.apache.ignite.internal.client.util.GridConcurrentHashSet) IgniteUuid(org.apache.ignite.lang.IgniteUuid) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) IgniteException(org.apache.ignite.IgniteException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) LongAdder(java.util.concurrent.atomic.LongAdder) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicLong(java.util.concurrent.atomic.AtomicLong) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) IgniteCacheGroupsWithRestartsTest(org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) Test(org.junit.Test)

Example 4 with READ_COMMITTED

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

the class TxRecoveryWithConcurrentRollbackTest method testTxDoesntBecomePreparedAfterError.

/**
 * Start 3 servers,
 * start 2 clients,
 * start two OPTIMISTIC transactions with the same key from different client nodes,
 * trying to transfer both to PREPARED state,
 * stop one client node.
 */
@Test
public void testTxDoesntBecomePreparedAfterError() throws Exception {
    backups = 2;
    persistence = true;
    syncMode = FULL_ASYNC;
    final IgniteEx node0 = startGrids(3);
    node0.cluster().state(ACTIVE);
    final IgniteEx client1 = startGrid("client1");
    final IgniteEx client2 = startGrid("client2");
    awaitPartitionMapExchange();
    final IgniteCache<Object, Object> cache = client1.cache(DEFAULT_CACHE_NAME);
    final IgniteCache<Object, Object> cache2 = client2.cache(DEFAULT_CACHE_NAME);
    final Integer pk = primaryKey(node0.cache(DEFAULT_CACHE_NAME));
    CountDownLatch txPrepareLatch = new CountDownLatch(1);
    GridTestUtils.runMultiThreadedAsync(() -> {
        try (final Transaction tx = client1.transactions().withLabel("tx1").txStart(OPTIMISTIC, READ_COMMITTED, 5000, 1)) {
            cache.put(pk, Boolean.TRUE);
            TransactionProxyImpl p = (TransactionProxyImpl) tx;
            // To prevent tx rollback on exit from try-with-resource block, this should cause another tx timeout fail.
            spi(client1).blockMessages((node, msg) -> msg instanceof GridNearTxFinishRequest);
            log.info("Test, preparing tx: xid=" + tx.xid() + ", tx=" + tx);
            // Doing only prepare to try to lock the key, commit is not needed here.
            p.tx().prepareNearTxLocal();
            p.tx().currentPrepareFuture().listen(fut -> txPrepareLatch.countDown());
        } catch (Exception e) {
        // No-op.
        }
    }, 1, "tx1-thread");
    try (final Transaction tx = client2.transactions().withLabel("tx2").txStart(OPTIMISTIC, READ_COMMITTED, 5000, 1)) {
        cache2.put(pk, Boolean.TRUE);
        TransactionProxyImpl p = (TransactionProxyImpl) tx;
        log.info("Test, preparing tx: xid=" + tx.xid() + ", tx=" + tx);
        p.tx().prepareNearTxLocal();
        p.tx().currentPrepareFuture().listen(fut -> txPrepareLatch.countDown());
        txPrepareLatch.await(6, TimeUnit.SECONDS);
        if (txPrepareLatch.getCount() > 0)
            fail("Failed to await for tx prepare.");
        AtomicReference<GridDhtTxLocal> dhtTxLocRef = new AtomicReference<>();
        assertTrue(waitForCondition(() -> {
            dhtTxLocRef.set((GridDhtTxLocal) txs(node0).stream().filter(t -> t.state() == TransactionState.PREPARING).findFirst().orElse(null));
            return dhtTxLocRef.get() != null;
        }, 6_000));
        assertNotNull(dhtTxLocRef.get());
        UUID clientNodeToFail = dhtTxLocRef.get().eventNodeId();
        GridDhtTxPrepareFuture prep = GridTestUtils.getFieldValue(dhtTxLocRef.get(), "prepFut");
        prep.get();
        List<IgniteInternalTx> txs = txs(node0);
        String txsStr = txs.stream().map(Object::toString).collect(Collectors.joining(", "));
        log.info("Transactions check point [count=" + txs.size() + ", txs=" + txsStr + "]");
        if (clientNodeToFail.equals(client1.localNode().id()))
            client1.close();
        else if (clientNodeToFail.equals(client2.localNode().id()))
            client2.close();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    U.sleep(500);
    assertEquals(3, grid(1).context().discovery().aliveServerNodes().size());
    assertEquals(txs(client1).toString() + ", " + txs(client2).toString(), 1, txs(client1).size() + txs(client2).size());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TestRecordingCommunicationSpi.spi(org.apache.ignite.internal.TestRecordingCommunicationSpi.spi) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest) Transaction(org.apache.ignite.transactions.Transaction) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) FULL_ASYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_ASYNC) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtTxLocal(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocal) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) GridDhtTxPrepareFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) GridDhtTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridCacheTxRecoveryRequest(org.apache.ignite.internal.processors.cache.distributed.GridCacheTxRecoveryRequest) TransactionState(org.apache.ignite.transactions.TransactionState) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PRIMARY_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC) GridDhtTxLocal(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocal) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest) UUID(java.util.UUID) GridDhtTxPrepareFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

List (java.util.List)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Collectors (java.util.stream.Collectors)4 Ignite (org.apache.ignite.Ignite)4 IgniteCache (org.apache.ignite.IgniteCache)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 U (org.apache.ignite.internal.util.typedef.internal.U)4 Transaction (org.apache.ignite.transactions.Transaction)4 PESSIMISTIC (org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC)4 READ_COMMITTED (org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 UUID (java.util.UUID)3 File (java.io.File)2 IOException (java.io.IOException)2 OpenOption (java.nio.file.OpenOption)2