You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2018/07/18 14:15:38 UTC
ignite git commit: IGNITE-2313 Added an option to fail atomic cache
access within a transaction - Fixes #4280.
Repository: ignite
Updated Branches:
refs/heads/master 2b22933b8 -> 4b4d263ea
IGNITE-2313 Added an option to fail atomic cache access within a transaction - Fixes #4280.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4b4d263e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4b4d263e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4b4d263e
Branch: refs/heads/master
Commit: 4b4d263ea0762d3504f3401b439974e7b92577d2
Parents: 2b22933
Author: Dmitrii Ryabov <So...@gmail.com>
Authored: Wed Jul 18 17:13:58 2018 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Wed Jul 18 17:13:58 2018 +0300
----------------------------------------------------------------------
.../src/main/java/org/apache/ignite/IgniteCache.java | 7 ++++++-
.../processors/cache/GatewayProtectedCacheProxy.java | 5 +++++
.../cache/transactions/AtomicOperationsInTxTest.java | 14 ++++++++++++++
3 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/4b4d263e/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index 7de830a..cf8087a 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -177,7 +177,12 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
public <K1, V1> IgniteCache<K1, V1> withKeepBinary();
/**
- * Reasonable only for atomic caches.
+ * By default atomic operations are allowed in transaction.
+ * To restrict transactions from operations with atomic caches you can set system property
+ * {@link IgniteSystemProperties#IGNITE_ALLOW_ATOMIC_OPS_IN_TX IGNITE_ALLOW_ATOMIC_OPS_IN_TX} to {@code false}.
+ * <p>
+ * If you want to use atomic operations inside transactions in case they are restricted by system property,
+ * you should allow it before transaction start.
*
* @return Cache with atomic operations allowed in transactions.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/4b4d263e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
index 33ea048..5a081fa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
@@ -176,6 +176,11 @@ public class GatewayProtectedCacheProxy<K, V> extends AsyncSupportAdapter<Ignite
/** {@inheritDoc} */
@Override public IgniteCache<K, V> withAllowAtomicOpsInTx() {
+ if (context().atomic() && !opCtx.allowedAtomicOpsInTx() && context().tm().tx() != null) {
+ throw new IllegalStateException("Enabling atomic operations during active transaction is not allowed. " +
+ "Enable atomic operations before transaction start.");
+ }
+
CacheOperationGate opGate = onEnter();
try {
http://git-wip-us.apache.org/repos/asf/ignite/blob/4b4d263e/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicOperationsInTxTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicOperationsInTxTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicOperationsInTxTest.java
index f12d790..b58dbe0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicOperationsInTxTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicOperationsInTxTest.java
@@ -71,6 +71,20 @@ public class AtomicOperationsInTxTest extends GridCommonAbstractTest {
/**
* @throws Exception If failed.
*/
+ public void testEnablingAtomicOperationDuringTransaction() throws Exception {
+ GridTestUtils.assertThrows(log, (Callable<IgniteCache>)() -> {
+ try (Transaction tx = grid(0).transactions().txStart()) {
+ return grid(0).cache(DEFAULT_CACHE_NAME).withAllowAtomicOpsInTx();
+ }
+ },
+ IllegalStateException.class,
+ "Enabling atomic operations during active transaction is not allowed."
+ );
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
public void testAllowedAtomicOperations() throws Exception {
checkOperations(true);
}