You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2019/01/11 15:36:38 UTC

[GitHub] asfgit closed pull request #5808: IGNITE-10884: Fixed failure when performing non-MVCC SQL from transactions.

asfgit closed pull request #5808: IGNITE-10884: Fixed failure when performing non-MVCC SQL from transactions.
URL: https://github.com/apache/ignite/pull/5808
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/mvcc/MvccUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/mvcc/MvccUtils.java
index 0ceed09ff66c..c6848d35ef1a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/mvcc/MvccUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/mvcc/MvccUtils.java
@@ -704,7 +704,7 @@ public static GridNearTxLocal checkActive(GridNearTxLocal tx) {
         GridNearTxLocal tx = tx0 != null && tx0.user() ? (GridNearTxLocal)tx0 : null;
 
         if (tx != null) {
-            if (!tx.pessimistic() || !tx.repeatableRead()) {
+            if (!tx.pessimistic()) {
                 tx.setRollbackOnly();
 
                 throw new UnsupportedTxModeException();
@@ -948,7 +948,7 @@ public R apply(GridCacheContext cctx, MvccSnapshot snapshot, long mvccCrd, long
         private static final long serialVersionUID = 0L;
         /** */
         private UnsupportedTxModeException() {
-            super("Only pessimistic repeatable read transactions are supported when MVCC is enabled.");
+            super("Only pessimistic transactions are supported when MVCC is enabled.");
         }
     }
 
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/MvccUnsupportedTxModesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/MvccUnsupportedTxModesTest.java
index dc1f2cb53541..e1b3e4119379 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/MvccUnsupportedTxModesTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/MvccUnsupportedTxModesTest.java
@@ -348,8 +348,10 @@ private void checkOperation(Runnable action) {
         assertNotSupportedInTx(action, OPTIMISTIC, READ_COMMITTED);
         assertNotSupportedInTx(action, OPTIMISTIC, REPEATABLE_READ);
         assertNotSupportedInTx(action, OPTIMISTIC, SERIALIZABLE);
-        assertNotSupportedInTx(action, PESSIMISTIC, READ_COMMITTED);
-        assertNotSupportedInTx(action, PESSIMISTIC, SERIALIZABLE);
+
+        assertSupportedInTx(action, PESSIMISTIC, READ_COMMITTED);
+        assertSupportedInTx(action, PESSIMISTIC, REPEATABLE_READ);
+        assertSupportedInTx(action, PESSIMISTIC, SERIALIZABLE);
     }
 
     /** */
@@ -360,7 +362,16 @@ private void assertNotSupportedInTx(Runnable action, TransactionConcurrency conc
             fail("Action failure is expected.");
         }
         catch (TransactionException e) {
-            assertEquals("Only pessimistic repeatable read transactions are supported when MVCC is enabled.", e.getMessage());
+            assertEquals("Only pessimistic transactions are supported when MVCC is enabled.", e.getMessage());
+        }
+    }
+
+    /** */
+    private void assertSupportedInTx(Runnable action, TransactionConcurrency conc, TransactionIsolation iso) {
+        try (Transaction tx = grid(0).transactions().txStart(conc, iso)) {
+            action.run();
+
+            tx.commit();
         }
     }
 }
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 53530a37f78c..4c26e357c90b 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -177,10 +177,10 @@
 import static org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.TEXT;
 import static org.apache.ignite.internal.processors.query.h2.PreparedStatementEx.MVCC_CACHE_ID;
 import static org.apache.ignite.internal.processors.query.h2.PreparedStatementEx.MVCC_STATE;
-import static org.apache.ignite.internal.processors.query.h2.opt.join.DistributedJoinMode.OFF;
-import static org.apache.ignite.internal.processors.query.h2.opt.join.DistributedJoinMode.distributedJoinMode;
 import static org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryType.LOCAL;
 import static org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryType.PREPARE;
+import static org.apache.ignite.internal.processors.query.h2.opt.join.DistributedJoinMode.OFF;
+import static org.apache.ignite.internal.processors.query.h2.opt.join.DistributedJoinMode.distributedJoinMode;
 
 /**
  * Indexing implementation based on H2 database engine. In this implementation main query language is SQL,
@@ -1119,7 +1119,7 @@ else if (mvccEnabled != cctx.mvccEnabled())
             final MvccQueryTracker tracker = mvccTracker == null && qry.mvccEnabled() ?
                 MvccUtils.mvccTracker(ctx.cache().context().cacheContext(qry.cacheIds().get(0)), startTx) : mvccTracker;
 
-            GridNearTxLocal tx = tx(ctx);
+            GridNearTxLocal tx = tracker != null ? tx(ctx) : null;
 
             if (qry.forUpdate())
                 qry.forUpdate(checkActive(tx) != null);
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlTxModesTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlTxModesTest.java
new file mode 100644
index 000000000000..05f30b6af498
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlTxModesTest.java
@@ -0,0 +1,213 @@
+/*
+ * 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.mvcc;
+
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE;
+
+/**
+ *
+ */
+public class CacheMvccSqlTxModesTest extends CacheMvccAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /**
+     * @throws Exception If failed
+     */
+    @Test
+    public void testSqlTransactionModesNoMvcc() throws Exception {
+        IgniteEx node = startGrid(0);
+
+        IgniteCache<Object, Object> nonMvccCache = node.createCache(new CacheConfiguration<>("no-mvcc-cache")
+            .setAtomicityMode(TRANSACTIONAL).setIndexedTypes(Integer.class, Integer.class));
+
+        nonMvccCache.put(1,1);
+
+        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, READ_COMMITTED)) {
+            nonMvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
+            nonMvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
+            nonMvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+            nonMvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+            nonMvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, SERIALIZABLE)) {
+            nonMvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
+            nonMvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer").setLocal(true)).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, SERIALIZABLE)) {
+            nonMvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer").setLocal(true)).getAll();
+
+            tx.commit();
+        }
+    }
+
+    /**
+     * @throws Exception If failed
+     */
+    @Test
+    public void testSqlTransactionModesMvcc() throws Exception {
+        IgniteEx node = startGrid(0);
+
+        IgniteCache<Object, Object> mvccCache = node.createCache(new CacheConfiguration<>("mvcc-cache")
+            .setAtomicityMode(TRANSACTIONAL_SNAPSHOT).setIndexedTypes(Integer.class, Integer.class));
+
+        mvccCache.put(1,1);
+
+        GridTestUtils.assertThrows(log, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                try (Transaction tx = node.transactions().txStart(OPTIMISTIC, READ_COMMITTED)) {
+                    mvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+                    tx.commit();
+                }
+
+                return null;
+            }
+        }, CacheException.class, "Only pessimistic transactions are supported when MVCC is enabled");
+
+        GridTestUtils.assertThrows(log, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
+                    mvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+                    tx.commit();
+                }
+
+                return null;
+            }
+        }, CacheException.class, "Only pessimistic transactions are supported when MVCC is enabled");
+
+        GridTestUtils.assertThrows(log, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                try (Transaction tx = node.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
+                    mvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+                    tx.commit();
+                }
+
+                return null;
+            }
+        }, CacheException.class, "Only pessimistic transactions are supported when MVCC is enabled");
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+            mvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+            mvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, SERIALIZABLE)) {
+            mvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll();
+
+            tx.commit();
+        }
+    }
+
+    /**
+     * @throws Exception If failed
+     */
+    @Test
+    public void testConsequentMvccNonMvccOperations() throws Exception {
+        IgniteEx node = startGrid(0);
+
+        IgniteCache<Object, Object> mvccCache = node.createCache(new CacheConfiguration<>("mvcc-cache")
+            .setAtomicityMode(TRANSACTIONAL_SNAPSHOT).setIndexedTypes(Integer.class, Integer.class));
+
+        IgniteCache<Object, Object> nonMvccCache = node.createCache(new CacheConfiguration<>("no-mvcc-cache")
+            .setAtomicityMode(TRANSACTIONAL).setIndexedTypes(Integer.class, Integer.class));
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+            nonMvccCache.put(1, 1);
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+            mvccCache.query(new SqlFieldsQuery("INSERT INTO Integer (_key, _val) VALUES (3,3)")).getAll();
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+            nonMvccCache.put(2, 2);
+
+            tx.commit();
+        }
+
+        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+            mvccCache.query(new SqlFieldsQuery("INSERT INTO Integer (_key, _val) VALUES (5,5)")).getAll();
+
+            tx.commit();
+        }
+    }
+}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccSqlTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccSqlTestSuite.java
index bdc766456504..04189145dba3 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccSqlTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccSqlTestSuite.java
@@ -62,6 +62,7 @@
 import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccSqlContinuousQueryPartitionedSelfTest;
 import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccSqlContinuousQueryReplicatedSelfTest;
 import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccSqlLockTimeoutTest;
+import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccSqlTxModesTest;
 import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccSqlUpdateCountersTest;
 import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccStreamingInsertTest;
 import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccTxNodeMappingTest;
@@ -87,7 +88,7 @@
     CacheMvccSizeTest.class,
     CacheMvccSqlUpdateCountersTest.class,
     CacheMvccSqlLockTimeoutTest.class,
-
+    CacheMvccSqlTxModesTest.class,
     GridIndexRebuildWithMvccEnabledSelfTest.class,
 
     CacheMvccTxNodeMappingTest.class,


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services