IGNITE-2792: User-defined configuration is not passed to system caches anymore. This closes #551.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/91a15342 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/91a15342 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/91a15342 Branch: refs/heads/ignite-2801 Commit: 91a153428b353554e0429b55b43b7ddf7b9ce8ca Parents: db05727 Author: dkarachentsev <[email protected]> Authored: Wed Mar 16 11:56:14 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Wed Mar 16 12:00:55 2016 +0300 ---------------------------------------------------------------------- .../processors/cache/GridCacheAdapter.java | 10 +- .../processors/cache/GridCacheUtils.java | 14 ++ .../transactions/IgniteTransactionsImpl.java | 9 +- .../cache/IgniteTxConfigCacheSelfTest.java | 249 +++++++++++++++++++ .../ignite/testsuites/IgniteCacheTestSuite.java | 2 + .../hadoop/cache/HadoopTxConfigCacheTest.java | 42 ++++ .../testsuites/IgniteHadoopTestSuite.java | 3 + 7 files changed, 320 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/91a15342/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java index 37347ef..54046a9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java @@ -3477,7 +3477,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V A.notNull(concurrency, "concurrency"); A.notNull(isolation, "isolation"); - TransactionConfiguration cfg = ctx.gridConfig().getTransactionConfiguration(); + TransactionConfiguration cfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config()); return txStart( concurrency, @@ -4265,7 +4265,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V IgniteTxLocalAdapter tx = ctx.tm().threadLocalTx(ctx); if (tx == null || tx.implicit()) { - TransactionConfiguration tCfg = ctx.gridConfig().getTransactionConfiguration(); + TransactionConfiguration tCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config()); CacheOperationContext opCtx = ctx.operationContextPerCall(); @@ -4362,6 +4362,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V CacheOperationContext opCtx = ctx.operationContextPerCall(); + final TransactionConfiguration txCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config()); + if (tx == null || tx.implicit()) { boolean skipStore = ctx.skipStore(); // Save value of thread-local flag. @@ -4374,7 +4376,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V ctx.systemTx() ? ctx : null, OPTIMISTIC, READ_COMMITTED, - ctx.kernalContext().config().getTransactionConfiguration().getDefaultTxTimeout(), + txCfg.getDefaultTxTimeout(), !skipStore, 0); @@ -5077,7 +5079,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V ctx.systemTx() ? ctx : null, OPTIMISTIC, READ_COMMITTED, - ctx.kernalContext().config().getTransactionConfiguration().getDefaultTxTimeout(), + CU.transactionConfiguration(ctx, ctx.kernalContext().config()).getDefaultTxTimeout(), opCtx == null || !opCtx.skipStore(), 0); http://git-wip-us.apache.org/repos/asf/ignite/blob/91a15342/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java index 51f6dcd..66fa8dd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java @@ -57,6 +57,7 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.FileSystemConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; @@ -156,6 +157,9 @@ public class GridCacheUtils { /** Empty predicate array. */ private static final IgnitePredicate[] EMPTY = new IgnitePredicate[0]; + /** Default transaction config. */ + private static final TransactionConfiguration DEFAULT_TX_CFG = new TransactionConfiguration(); + /** Partition to state transformer. */ private static final IgniteClosure PART2STATE = new C1<GridDhtLocalPartition, GridDhtPartitionState>() { @@ -1863,4 +1867,14 @@ public class GridCacheUtils { return res; } + + /** + * @return default TX configuration if system cache is used or current grid TX config otherwise. + */ + public static TransactionConfiguration transactionConfiguration(final @Nullable GridCacheContext sysCacheCtx, + final IgniteConfiguration cfg) { + return sysCacheCtx != null && sysCacheCtx.systemTx() + ? DEFAULT_TX_CFG + : cfg.getTransactionConfiguration(); + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/91a15342/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java index 76f2f77..7c7b5a8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java @@ -23,14 +23,13 @@ import org.apache.ignite.internal.IgniteTransactionsEx; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.transactions.Transaction; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; import org.apache.ignite.transactions.TransactionMetrics; import org.jetbrains.annotations.Nullable; -import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE; - /** * Grid transactions implementation. */ @@ -47,7 +46,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx { /** {@inheritDoc} */ @Override public Transaction txStart() throws IllegalStateException { - TransactionConfiguration cfg = cctx.gridConfig().getTransactionConfiguration(); + TransactionConfiguration cfg = CU.transactionConfiguration(null, cctx.kernalContext().config()); return txStart0( cfg.getDefaultTxConcurrency(), @@ -63,7 +62,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx { A.notNull(concurrency, "concurrency"); A.notNull(isolation, "isolation"); - TransactionConfiguration cfg = cctx.gridConfig().getTransactionConfiguration(); + TransactionConfiguration cfg = CU.transactionConfiguration(null, cctx.kernalContext().config()); return txStart0( concurrency, @@ -124,7 +123,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx { checkTransactional(ctx); - TransactionConfiguration cfg = cctx.gridConfig().getTransactionConfiguration(); + TransactionConfiguration cfg = CU.transactionConfiguration(ctx, cctx.kernalContext().config()); return txStart0(concurrency, isolation, http://git-wip-us.apache.org/repos/asf/ignite/blob/91a15342/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java new file mode 100644 index 0000000..94b5620 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java @@ -0,0 +1,249 @@ +/* + * 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; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx; +import org.apache.ignite.internal.util.typedef.internal.CU; +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.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionTimeoutException; + +import javax.cache.CacheException; +import javax.cache.processor.EntryProcessor; +import javax.cache.processor.EntryProcessorException; +import javax.cache.processor.MutableEntry; + +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; + +/** + * Test checks that grid transaction configuration doesn't influence system caches. + */ +public class IgniteTxConfigCacheSelfTest extends GridCommonAbstractTest { + /** Ip finder. */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** Test cache name. */ + private static final String CACHE_NAME = "cache_name"; + + /** Timeout of transaction. */ + private static final long TX_TIMEOUT = 100; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setAtomicityMode(atomicityMode()); + ccfg.setBackups(1); + + cfg.setCacheConfiguration(ccfg); + + final TransactionConfiguration txCfg = new TransactionConfiguration(); + + txCfg.setDefaultTxTimeout(TX_TIMEOUT); + + cfg.setTransactionConfiguration(txCfg); + + return cfg; + } + + /** + * @return Cache atomicity mode. + */ + public CacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrids(1); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** + * Success if user tx was timed out. + * + * @throws Exception + */ + public void testUserTxTimeout() throws Exception { + final Ignite ignite = grid(0); + + final IgniteCache<Object, Object> cache = ignite.getOrCreateCache(CACHE_NAME); + + checkImplicitTxTimeout(cache); + checkExplicitTxTimeout(cache, ignite); + } + + /** + * Success if system caches weren't timed out. + * + * @throws Exception + */ + public void testSystemCacheTx() throws Exception { + final Ignite ignite = grid(0); + + final IgniteInternalCache<Object, Object> utilCache = getSystemCache(ignite, CU.UTILITY_CACHE_NAME); + + checkImplicitTxSuccess(utilCache); + checkStartTxSuccess(utilCache); + + final IgniteInternalCache<Object, Object> atomicsCache = getSystemCache(ignite, CU.ATOMICS_CACHE_NAME); + + checkImplicitTxSuccess(atomicsCache); + checkStartTxSuccess(atomicsCache); + } + + /** + * Extract system cache from kernal. + * + * @param ignite Ignite instance. + * @param cacheName System cache name. + * @return Internal cache instance. + */ + protected IgniteInternalCache<Object, Object> getSystemCache(final Ignite ignite, final String cacheName) { + return ((IgniteKernal) ignite).context().cache().cache(cacheName); + } + + /** + * Success if implicit tx fails. + * + * @param cache Cache name. + * @throws Exception + */ + protected void checkImplicitTxTimeout(final IgniteCache<Object, Object> cache) throws Exception { + try { + cache.invoke("key", new EntryProcessor<Object, Object, Object>() { + @Override public Object process(final MutableEntry<Object, Object> entry, final Object... args) + throws EntryProcessorException { + try { + sleepForTxFailure(); + } catch (InterruptedException e) { + throw new EntryProcessorException(e); + } + + return null; + } + }); + + fail("Timeout exception must be thrown"); + } + catch (CacheException e) { + // OK + } + + cache.clear(); + } + + /** + * Success if explicit tx fails. + * + * @param cache Cache name. + * @param ignite Ignite instance. + * @throws Exception + */ + protected void checkExplicitTxTimeout(final IgniteCache<Object, Object> cache, final Ignite ignite) + throws Exception { + try (final Transaction tx = ignite.transactions().txStart()) { + assert tx != null; + + sleepForTxFailure(); + + cache.put("key", "val"); + + fail("Timeout exception must be thrown"); + } + catch (CacheException e) { + assert e.getCause() instanceof TransactionTimeoutException; + } + + assert !cache.containsKey("key"); + } + + /** + * Success if explicit tx doesn't fail. + * + * @param cache Cache instance. + * @throws Exception + */ + protected void checkStartTxSuccess(final IgniteInternalCache<Object, Object> cache) throws Exception { + try (final IgniteInternalTx tx = CU.txStartInternal(cache.context(), cache, PESSIMISTIC, READ_COMMITTED)) { + assert tx != null; + + sleepForTxFailure(); + + cache.put("key", "val"); + + tx.commit(); + } + + assert cache.containsKey("key"); + + cache.clear(); + } + + /** + * Success if implicit tx fails. + * + * @param cache Cache instance. + * @throws Exception + */ + protected void checkImplicitTxSuccess(final IgniteInternalCache<Object, Object> cache) throws Exception { + cache.invoke("key", new EntryProcessor<Object, Object, Object>() { + @Override public Object process(final MutableEntry<Object, Object> entry, final Object... args) + throws EntryProcessorException { + try { + sleepForTxFailure(); + } catch (InterruptedException e) { + throw new EntryProcessorException(e); + } + return null; + } + }); + + cache.clear(); + } + + /** + * Sleep multiple {@link #TX_TIMEOUT} times. + * + * @throws InterruptedException + */ + private void sleepForTxFailure() throws InterruptedException { + Thread.sleep(TX_TIMEOUT * 3); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/91a15342/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index 045ff6f..2613175 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -107,6 +107,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheTxNearEnabledInvok import org.apache.ignite.internal.processors.cache.IgniteClientAffinityAssignmentSelfTest; import org.apache.ignite.internal.processors.cache.IgnitePutAllLargeBatchSelfTest; import org.apache.ignite.internal.processors.cache.IgnitePutAllUpdateNonPreloadedPartitionSelfTest; +import org.apache.ignite.internal.processors.cache.IgniteTxConfigCacheSelfTest; import org.apache.ignite.internal.processors.cache.context.IgniteCacheAtomicExecutionContextTest; import org.apache.ignite.internal.processors.cache.context.IgniteCacheContinuousExecutionContextTest; import org.apache.ignite.internal.processors.cache.context.IgniteCacheIsolatedExecutionContextTest; @@ -293,6 +294,7 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTestSuite(CachePutEventListenerErrorSelfTest.class); + suite.addTestSuite(IgniteTxConfigCacheSelfTest.class); return suite; } } http://git-wip-us.apache.org/repos/asf/ignite/blob/91a15342/modules/hadoop/src/test/java/org/apache/ignite/hadoop/cache/HadoopTxConfigCacheTest.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/cache/HadoopTxConfigCacheTest.java b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/cache/HadoopTxConfigCacheTest.java new file mode 100644 index 0000000..6f910f1 --- /dev/null +++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/cache/HadoopTxConfigCacheTest.java @@ -0,0 +1,42 @@ +/* + * 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.hadoop.cache; + +import org.apache.ignite.Ignite; +import org.apache.ignite.internal.processors.cache.IgniteInternalCache; +import org.apache.ignite.internal.processors.cache.IgniteTxConfigCacheSelfTest; +import org.apache.ignite.internal.util.typedef.internal.CU; + +/** + * Test checks whether hadoop system cache doesn't use user defined TX config. + */ +public class HadoopTxConfigCacheTest extends IgniteTxConfigCacheSelfTest { + /** + * Success if system caches weren't timed out. + * + * @throws Exception + */ + public void testSystemCacheTx() throws Exception { + final Ignite ignite = grid(0); + + final IgniteInternalCache<Object, Object> hadoopCache = getSystemCache(ignite, CU.SYS_CACHE_HADOOP_MR); + + checkImplicitTxSuccess(hadoopCache); + checkStartTxSuccess(hadoopCache); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/91a15342/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java index acd255c..e03e4e1 100644 --- a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java +++ b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java @@ -35,6 +35,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.client.hadoop.HadoopClientProtocolEmbeddedSelfTest; import org.apache.ignite.client.hadoop.HadoopClientProtocolSelfTest; +import org.apache.ignite.hadoop.cache.HadoopTxConfigCacheTest; import org.apache.ignite.hadoop.fs.KerberosHadoopFileSystemFactorySelfTest; import org.apache.ignite.igfs.Hadoop1OverIgfsDualAsyncTest; import org.apache.ignite.igfs.Hadoop1OverIgfsDualSyncTest; @@ -181,6 +182,8 @@ public class IgniteHadoopTestSuite extends TestSuite { suite.addTest(new TestSuite(ldr.loadClass(HadoopCommandLineTest.class.getName()))); suite.addTest(new TestSuite(ldr.loadClass(HadoopSecondaryFileSystemConfigurationTest.class.getName()))); + + suite.addTest(new TestSuite(ldr.loadClass(HadoopTxConfigCacheTest.class.getName()))); return suite; }
