You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by gv...@apache.org on 2019/01/11 15:33:27 UTC
[ignite] branch master updated: IGNITE-10884: Fixed failure when
performing non-MVCC SQL from transactions. This closes #5808.
This is an automated email from the ASF dual-hosted git repository.
gvvinblade 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 f76acd7 IGNITE-10884: Fixed failure when performing non-MVCC SQL from transactions. This closes #5808.
f76acd7 is described below
commit f76acd7006765023586e782272d6907b57b87d86
Author: rkondakov <ko...@mail.ru>
AuthorDate: Fri Jan 11 18:33:01 2019 +0300
IGNITE-10884: Fixed failure when performing non-MVCC SQL from transactions. This closes #5808.
---
.../internal/processors/cache/mvcc/MvccUtils.java | 4 +-
.../cache/mvcc/MvccUnsupportedTxModesTest.java | 17 +-
.../processors/query/h2/IgniteH2Indexing.java | 6 +-
.../cache/mvcc/CacheMvccSqlTxModesTest.java | 213 +++++++++++++++++++++
.../testsuites/IgniteCacheMvccSqlTestSuite.java | 3 +-
5 files changed, 234 insertions(+), 9 deletions(-)
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 0ceed09..c6848d3 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 class MvccUtils {
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 class MvccUtils {
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 dc1f2cb..e1b3e41 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 @@ public class MvccUnsupportedTxModesTest extends GridCommonAbstractTest {
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 @@ public class MvccUnsupportedTxModesTest extends GridCommonAbstractTest {
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 53530a3..4c26e35 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.mvcc.MvccUtils.txStart
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 @@ public class IgniteH2Indexing implements GridQueryIndexing {
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 0000000..05f30b6
--- /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 bdc7664..0418914 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.CacheMvccSqlConfiguratio
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 @@ import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
CacheMvccSizeTest.class,
CacheMvccSqlUpdateCountersTest.class,
CacheMvccSqlLockTimeoutTest.class,
-
+ CacheMvccSqlTxModesTest.class,
GridIndexRebuildWithMvccEnabledSelfTest.class,
CacheMvccTxNodeMappingTest.class,