This is an automated email from the ASF dual-hosted git repository.

sk0x50 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new c68d2f7  IGNITE-15777 PME hangs on client due to implicit transaction 
committing. Fixes #9502
c68d2f7 is described below

commit c68d2f70842097b6b85f0ea3a95b067846bd0a8f
Author: Vladislav Pyatkov <[email protected]>
AuthorDate: Thu Oct 21 21:04:39 2021 +0300

    IGNITE-15777 PME hangs on client due to implicit transaction committing. 
Fixes #9502
    
    Signed-off-by: Slava Koptilin <[email protected]>
---
 .../processors/cache/GridCacheProcessor.java       |   4 +-
 .../cache/transactions/IgniteTxManager.java        |   4 +-
 .../StartImplicitlyTxOnStopCacheTest.java          | 103 +++++++++++++++++++++
 .../TxRollbackDuringPreparingTest.java             | 102 ++++++++++++++++++++
 .../ignite/testsuites/IgniteCacheTestSuite6.java   |   6 ++
 5 files changed, 215 insertions(+), 4 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 89ec474..5ff1d3e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -2846,10 +2846,10 @@ public class GridCacheProcessor extends 
GridProcessorAdapter {
                         }
 
                         for (ExchangeActions.CacheActionData action : 
cachesToStopByGrp.getValue()) {
-                            stopGateway(action.request());
-
                             
context().tm().rollbackTransactionsForStoppingCache(action.descriptor().cacheId());
 
+                            stopGateway(action.request());
+
                             String cacheName = action.request().cacheName();
 
                             // TTL manager has to be unregistered before the 
checkpointReadLock is acquired.
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
index d4a591e..98c1ed4 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
@@ -3324,13 +3324,13 @@ public class IgniteTxManager extends 
GridCacheSharedManagerAdapter {
                                         if (tx.state() == PREPARED)
                                             processPrepared(tx, evtNodeId);
                                             // If we could not mark tx as 
rollback, it means that transaction is being committed.
-                                        else if (tx.setRollbackOnly())
+                                        else if (tx.state() == MARKED_ROLLBACK 
|| tx.setRollbackOnly())
                                             tx.rollbackAsync();
                                     });
                                 }
                                 // If we could not mark tx as rollback, it 
means that transaction
                                 // is either being committed or already marked 
as rollback.
-                                else if (tx.setRollbackOnly() || tx.state() == 
MARKED_ROLLBACK)
+                                else if (tx.state() == MARKED_ROLLBACK || 
tx.setRollbackOnly())
                                     tx.rollbackAsync();
                             }
                         }
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/StartImplicitlyTxOnStopCacheTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/StartImplicitlyTxOnStopCacheTest.java
new file mode 100644
index 0000000..3305d84
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/StartImplicitlyTxOnStopCacheTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.TestRecordingCommunicationSpi;
+import 
org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture;
+import 
org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware;
+import 
org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * The test starts an implicit transaction during the cache is stopping.
+ * The transaction has to be completed, and the cache is stopped.
+ */
+public class StartImplicitlyTxOnStopCacheTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName)
+            .setConsistentId(igniteInstanceName)
+            .setCommunicationSpi(new TestRecordingCommunicationSpi())
+            .setCacheConfiguration(new CacheConfiguration(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void test() throws Exception {
+        IgniteEx ignite0 = startGrid(0);
+
+        IgniteEx client = startClientGrid("client");
+
+        IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
+
+        for (int i = 0; i < 100; i++)
+            cache.put(i, i);
+
+        TestRecordingCommunicationSpi commSpiClient = 
TestRecordingCommunicationSpi.spi(client);
+
+        commSpiClient.blockMessages(GridNearTxPrepareRequest.class, 
getTestIgniteInstanceName(0));
+
+        CyclicBarrier exchnageStartedBarrier = new CyclicBarrier(2, 
commSpiClient::stopBlock);
+
+        
ignite0.context().cache().context().exchange().registerExchangeAwareComponent(new
 PartitionsExchangeAware() {
+            @Override public void 
onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
+                try {
+                    exchnageStartedBarrier.await();
+                }
+                catch (InterruptedException | BrokenBarrierException e) {
+                    log.error("Exchange delay was interrupted.", e);
+                }
+            }
+        });
+
+        IgniteInternalFuture runTxFut = GridTestUtils.runAsync(() -> 
cache.put(100, 100));
+
+        IgniteInternalFuture destroyCacheFut = GridTestUtils.runAsync(() ->
+            client.destroyCache(DEFAULT_CACHE_NAME));
+
+        exchnageStartedBarrier.await();
+
+        assertTrue(GridTestUtils.waitForCondition(destroyCacheFut::isDone, 
10_000));
+
+        assertTrue(GridTestUtils.waitForCondition(runTxFut::isDone, 10_000));
+
+        assertNull(client.cache(DEFAULT_CACHE_NAME));
+    }
+}
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackDuringPreparingTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackDuringPreparingTest.java
new file mode 100644
index 0000000..2e0d3e6
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackDuringPreparingTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.transactions;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.TestRecordingCommunicationSpi;
+import 
org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.junit.Test;
+
+/**
+ * Transaction rolls back during the prepare phase, before a prepare request 
was sent to dht nodes.
+ * It should lead to the full transaction rollback.
+ */
+public class TxRollbackDuringPreparingTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setConsistentId(igniteInstanceName)
+            .setCommunicationSpi(new TestRecordingCommunicationSpi())
+            .setCacheConfiguration(new CacheConfiguration(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+                .setBackups(2));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void test() throws Exception {
+        IgniteEx ignite0 = startGrids(3);
+
+        awaitPartitionMapExchange();
+
+        int key = primaryKey(ignite(1).cache(DEFAULT_CACHE_NAME));
+
+        IgniteEx client = startClientGrid("client");
+
+        waitForTopology(4);
+
+        
TestRecordingCommunicationSpi.spi(ignite(1)).blockMessages(GridDhtTxPrepareRequest.class,
 getTestIgniteInstanceName(0));
+        
TestRecordingCommunicationSpi.spi(ignite(1)).blockMessages(GridDhtTxPrepareRequest.class,
 getTestIgniteInstanceName(2));
+
+        IgniteCache cache = client.cache(DEFAULT_CACHE_NAME);
+
+        long txTimeout = 1_000;
+
+        IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
+            Transaction tx = client.transactions().txStart(
+                TransactionConcurrency.OPTIMISTIC,
+                TransactionIsolation.SERIALIZABLE,
+                txTimeout,
+                1
+            );
+
+            cache.put(key, key);
+
+            tx.commit();
+        });
+
+        TestRecordingCommunicationSpi.spi(ignite(1)).waitForBlocked();
+
+        ignite(0).context().discovery().failNode(client.localNode().id(), 
"Stop the client!");
+
+        doSleep(2 * txTimeout);
+
+        TestRecordingCommunicationSpi.spi(ignite(1)).stopBlock();
+
+        GridTestUtils.assertThrows(log, () -> fut.get(10_000), 
IgniteCheckedException.class, "");
+
+        ignite0.createCache(DEFAULT_CACHE_NAME + 1);
+
+        awaitPartitionMapExchange();
+
+        assertNull(cache.get(key));
+    }
+}
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite6.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite6.java
index 9fb6c24..b46fc6f 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite6.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite6.java
@@ -51,6 +51,7 @@ import 
org.apache.ignite.internal.processors.cache.distributed.OnePhaseCommitAnd
 import 
org.apache.ignite.internal.processors.cache.distributed.PartitionsExchangeAwareTest;
 import 
org.apache.ignite.internal.processors.cache.distributed.dht.preloader.latch.ExchangeLatchManagerTest;
 import 
org.apache.ignite.internal.processors.cache.distributed.rebalancing.GridCacheRebalancingOrderingTest;
+import 
org.apache.ignite.internal.processors.cache.transactions.StartImplicitlyTxOnStopCacheTest;
 import org.apache.ignite.internal.processors.cache.transactions.TxLabelTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxLocalDhtMixedCacheModesTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxMultiCacheAsyncOpsTest;
@@ -61,6 +62,7 @@ import 
org.apache.ignite.internal.processors.cache.transactions.TxOptimisticPrep
 import 
org.apache.ignite.internal.processors.cache.transactions.TxOptimisticReadThroughTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackAsyncNearCacheTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackAsyncTest;
+import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackDuringPreparingTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnIncorrectParamsTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnMapOnInvalidTopologyTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnTimeoutNearCacheTest;
@@ -164,6 +166,10 @@ public class IgniteCacheTestSuite6 {
 
         GridTestUtils.addTestIfNeeded(suite, 
SysCacheInconsistencyInternalKeyTest.class, ignoredTests);
 
+        GridTestUtils.addTestIfNeeded(suite, 
TxRollbackDuringPreparingTest.class, ignoredTests);
+
+        GridTestUtils.addTestIfNeeded(suite, 
StartImplicitlyTxOnStopCacheTest.class, ignoredTests);
+
         return suite;
     }
 }

Reply via email to