http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java index 9510e63..143bd42 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java @@ -37,8 +37,9 @@ import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.binary.BinaryWriterExImpl; import org.apache.ignite.internal.binary.GridBinaryMarshaller; import org.apache.ignite.internal.processors.authentication.AuthorizationContext; -import org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx; +import org.apache.ignite.internal.processors.cache.mvcc.MvccUtils; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; +import org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx; import org.apache.ignite.internal.processors.odbc.ClientListenerProtocolVersion; import org.apache.ignite.internal.processors.odbc.ClientListenerRequest; import org.apache.ignite.internal.processors.odbc.ClientListenerRequestHandler; @@ -148,10 +149,8 @@ public class OdbcRequestHandler implements ClientListenerRequestHandler { log = ctx.log(getClass()); - if (ctx.grid().configuration().isMvccEnabled()) - worker = new OdbcRequestHandlerWorker(ctx.igniteInstanceName(), log, this, ctx); - else - worker = null; + // TODO IGNITE-9484 Do not create worker if there is a possibility to unbind TX from threads. + worker = new OdbcRequestHandlerWorker(ctx.igniteInstanceName(), log, this, ctx); } /** {@inheritDoc} */ @@ -162,7 +161,7 @@ public class OdbcRequestHandler implements ClientListenerRequestHandler { OdbcRequest req = (OdbcRequest)req0; - if (worker == null) + if (!MvccUtils.mvccEnabled(ctx)) return doHandle(req); else { GridFutureAdapter<ClientListenerResponse> fut = worker.process(req);
http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractFeatureTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractFeatureTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractFeatureTest.java index a667297..fe450d1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractFeatureTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractFeatureTest.java @@ -87,7 +87,7 @@ public abstract class CacheMvccAbstractFeatureTest extends CacheMvccAbstractTest @Override protected void beforeTest() throws Exception { CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<>(CACHE_NAME); - ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT); ccfg.setIndexedTypes(Integer.class, Person.class); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractTest.java index c5137f6..a4962d1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccAbstractTest.java @@ -71,7 +71,6 @@ import org.apache.ignite.internal.util.lang.GridInClosure3; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.X; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiPredicate; import org.apache.ignite.lang.IgniteBiTuple; @@ -89,7 +88,7 @@ import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; import org.jetbrains.annotations.Nullable; -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.cache.CacheMode.REPLICATED; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; @@ -162,10 +161,8 @@ public abstract class CacheMvccAbstractTest extends GridCommonAbstractTest { @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - cfg.setMvccEnabled(true); - if (disableScheduledVacuum) - cfg.setMvccVacuumTimeInterval(Integer.MAX_VALUE); + cfg.setMvccVacuumFrequency(Integer.MAX_VALUE); ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); @@ -1438,7 +1435,7 @@ public abstract class CacheMvccAbstractTest extends GridCommonAbstractTest { CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); ccfg.setCacheMode(cacheMode); - ccfg.setAtomicityMode(TRANSACTIONAL); + ccfg.setAtomicityMode(TRANSACTIONAL_SNAPSHOT); ccfg.setWriteSynchronizationMode(syncMode); ccfg.setAffinity(new RendezvousAffinityFunction(false, parts)); @@ -1464,7 +1461,7 @@ public abstract class CacheMvccAbstractTest extends GridCommonAbstractTest { for (Ignite node : G.allGrids()) { final MvccProcessorImpl crd = mvccProcessor(node); - if (crd == null) + if (!crd.mvccEnabled()) continue; crd.stopVacuumWorkers(); // to prevent new futures creation. @@ -1576,9 +1573,11 @@ public abstract class CacheMvccAbstractTest extends GridCommonAbstractTest { if (!node.configuration().isClientMode()) { MvccProcessorImpl crd = mvccProcessor(node); - if (crd == null) + if (!crd.mvccEnabled() || GridTestUtils.getFieldValue(crd, "vacuumWorkers") == null) continue; + assert GridTestUtils.getFieldValue(crd, "txLog") != null; + Throwable vacuumError = crd.vacuumError(); assertNull(X.getFullStackTrace(vacuumError), vacuumError); @@ -1604,12 +1603,6 @@ public abstract class CacheMvccAbstractTest extends GridCommonAbstractTest { assertNotNull(crd); - if (crd instanceof NoOpMvccProcessor) { - assertFalse(MvccUtils.mvccEnabled(ctx)); - - return null; - } - return (MvccProcessorImpl)crd; } http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccClusterRestartTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccClusterRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccClusterRestartTest.java index 76a8604..5cabffc 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccClusterRestartTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccClusterRestartTest.java @@ -33,7 +33,7 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.apache.ignite.transactions.Transaction; -import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; @@ -51,8 +51,6 @@ public class CacheMvccClusterRestartTest extends GridCommonAbstractTest { cfg.setConsistentId(gridName); - cfg.setMvccEnabled(true); - ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); DataStorageConfiguration storageCfg = new DataStorageConfiguration(); @@ -170,7 +168,7 @@ public class CacheMvccClusterRestartTest extends GridCommonAbstractTest { CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); ccfg.setWriteSynchronizationMode(FULL_SYNC); - ccfg.setAtomicityMode(TRANSACTIONAL); + ccfg.setAtomicityMode(TRANSACTIONAL_SNAPSHOT); ccfg.setBackups(2); return ccfg; http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java index b0a2ec8..a10c6c7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java @@ -18,30 +18,40 @@ package org.apache.ignite.internal.processors.cache.mvcc; import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import javax.cache.CacheException; import javax.cache.configuration.Factory; +import javax.cache.configuration.FactoryBuilder; import javax.cache.expiry.CreatedExpiryPolicy; import javax.cache.expiry.Duration; import javax.cache.expiry.ExpiryPolicy; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheInterceptorAdapter; +import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.store.CacheStore; +import org.apache.ignite.cache.store.CacheStoreReadFromBackupTest; import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.configvariations.ConfigVariations; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT; /** * */ +@SuppressWarnings("unchecked") public class CacheMvccConfigurationValidationTest extends GridCommonAbstractTest { /** */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -50,8 +60,6 @@ public class CacheMvccConfigurationValidationTest extends GridCommonAbstractTest @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); - cfg.setMvccEnabled(true); - ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); return cfg; @@ -74,7 +82,7 @@ public class CacheMvccConfigurationValidationTest extends GridCommonAbstractTest GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { - node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL)); + node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); return null; } @@ -89,7 +97,7 @@ public class CacheMvccConfigurationValidationTest extends GridCommonAbstractTest public void testMvccModeMismatchForGroup2() throws Exception { final Ignite node = startGrid(0); - node.createCache(new CacheConfiguration("cache1").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL)); + node.createCache(new CacheConfiguration("cache1").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { @@ -99,7 +107,232 @@ public class CacheMvccConfigurationValidationTest extends GridCommonAbstractTest } }, CacheException.class, null); - node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL)); + node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + } + + /** + * @throws Exception If failed. + */ + public void testMvccLocalCacheDisabled() throws Exception { + final Ignite node1 = startGrid(1); + final Ignite node2 = startGrid(2); + + IgniteCache cache1 = node1.createCache(new CacheConfiguration("cache1") + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + cache1.put(1,1); + cache1.put(2,2); + cache1.put(2,2); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + node1.createCache(new CacheConfiguration("cache2").setCacheMode(CacheMode.LOCAL) + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + return null; + } + }, CacheException.class, null); + + IgniteCache cache3 = node2.createCache(new CacheConfiguration("cache3") + .setAtomicityMode(TRANSACTIONAL)); + + cache3.put(1, 1); + cache3.put(2, 2); + cache3.put(3, 3); + } + + /** + * @throws Exception If failed. + */ + public void testMvccExpiredPolicyCacheDisabled() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-8640"); + + final Ignite node1 = startGrid(1); + final Ignite node2 = startGrid(2); + + IgniteCache cache1 = node1.createCache(new CacheConfiguration("cache1") + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + cache1.put(1,1); + cache1.put(2,2); + cache1.put(2,2); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + node1.createCache(new CacheConfiguration("cache2") + .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 1))) + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + return null; + } + }, CacheException.class, null); + + IgniteCache cache3 = node2.createCache(new CacheConfiguration("cache3") + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + cache3.put(1, 1); + cache3.put(2, 2); + cache3.put(3, 3); + } + + /** + * @throws Exception If failed. + */ + public void testMvccThirdPartyStoreCacheDisabled() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-8640"); + + final Ignite node1 = startGrid(1); + final Ignite node2 = startGrid(2); + + IgniteCache cache1 = node1.createCache(new CacheConfiguration("cache1") + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + cache1.put(1,1); + cache1.put(2,2); + cache1.put(2,2); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + node1.createCache(new CacheConfiguration("cache2") + .setCacheStoreFactory(FactoryBuilder.factoryOf(CacheStoreReadFromBackupTest.TestStore.class)) + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + return null; + } + }, CacheException.class, null); + + IgniteCache cache3 = node2.createCache(new CacheConfiguration("cache3") + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + cache3.put(1, 1); + cache3.put(2, 2); + cache3.put(3, 3); + } + + /** + * @throws Exception If failed. + */ + public void testMvccInterceptorCacheDisabled() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-8640"); + + final Ignite node1 = startGrid(1); + final Ignite node2 = startGrid(2); + + IgniteCache cache1 = node1.createCache(new CacheConfiguration("cache1") + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + cache1.put(1,1); + cache1.put(2,2); + cache1.put(2,2); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + node1.createCache(new CacheConfiguration("cache2") + .setInterceptor(new ConfigVariations.NoopInterceptor()) + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + return null; + } + }, CacheException.class, null); + + IgniteCache cache3 = node2.createCache(new CacheConfiguration("cache3") + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); + + cache3.put(1, 1); + cache3.put(2, 2); + cache3.put(3, 3); + } + + /** + * @throws Exception If failed. + */ + public void testNodeRestartWithCacheModeChangedTxToMvcc() throws Exception { + cleanPersistenceDir(); + + //Enable persistence. + DataStorageConfiguration storageCfg = new DataStorageConfiguration(); + DataRegionConfiguration regionCfg = new DataRegionConfiguration(); + regionCfg.setPersistenceEnabled(true); + storageCfg.setDefaultDataRegionConfiguration(regionCfg); + IgniteConfiguration cfg = getConfiguration("testGrid"); + cfg.setDataStorageConfiguration(storageCfg); + cfg.setConsistentId(cfg.getIgniteInstanceName()); + + Ignite node = startGrid(cfg); + + node.cluster().active(true); + + CacheConfiguration ccfg1 = new CacheConfiguration("test1").setAtomicityMode(TRANSACTIONAL); + + IgniteCache cache = node.createCache(ccfg1); + + cache.put(1, 1); + cache.put(1, 2); + cache.put(2, 2); + + stopGrid(cfg.getIgniteInstanceName()); + + CacheConfiguration ccfg2 = new CacheConfiguration().setName(ccfg1.getName()) + .setAtomicityMode(TRANSACTIONAL_SNAPSHOT); + + IgniteConfiguration cfg2 = getConfiguration("testGrid") + .setConsistentId(cfg.getIgniteInstanceName()) + .setCacheConfiguration(ccfg2) + .setDataStorageConfiguration(storageCfg); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + startGrid(cfg2); + + return null; + } + }, IgniteCheckedException.class, "Failed to start processor"); + } + + /** + * @throws Exception If failed. + */ + public void testNodeRestartWithCacheModeChangedMvccToTx() throws Exception { + cleanPersistenceDir(); + + //Enable persistence. + DataStorageConfiguration storageCfg = new DataStorageConfiguration(); + DataRegionConfiguration regionCfg = new DataRegionConfiguration(); + regionCfg.setPersistenceEnabled(true); + storageCfg.setDefaultDataRegionConfiguration(regionCfg); + IgniteConfiguration cfg = getConfiguration("testGrid"); + cfg.setDataStorageConfiguration(storageCfg); + cfg.setConsistentId(cfg.getIgniteInstanceName()); + + Ignite node = startGrid(cfg); + + node.cluster().active(true); + + CacheConfiguration ccfg1 = new CacheConfiguration("test1").setAtomicityMode(TRANSACTIONAL_SNAPSHOT); + + IgniteCache cache = node.createCache(ccfg1); + + cache.put(1, 1); + cache.put(1, 2); + cache.put(2, 2); + + stopGrid(cfg.getIgniteInstanceName()); + + CacheConfiguration ccfg2 = new CacheConfiguration().setName(ccfg1.getName()) + .setAtomicityMode(TRANSACTIONAL); + + IgniteConfiguration cfg2 = getConfiguration("testGrid") + .setConsistentId(cfg.getIgniteInstanceName()) + .setCacheConfiguration(ccfg2) + .setDataStorageConfiguration(storageCfg); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + startGrid(cfg2); + + return null; + } + }, IgniteCheckedException.class, "Failed to start processor"); } /** @@ -141,7 +374,7 @@ public class CacheMvccConfigurationValidationTest extends GridCommonAbstractTest try (final Ignite node = startGrid(0)) { final CacheConfiguration cfg = new TestConfiguration("cache"); - cfg.setAtomicityMode(TRANSACTIONAL); + cfg.setAtomicityMode(TRANSACTIONAL_SNAPSHOT); U.invoke(TestConfiguration.class, cfg, setterName, obj); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java index dc2de9a..5aedf17 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java @@ -34,7 +34,7 @@ import org.apache.ignite.lang.IgniteBiPredicate; import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.testframework.GridTestUtils; -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; /** @@ -158,7 +158,7 @@ public class CacheMvccOperationChecksTest extends CacheMvccAbstractTest { final CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>("cache"); cfg.setCacheMode(cacheMode()); - cfg.setAtomicityMode(TRANSACTIONAL); + cfg.setAtomicityMode(TRANSACTIONAL_SNAPSHOT); try (IgniteCache<Integer, String> cache = node.createCache(cfg)) { GridTestUtils.assertThrows(log, new Callable<Void>() { http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorLazyStartTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorLazyStartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorLazyStartTest.java new file mode 100644 index 0000000..064e7bb --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorLazyStartTest.java @@ -0,0 +1,175 @@ +/* + * 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 org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; + +/** + * Tests for a lazy MVCC processor start. + */ +@SuppressWarnings("unchecked") +public class CacheMvccProcessorLazyStartTest extends CacheMvccAbstractTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return CacheMode.PARTITIONED; + } + + /** + * @throws Exception If failed. + */ + public void testPreconfiguredCacheMvccNotStarted() throws Exception { + CacheConfiguration ccfg = cacheConfiguration(CacheMode.PARTITIONED, CacheWriteSynchronizationMode.FULL_SYNC, 0, 1); + ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); + + IgniteConfiguration cfg = getConfiguration(); + cfg.setCacheConfiguration(ccfg); + IgniteConfiguration cfg2 = getConfiguration("node2"); + + IgniteEx node1 = startGrid(cfg); + IgniteEx node2 = startGrid(cfg2); + + IgniteCache cache = node1.cache(ccfg.getName()); + + cache.put(1, 1); + cache.put(1, 2); + + assertFalse(mvccEnabled(node1)); + assertFalse(mvccEnabled(node2)); + } + + /** + * @throws Exception If failed. + */ + public void testPreconfiguredCacheMvccStarted() throws Exception { + CacheConfiguration ccfg = cacheConfiguration(CacheMode.PARTITIONED, CacheWriteSynchronizationMode.FULL_SYNC, 0, 1); + + IgniteConfiguration cfg1 = getConfiguration(); + cfg1.setCacheConfiguration(ccfg); + IgniteConfiguration cfg2 = getConfiguration("node2"); + + IgniteEx node1 = startGrid(cfg1); + IgniteEx node2 = startGrid(cfg2); + + IgniteCache cache = node1.cache(ccfg.getName()); + + cache.put(1, 1); + cache.put(1, 2); + + assertTrue(mvccEnabled(node1)); + assertTrue(mvccEnabled(node2)); + } + + /** + * @throws Exception If failed. + */ + public void testMvccRestartedWithDynamicCache() throws Exception { + persistence = true; + + IgniteEx node1 = startGrid(1); + IgniteEx node2 = startGrid(2); + + assertFalse(mvccEnabled(node1)); + assertFalse(mvccEnabled(node2)); + + node1.cluster().active(true); + + assertFalse(mvccEnabled(node1)); + assertFalse(mvccEnabled(node2)); + + CacheConfiguration ccfg = cacheConfiguration(CacheMode.PARTITIONED, CacheWriteSynchronizationMode.FULL_SYNC, 0, 1); + + IgniteCache cache = node1.createCache(ccfg); + + cache.put(1, 1); + cache.put(1, 2); + + assertTrue(mvccEnabled(node1)); + assertTrue(mvccEnabled(node2)); + + stopGrid(1); + stopGrid(2); + + node1 = startGrid(1); + node2 = startGrid(2); + + node1.cluster().active(true); + + assertTrue(mvccEnabled(node1)); + assertTrue(mvccEnabled(node2)); + + cache = node1.cache(ccfg.getName()); + + cache.put(1, 1); + cache.put(1, 2); + + assertTrue(mvccEnabled(node1)); + assertTrue(mvccEnabled(node2)); + } + + /** + * @throws Exception If failed. + */ + public void testMvccStartedWithDynamicCache() throws Exception { + IgniteEx node1 = startGrid(1); + IgniteEx node2 = startGrid(2); + + assertFalse(mvccEnabled(node1)); + assertFalse(mvccEnabled(node2)); + + CacheConfiguration ccfg = cacheConfiguration(CacheMode.PARTITIONED, CacheWriteSynchronizationMode.FULL_SYNC, 0, 1); + + IgniteCache cache = node1.createCache(ccfg); + + cache.put(1, 1); + cache.put(1, 2); + + assertTrue(mvccEnabled(node1)); + assertTrue(mvccEnabled(node2)); + + stopGrid(1); + stopGrid(2); + + node1 = startGrid(1); + node2 = startGrid(2); + + // Should not be started because we do not have persistence enabled + assertFalse(mvccEnabled(node1)); + assertFalse(mvccEnabled(node2)); + + cache = node1.createCache(ccfg); + + cache.put(1, 1); + cache.put(1, 2); + + assertTrue(mvccEnabled(node1)); + assertTrue(mvccEnabled(node2)); + } + + /** + * @param node Node. + * @return {@code True} if {@link MvccProcessor} is started. + */ + private boolean mvccEnabled(IgniteEx node) { + return node.context().coordinators().mvccEnabled(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java index 503460a..dc902fc 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java @@ -17,7 +17,9 @@ package org.apache.ignite.internal.processors.cache.mvcc; +import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.mvcc.txlog.TxState; @@ -58,6 +60,8 @@ public class CacheMvccProcessorTest extends CacheMvccAbstractTest { grid.cluster().active(true); + grid.createCache(new CacheConfiguration<>("test").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT)); + MvccProcessorImpl mvccProcessor = mvccProcessor(grid); assertEquals(TxState.NA, mvccProcessor.state(new MvccVersionImpl(1, 1, MvccUtils.MVCC_OP_COUNTER_NA))); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccVacuumTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccVacuumTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccVacuumTest.java index cba6d99..8c96b2e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccVacuumTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccVacuumTest.java @@ -19,9 +19,10 @@ package org.apache.ignite.internal.processors.cache.mvcc; import java.util.List; import org.apache.ignite.Ignite; +import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.util.worker.GridWorker; import org.apache.ignite.testframework.GridTestUtils; @@ -43,6 +44,15 @@ public class CacheMvccVacuumTest extends CacheMvccAbstractTest { Ignite node0 = startGrid(0); Ignite node1 = startGrid(1); + node1.createCache(new CacheConfiguration<>("test1") + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)); + + ensureNoVacuum(node0); + ensureNoVacuum(node1); + + node1.createCache(new CacheConfiguration<>("test2") + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT)); + ensureVacuum(node0); ensureVacuum(node1); @@ -71,6 +81,12 @@ public class CacheMvccVacuumTest extends CacheMvccAbstractTest { node1.cluster().active(true); + ensureNoVacuum(node0); + ensureNoVacuum(node1); + + node1.createCache(new CacheConfiguration<>("test2") + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT)); + ensureVacuum(node0); ensureVacuum(node1); @@ -93,13 +109,24 @@ public class CacheMvccVacuumTest extends CacheMvccAbstractTest { ensureNoVacuum(node0); ensureNoVacuum(node1); + + node0 = startGrid(0); + node1 = startGrid(1); + + ensureNoVacuum(node0); + ensureNoVacuum(node1); + + node1.cluster().active(true); + + ensureVacuum(node0); + ensureVacuum(node1); } /** * @throws Exception If failed. */ public void testVacuumNotStartedWithoutMvcc() throws Exception { - IgniteConfiguration cfg = getConfiguration("grid1").setMvccEnabled(false); + IgniteConfiguration cfg = getConfiguration("grid1"); Ignite node = startGrid(cfg); @@ -112,7 +139,7 @@ public class CacheMvccVacuumTest extends CacheMvccAbstractTest { public void testVacuumNotStartedWithoutMvccPersistence() throws Exception { persistence = true; - IgniteConfiguration cfg = getConfiguration("grid1").setMvccEnabled(false); + IgniteConfiguration cfg = getConfiguration("grid1"); Ignite node = startGrid(cfg); @@ -152,7 +179,6 @@ public class CacheMvccVacuumTest extends CacheMvccAbstractTest { private void ensureNoVacuum(Ignite node) { MvccProcessorImpl crd = mvccProcessor(node); - if (crd != null) - assertNull(GridTestUtils.<List<GridWorker>>getFieldValue(crd, "vacuumWorkers")); + assertNull(GridTestUtils.<List<GridWorker>>getFieldValue(crd, "vacuumWorkers")); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java index ccf1502..fac021e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java @@ -75,7 +75,7 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest { Collection<DataRegion> allMemPlcs = ignite.context().cache().context().database().dataRegions(); - assertEquals(2, allMemPlcs.size()); + assertEquals(3, allMemPlcs.size()); verifyDefaultAndSystemMemoryPolicies(allMemPlcs); } @@ -91,7 +91,7 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest { Collection<DataRegion> allMemPlcs = ignite.context().cache().context().database().dataRegions(); - assertEquals(3, allMemPlcs.size()); + assertEquals(4, allMemPlcs.size()); verifyDefaultAndSystemMemoryPolicies(allMemPlcs); @@ -112,7 +112,7 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest { Collection<DataRegion> allMemPlcs = dbMgr.dataRegions(); - assertEquals(2, allMemPlcs.size()); + assertEquals(3, allMemPlcs.size()); verifyDefaultAndSystemMemoryPolicies(allMemPlcs); @@ -136,7 +136,7 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest { Collection<DataRegion> allMemPlcs = dbMgr.dataRegions(); - assertEquals(3, allMemPlcs.size()); + assertEquals(4, allMemPlcs.size()); verifyDefaultAndSystemMemoryPolicies(allMemPlcs); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorMvccSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorMvccSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorMvccSelfTest.java index eaea6da..d7948bd 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorMvccSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorMvccSelfTest.java @@ -17,10 +17,11 @@ package org.apache.ignite.internal.processors.datastreamer; +import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; -import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT; /** * Check DataStreamer with Mvcc enabled. @@ -33,14 +34,17 @@ public class DataStreamProcessorMvccSelfTest extends DataStreamProcessorSelfTest CacheConfiguration[] cacheConfigurations = igniteConfiguration.getCacheConfiguration(); assert cacheConfigurations == null || cacheConfigurations.length == 0 - || (cacheConfigurations.length == 1 && cacheConfigurations[0].getAtomicityMode() == TRANSACTIONAL); - - igniteConfiguration.setMvccEnabled(true); + || (cacheConfigurations.length == 1 && cacheConfigurations[0].getAtomicityMode() == TRANSACTIONAL_SNAPSHOT); return igniteConfiguration; } /** {@inheritDoc} */ + @Override protected CacheAtomicityMode getCacheAtomicityMode() { + return TRANSACTIONAL_SNAPSHOT; + } + + /** {@inheritDoc} */ @Override public void testPartitioned() throws Exception { // test uses batchedSorted StreamReceiver which depends on Cache.putAll, Cache.removeAll fail("https://issues.apache.org/jira/browse/IGNITE-9451"); @@ -70,4 +74,9 @@ public class DataStreamProcessorMvccSelfTest extends DataStreamProcessorSelfTest super.testUpdateStore(); } + + /** {@inheritDoc} */ + @Override public void testLocal() throws Exception { + // Do not check local caches with MVCC enabled. + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java index 7075973..536d73e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java @@ -34,6 +34,7 @@ import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteDataStreamer; import org.apache.ignite.IgniteException; +import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.cache.affinity.Affinity; @@ -67,6 +68,7 @@ import org.jetbrains.annotations.Nullable; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT; import static org.apache.ignite.cache.CacheMode.LOCAL; import static org.apache.ignite.cache.CacheMode.PARTITIONED; import static org.apache.ignite.cache.CacheMode.REPLICATED; @@ -122,7 +124,7 @@ public class DataStreamProcessorSelfTest extends GridCommonAbstractTest { CacheConfiguration cc = defaultCacheConfiguration(); cc.setCacheMode(mode); - cc.setAtomicityMode(TRANSACTIONAL); + cc.setAtomicityMode(getCacheAtomicityMode()); if (nearEnabled) { NearCacheConfiguration nearCfg = new NearCacheConfiguration(); @@ -150,6 +152,13 @@ public class DataStreamProcessorSelfTest extends GridCommonAbstractTest { } /** + * @return Default cache atomicity mode. + */ + protected CacheAtomicityMode getCacheAtomicityMode() { + return TRANSACTIONAL; + } + + /** * @return {@code True} if custom stream receiver should use keepBinary flag. */ protected boolean customKeepBinary() { @@ -730,7 +739,8 @@ public class DataStreamProcessorSelfTest extends GridCommonAbstractTest { * @throws Exception If failed. */ public void testFlush() throws Exception { - mode = LOCAL; + // Local caches are not allowed with MVCC enabled. + mode = getCacheAtomicityMode() != TRANSACTIONAL_SNAPSHOT ? LOCAL : PARTITIONED; useCache = true; @@ -782,7 +792,8 @@ public class DataStreamProcessorSelfTest extends GridCommonAbstractTest { * @throws Exception If failed. */ public void testTryFlush() throws Exception { - mode = LOCAL; + // Local caches are not allowed with MVCC enabled. + mode = getCacheAtomicityMode() != TRANSACTIONAL_SNAPSHOT ? LOCAL : PARTITIONED; useCache = true; @@ -817,7 +828,8 @@ public class DataStreamProcessorSelfTest extends GridCommonAbstractTest { * @throws Exception If failed. */ public void testFlushTimeout() throws Exception { - mode = LOCAL; + // Local caches are not allowed with MVCC enabled. + mode = getCacheAtomicityMode() != TRANSACTIONAL_SNAPSHOT ? LOCAL : PARTITIONED; useCache = true; http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java index 8e7e554..ca22b56 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java @@ -92,7 +92,7 @@ public class ConfigVariations { @SuppressWarnings("unchecked") private static final ConfigParameter<CacheConfiguration>[][] BASIC_CACHE_SET = new ConfigParameter[][] { Parameters.objectParameters("setCacheMode", CacheMode.REPLICATED, CacheMode.PARTITIONED), - Parameters.enumParameters("setAtomicityMode", CacheAtomicityMode.class), + Parameters.objectParameters("setAtomicityMode", CacheAtomicityMode.ATOMIC, CacheAtomicityMode.TRANSACTIONAL), // Set default parameters. Parameters.objectParameters("setLoadPreviousValue", true), asArray(SIMPLE_CACHE_STORE_PARAM), http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite.java index f87b14d..8585ebe 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite.java @@ -24,6 +24,7 @@ import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccIteratorWithCon import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccLocalEntriesWithConcurrentTransactionTest; import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccOperationChecksTest; import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccPartitionedCoordinatorFailoverTest; +import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccProcessorLazyStartTest; import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccProcessorTest; import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccReplicatedCoordinatorFailoverTest; import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccScanQueryWithConcurrentTransactionTest; @@ -61,6 +62,7 @@ public class IgniteCacheMvccTestSuite extends TestSuite { suite.addTestSuite(CacheMvccClusterRestartTest.class); suite.addTestSuite(CacheMvccPartitionedCoordinatorFailoverTest.class); suite.addTestSuite(CacheMvccReplicatedCoordinatorFailoverTest.class); + suite.addTestSuite(CacheMvccProcessorLazyStartTest.class); return suite; } http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java ---------------------------------------------------------------------- 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 a795552..79c431f 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 @@ -128,6 +128,7 @@ import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQuerySplitter; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlTable; import org.apache.ignite.internal.processors.query.h2.sys.SqlSystemTableEngine; +import org.apache.ignite.internal.processors.query.h2.sys.view.SqlSystemView; import org.apache.ignite.internal.processors.query.h2.sys.view.SqlSystemViewBaselineNodes; import org.apache.ignite.internal.processors.query.h2.sys.view.SqlSystemViewNodeAttributes; import org.apache.ignite.internal.processors.query.h2.sys.view.SqlSystemViewNodeMetrics; @@ -136,7 +137,6 @@ import org.apache.ignite.internal.processors.query.h2.twostep.GridMapQueryExecut import org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor; import org.apache.ignite.internal.processors.query.h2.twostep.MapQueryLazyWorker; import org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2QueryRequest; -import org.apache.ignite.internal.processors.query.h2.sys.view.SqlSystemView; import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitor; import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure; import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorImpl; @@ -209,7 +209,8 @@ import static org.apache.ignite.internal.processors.cache.query.GridCacheQueryTy import static org.apache.ignite.internal.processors.query.QueryUtils.KEY_FIELD_NAME; import static org.apache.ignite.internal.processors.query.QueryUtils.VAL_FIELD_NAME; import static org.apache.ignite.internal.processors.query.QueryUtils.VER_FIELD_NAME; -import static org.apache.ignite.internal.processors.query.h2.PreparedStatementEx.INVOLVED_CACHES; +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.DistributedJoinMode.OFF; import static org.apache.ignite.internal.processors.query.h2.opt.DistributedJoinMode.distributedJoinMode; import static org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryType.LOCAL; @@ -1073,7 +1074,9 @@ public class IgniteH2Indexing implements GridQueryIndexing { boolean startTx, int timeout, final GridQueryCancel cancel, MvccQueryTracker mvccTracker) throws IgniteCheckedException { - GridNearTxLocal tx = null; boolean mvccEnabled = mvccEnabled(kernalContext()); + GridNearTxLocal tx = null; + + boolean mvccEnabled = mvccEnabled(kernalContext()); assert mvccEnabled || mvccTracker == null; @@ -1649,53 +1652,90 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @return MVCC query tracker or {@code null} if MVCC is disabled for involved caches. */ private MvccQueryTracker mvccTracker(PreparedStatement stmt, boolean startTx) throws IgniteCheckedException { - List<GridCacheContext> caches; + boolean mvccEnabled; + + GridCacheContext mvccCacheCtx = null; + try { if (stmt.isWrapperFor(PreparedStatementEx.class)) { PreparedStatementEx stmtEx = stmt.unwrap(PreparedStatementEx.class); - caches = stmtEx.meta(INVOLVED_CACHES); + Boolean mvccState = stmtEx.meta(MVCC_STATE); + + mvccEnabled = mvccState != null ? mvccState : checkMvcc(stmt); + + if (mvccEnabled) { + Integer cacheId = stmtEx.meta(MVCC_CACHE_ID); + + assert cacheId != null; + + mvccCacheCtx = ctx.cache().context().cacheContext(cacheId); - if (caches == null) - stmtEx.putMeta(INVOLVED_CACHES, caches = parseInvolvedCaches(stmt)); + assert mvccCacheCtx != null; + } } else - caches = parseInvolvedCaches(stmt); - } catch (SQLException e) { + mvccEnabled = checkMvcc(stmt); + } + catch (SQLException e) { throw new IgniteSQLException(e); } - GridCacheContext firstCctx = null; - boolean mvccEnabled = false; + assert !mvccEnabled || mvccCacheCtx != null; - for (GridCacheContext cctx : caches) { - if (firstCctx == null) { - firstCctx = cctx; - mvccEnabled = firstCctx.mvccEnabled(); - } - else if (mvccEnabled != cctx.mvccEnabled()) - throw new IllegalStateException("Using caches with different mvcc settings in same query is forbidden."); - } - - return mvccEnabled ? MvccUtils.mvccTracker(firstCctx, startTx) : null; + return mvccEnabled ? MvccUtils.mvccTracker(mvccCacheCtx, startTx) : null; } - /** */ - private static List<GridCacheContext> parseInvolvedCaches(PreparedStatement stmt) { + /** + * Checks if statement uses MVCC caches. If it does, additional metadata is added to statement. + * + * @param stmt Statement to check. + * @return {@code True} if there MVCC cache involved in statement. + * @throws SQLException If parser failed. + */ + private static Boolean checkMvcc(PreparedStatement stmt) throws SQLException { GridSqlQueryParser parser = new GridSqlQueryParser(false); parser.parse(GridSqlQueryParser.prepared(stmt)); - List<GridCacheContext> involvedCaches = new ArrayList<>(); + Boolean mvccEnabled = null; + Integer mvccCacheId = null; + GridCacheContext ctx0 = null; for (Object o : parser.objectsMap().values()) { if (o instanceof GridSqlAlias) o = GridSqlAlias.unwrap((GridSqlAst) o); - if (o instanceof GridSqlTable && ((GridSqlTable) o).dataTable() != null) - involvedCaches.add(((GridSqlTable) o).dataTable().cache()); + if (o instanceof GridSqlTable && ((GridSqlTable) o).dataTable() != null) { + GridCacheContext cctx = ((GridSqlTable) o).dataTable().cache(); + + if (mvccEnabled == null) { + mvccEnabled = cctx.mvccEnabled(); + mvccCacheId = cctx.cacheId(); + ctx0 = cctx; + } + else if (mvccEnabled != cctx.mvccEnabled()) + MvccUtils.throwAtomicityModesMismatchException(ctx0, cctx); + } } - return involvedCaches; + if (mvccEnabled == null) + return false; + + // Remember mvccEnabled flag to avoid further additional parsing if statement obtained from the statement cache. + if (stmt.isWrapperFor(PreparedStatementEx.class)) { + PreparedStatementEx stmtEx = stmt.unwrap(PreparedStatementEx.class); + + if (mvccEnabled) { + assert mvccCacheId != null; + + stmtEx.putMeta(MVCC_CACHE_ID, mvccCacheId); + stmtEx.putMeta(MVCC_STATE, Boolean.TRUE); + } + else + stmtEx.putMeta(MVCC_STATE, Boolean.FALSE); + } + + return mvccEnabled; } /** @@ -2596,6 +2636,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { GridCacheSharedContext sharedCtx = ctx.cache().context(); int expectedParallelism = 0; + GridCacheContext cctx0 = null; boolean mvccEnabled = false; @@ -2606,11 +2647,12 @@ public class IgniteH2Indexing implements GridQueryIndexing { assert cctx != null; - if (i == 0) + if (i == 0) { mvccEnabled = cctx.mvccEnabled(); + cctx0 = cctx; + } else if (cctx.mvccEnabled() != mvccEnabled) - throw new IllegalStateException("Using caches with different mvcc settings in same query is " + - "forbidden."); + MvccUtils.throwAtomicityModesMismatchException(cctx0, cctx); if (!cctx.isPartitioned()) continue; http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/PreparedStatementEx.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/PreparedStatementEx.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/PreparedStatementEx.java index d254971..50dd892 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/PreparedStatementEx.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/PreparedStatementEx.java @@ -28,8 +28,11 @@ public interface PreparedStatementEx extends PreparedStatement { /** */ static final AtomicInteger metaIdGenerator = new AtomicInteger(); - /** */ - static final int INVOLVED_CACHES = metaIdGenerator.getAndIncrement(); + /** Flag if at least one MVCC cache is used in this statement. */ + static final int MVCC_STATE = metaIdGenerator.getAndIncrement(); + + /** First mvcc cache id of the involved caches. */ + static final int MVCC_CACHE_ID = metaIdGenerator.getAndIncrement(); /** * @param id Metadata key. http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java index 6c103f3..5e44f27 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlanBuilder.java @@ -30,6 +30,7 @@ import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.binary.BinaryObjectBuilder; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.mvcc.MvccUtils; import org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; import org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx; @@ -126,7 +127,7 @@ public final class UpdatePlanBuilder { if (cctx == null) mvccEnabled = (cctx = (((GridSqlTable)o).dataTable()).cache()).mvccEnabled(); else if (((GridSqlTable)o).dataTable().cache().mvccEnabled() != mvccEnabled) - throw new IllegalStateException("Using caches with different mvcc settings in same query is forbidden."); + MvccUtils.throwAtomicityModesMismatchException(cctx, ((GridSqlTable)o).dataTable().cache()); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java index 599d792..18c068a 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java @@ -1492,6 +1492,8 @@ public class GridSqlQueryParser { atomicityMode = CacheAtomicityMode.TRANSACTIONAL; else if (CacheAtomicityMode.ATOMIC.name().equalsIgnoreCase(val)) atomicityMode = CacheAtomicityMode.ATOMIC; + else if (CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT.name().equalsIgnoreCase(val)) + atomicityMode = CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT; else throw new IgniteSQLException("Invalid value of \"" + PARAM_ATOMICITY + "\" parameter " + "(should be either TRANSACTIONAL or ATOMIC): " + val, IgniteQueryErrorCode.PARSING); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsCommandsWithMvccEnabledSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsCommandsWithMvccEnabledSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsCommandsWithMvccEnabledSelfTest.java index 55dd59a..8c6f407 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsCommandsWithMvccEnabledSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsCommandsWithMvccEnabledSelfTest.java @@ -52,10 +52,10 @@ public class SqlTransactionsCommandsWithMvccEnabledSelfTest extends AbstractSche @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); - startGrid(commonConfiguration(0).setMvccEnabled(true)); + startGrid(commonConfiguration(0)); super.execute(node(), "CREATE TABLE INTS(k int primary key, v int) WITH \"wrap_value=false,cache_name=ints," + - "atomicity=transactional\""); + "atomicity=transactional_snapshot\""); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsSelfTest.java index 7081e34..d93bdab 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SqlTransactionsSelfTest.java @@ -35,7 +35,6 @@ import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; -import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.X; @@ -53,10 +52,10 @@ public class SqlTransactionsSelfTest extends AbstractSchemaSelfTest { @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); - startGrid(commonConfiguration(0).setMvccEnabled(true)); + startGrid(commonConfiguration(0)); super.execute(node(), "CREATE TABLE INTS(k int primary key, v int) WITH \"wrap_value=false,cache_name=ints," + - "atomicity=transactional\""); + "atomicity=transactional_snapshot\""); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccBulkLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccBulkLoadTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccBulkLoadTest.java index d620e84..98bbdfc 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccBulkLoadTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccBulkLoadTest.java @@ -57,7 +57,7 @@ public class CacheMvccBulkLoadTest extends CacheMvccAbstractTest { "create table person(" + " id int not null primary key," + " name varchar not null" + - ") with \"atomicity=transactional\"" + ") with \"atomicity=transactional_snapshot\"" )); stmt = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1").createStatement(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccDmlSimpleTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccDmlSimpleTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccDmlSimpleTest.java index bb5e753..7f141ca 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccDmlSimpleTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccDmlSimpleTest.java @@ -49,7 +49,7 @@ public class CacheMvccDmlSimpleTest extends CacheMvccAbstractTest { cache = startGrid(0).getOrCreateCache( new CacheConfiguration<>("test") - .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) .setSqlSchema("PUBLIC") .setIndexedTypes(Integer.class, Integer.class) ); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSelectForUpdateQueryAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSelectForUpdateQueryAbstractTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSelectForUpdateQueryAbstractTest.java index 152dc7e..739aaf8 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSelectForUpdateQueryAbstractTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSelectForUpdateQueryAbstractTest.java @@ -17,6 +17,13 @@ package org.apache.ignite.internal.processors.cache.mvcc; +import java.sql.Connection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; +import javax.cache.CacheException; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.QueryEntity; @@ -32,14 +39,6 @@ import org.apache.ignite.transactions.Transaction; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; -import javax.cache.CacheException; -import java.sql.Connection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; - import static org.apache.ignite.cache.CacheMode.PARTITIONED; import static org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.connect; import static org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.execute; @@ -73,10 +72,10 @@ public abstract class CacheMvccSelectForUpdateQueryAbstractTest extends CacheMvc try (Connection c = connect(grid(0))) { execute(c, "create table person (id int primary key, firstName varchar, lastName varchar) " + - "with \"atomicity=transactional,cache_name=Person\""); + "with \"atomicity=transactional_snapshot,cache_name=Person\""); execute(c, "create table person_seg (id int primary key, firstName varchar, lastName varchar) " + - "with \"atomicity=transactional,cache_name=PersonSeg,template=segmented\""); + "with \"atomicity=transactional_snapshot,cache_name=PersonSeg,template=segmented\""); try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeTest.java index 32709ff..fe1304a 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeTest.java @@ -444,7 +444,7 @@ public class CacheMvccSizeTest extends CacheMvccAbstractTest { /** */ private static IgniteCache<?, ?> table(IgniteEx ignite) { - assert ignite.cachex("person").configuration().getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL; + assert ignite.cachex("person").configuration().getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT; assert ignite.cachex("person").configuration().getCacheMode() == CacheMode.REPLICATED; return ignite.cache("person"); @@ -458,7 +458,7 @@ public class CacheMvccSizeTest extends CacheMvccAbstractTest { "create table person(" + " id int primary key," + " name varchar" + - ") with \"atomicity=transactional,template=replicated,cache_name=person\"")); + ") with \"atomicity=transactional_snapshot,template=replicated,cache_name=person\"")); return table(ignite); } http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlConfigurationValidationTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlConfigurationValidationTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlConfigurationValidationTest.java new file mode 100644 index 0000000..7e6c9e8 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlConfigurationValidationTest.java @@ -0,0 +1,111 @@ +/* + * 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.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionConcurrency; +import org.apache.ignite.transactions.TransactionIsolation; + +/** + * Configuration validation for SQL configured caches. + */ +public class CacheMvccSqlConfigurationValidationTest extends CacheMvccAbstractTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return CacheMode.PARTITIONED; + } + + /** + * @throws Exception If failed. + */ + public void testCacheGroupAtomicityModeMismatch1() throws Exception { + Ignite node = startGrid(); + + node.getOrCreateCache(DEFAULT_CACHE_NAME) + .query(new SqlFieldsQuery("CREATE TABLE City (id int primary key, name varchar, population int) WITH " + + "\"atomicity=transactional_snapshot,cache_group=group1,template=partitioned,backups=3,cache_name=City\"")) + .getAll();; + + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + node.cache(DEFAULT_CACHE_NAME) + .query(new SqlFieldsQuery("CREATE TABLE Person (id int primary key, name varchar) WITH " + + "\"atomicity=transactional,cache_group=group1,template=partitioned,backups=3,cache_name=Person\"")) + .getAll(); + + return null; + } + }, CacheException.class, "Atomicity mode mismatch for caches related to the same group"); + } + + /** + * @throws Exception If failed. + */ + public void testCacheGroupAtomicityModeMismatch2() throws Exception { + Ignite node = startGrid(); + + node.getOrCreateCache(DEFAULT_CACHE_NAME) + .query(new SqlFieldsQuery("CREATE TABLE City (id int primary key, name varchar, population int) WITH " + + "\"atomicity=transactional,cache_group=group1,template=partitioned,backups=3,cache_name=City\"")); + + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + node.cache(DEFAULT_CACHE_NAME) + .query(new SqlFieldsQuery("CREATE TABLE Person (id int primary key, name varchar) WITH " + + "\"atomicity=transactional_snapshot,cache_group=group1,template=partitioned,backups=3,cache_name=Person\"")) + .getAll(); + + return null; + } + }, CacheException.class, "Atomicity mode mismatch for caches related to the same group"); + } + + /** + * @throws Exception If failed. + */ + public void testTxDifferentMvccSettingsTransactional() throws Exception { + ccfg = defaultCacheConfiguration().setSqlSchema("PUBLIC"); + Ignite node = startGrid(); + + IgniteCache cache = node.cache(DEFAULT_CACHE_NAME); + + cache.query(new SqlFieldsQuery("CREATE TABLE Person (id int primary key, name varchar) WITH " + + "\"atomicity=transactional_snapshot,template=partitioned,backups=1\"")).getAll(); + + cache.query(new SqlFieldsQuery("CREATE TABLE City (id int primary key, name varchar, population int) WITH " + + "\"atomicity=transactional,template=partitioned,backups=3\"")).getAll(); + + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + try (Transaction tx = node.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { + cache.query(new SqlFieldsQuery("SELECT * FROM Person, City")).getAll(); + + tx.commit(); + } + + return null; + } + }, CacheException.class, "Caches with transactional_snapshot atomicity mode cannot participate in the same transaction"); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlTxQueriesAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlTxQueriesAbstractTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlTxQueriesAbstractTest.java index e683def..2aad2d4 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlTxQueriesAbstractTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlTxQueriesAbstractTest.java @@ -1624,7 +1624,7 @@ public abstract class CacheMvccSqlTxQueriesAbstractTest extends CacheMvccAbstrac ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT) .setIndexedTypes(Integer.class, Integer.class); - startGrid(getConfiguration("grid").setMvccVacuumTimeInterval(Integer.MAX_VALUE)); + startGrid(getConfiguration("grid").setMvccVacuumFrequency(Integer.MAX_VALUE)); Ignite client = startGrid(getConfiguration("client").setClientMode(true)); @@ -1696,7 +1696,7 @@ public abstract class CacheMvccSqlTxQueriesAbstractTest extends CacheMvccAbstrac ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT) .setIndexedTypes(Integer.class, Integer.class); - Ignite node = startGrid(getConfiguration("grid").setMvccVacuumTimeInterval(100)); + Ignite node = startGrid(getConfiguration("grid").setMvccVacuumFrequency(100)); node.cluster().active(true); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccStreamingInsertTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccStreamingInsertTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccStreamingInsertTest.java index 7d2e335..b07a187 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccStreamingInsertTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccStreamingInsertTest.java @@ -57,7 +57,7 @@ public class CacheMvccStreamingInsertTest extends CacheMvccAbstractTest { "create table person(" + " id int not null primary key," + " name varchar not null" + - ") with \"atomicity=transactional\"" + ") with \"atomicity=transactional_snapshot\"" )); Properties props = new Properties(); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildSelfTest.java index 1a6cb55..c5f1441 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildSelfTest.java @@ -113,7 +113,7 @@ public class GridIndexRebuildSelfTest extends DynamicIndexAbstractSelfTest { IgniteEx srv = startServer(); execute(srv, "CREATE TABLE T(k int primary key, v int) WITH \"cache_name=T,wrap_value=false," + - "atomicity=transactional\""); + "atomicity=transactional_snapshot\""); execute(srv, "CREATE INDEX IDX ON T(v)"); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildWithMvccEnabledSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildWithMvccEnabledSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildWithMvccEnabledSelfTest.java index 3d65db8..cf68546 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildWithMvccEnabledSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexRebuildWithMvccEnabledSelfTest.java @@ -40,8 +40,7 @@ public class GridIndexRebuildWithMvccEnabledSelfTest extends GridIndexRebuildSel /** {@inheritDoc} */ @Override protected IgniteConfiguration serverConfiguration(int idx, boolean filter) throws Exception { return super.serverConfiguration(idx, filter) - .setMvccVacuumTimeInterval(Integer.MAX_VALUE) - .setMvccEnabled(true); + .setMvccVacuumFrequency(Integer.MAX_VALUE); } /** {@inheritDoc} */ @@ -49,7 +48,7 @@ public class GridIndexRebuildWithMvccEnabledSelfTest extends GridIndexRebuildSel IgniteEx srv = startServer(); execute(srv, "CREATE TABLE T(k int primary key, v int) WITH \"cache_name=T,wrap_value=false," + - "atomicity=transactional\""); + "atomicity=transactional_snapshot\""); execute(srv, "CREATE INDEX IDX ON T(v)"); http://git-wip-us.apache.org/repos/asf/ignite/blob/2ab94934/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccSqlTestSuite.java ---------------------------------------------------------------------- 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 c8f7643..ec60596 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 @@ -38,6 +38,7 @@ import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccReplicatedSqlTx import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccScanQueryWithConcurrentJdbcTransactionTest; import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccSizeTest; import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccSizeWithConcurrentJdbcTransactionTest; +import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccSqlConfigurationValidationTest; import org.apache.ignite.internal.processors.cache.mvcc.CacheMvccStreamingInsertTest; import org.apache.ignite.internal.processors.query.h2.GridIndexRebuildWithMvccEnabledSelfTest; @@ -52,6 +53,7 @@ public class IgniteCacheMvccSqlTestSuite extends TestSuite { TestSuite suite = new TestSuite("IgniteCache SQL MVCC Test Suite"); // Simple tests. + suite.addTestSuite(CacheMvccSqlConfigurationValidationTest.class); suite.addTestSuite(CacheMvccDmlSimpleTest.class); suite.addTestSuite(SqlTransactionsCommandsWithMvccEnabledSelfTest.class); suite.addTestSuite(CacheMvccSizeTest.class);