You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/11 12:26:30 UTC
[2/4] incubator-ignite git commit: #sberb-28: add exception in
start/stop cache if transaction exist.
#sberb-28: add exception in start/stop cache if transaction exist.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4f18b6c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4f18b6c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4f18b6c9
Branch: refs/heads/sberb-28
Commit: 4f18b6c9e1be20ee2629aef190e449c78327f802
Parents: d757582
Author: ivasilinets <iv...@gridgain.com>
Authored: Thu Jun 11 13:00:23 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Thu Jun 11 13:00:23 2015 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheProcessor.java | 14 +++++++
.../cache/StartCacheInTransactionSelfTest.java | 40 ++++++++++++++++++--
2 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4f18b6c9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 5582ba7..17e6ec0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -1880,6 +1880,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
CacheType cacheType,
boolean failIfExists
) {
+ checkEmptyTransactions();
+
assert ccfg != null || nearCfg != null;
DynamicCacheDescriptor desc = registeredCaches.get(maskNull(cacheName));
@@ -1970,6 +1972,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
* @return Future that will be completed when cache is stopped.
*/
public IgniteInternalFuture<?> dynamicStopCache(String cacheName) {
+ checkEmptyTransactions();
+
DynamicCacheChangeRequest t = new DynamicCacheChangeRequest(cacheName, ctx.localNodeId(), true);
return F.first(initiateCacheChanges(F.asList(t), false));
@@ -2653,6 +2657,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
* @throws IgniteCheckedException If failed.
*/
private IgniteCacheProxy startJCache(String cacheName, boolean failIfNotStarted) throws IgniteCheckedException {
+ checkEmptyTransactions();
+
String masked = maskNull(cacheName);
DynamicCacheDescriptor desc = registeredCaches.get(masked);
@@ -2950,6 +2956,14 @@ public class GridCacheProcessor extends GridProcessorAdapter {
}
/**
+ * @throws IgniteException If transaction exist.
+ */
+ private void checkEmptyTransactions() throws IgniteException {
+ if (transactions().tx() != null)
+ throw new IgniteException("Cannot start/stop cache within transaction.");
+ }
+
+ /**
* @param val Object to check.
* @throws IgniteCheckedException If validation failed.
*/
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4f18b6c9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/StartCacheInTransactionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/StartCacheInTransactionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/StartCacheInTransactionSelfTest.java
index 391a2c6..e2be184 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/StartCacheInTransactionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/StartCacheInTransactionSelfTest.java
@@ -20,9 +20,12 @@ package org.apache.ignite.internal.processors.cache;
import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.configuration.*;
+import org.apache.ignite.testframework.*;
import org.apache.ignite.testframework.junits.common.*;
import org.apache.ignite.transactions.*;
+import java.util.concurrent.*;
+
/**
* Check starting cache in transaction.
*/
@@ -55,7 +58,34 @@ public class StartCacheInTransactionSelfTest extends GridCommonAbstractTest {
* @throws Exception If failed.
*/
public void testStartCache() throws Exception {
- Ignite ignite = grid(0);
+ final Ignite ignite = grid(0);
+
+ final String key = "key";
+ final String val = "val";
+
+ try (Transaction tx = ignite.transactions().txStart(
+ TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)){
+ ignite.cache(null).put(key, val);
+
+ GridTestUtils.assertThrows(log, new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ IgniteCache<String, String> cache = ignite.createCache("NEW_CACHE");
+
+ cache.put(key, val);
+
+ return null;
+ }
+ }, IgniteException.class, "Cannot start/stop cache within transaction.");
+
+ tx.commit();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testStopCache() throws Exception {
+ final Ignite ignite = grid(0);
final String key = "key";
final String val = "val";
@@ -64,9 +94,13 @@ public class StartCacheInTransactionSelfTest extends GridCommonAbstractTest {
TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)){
ignite.cache(null).put(key, val);
- IgniteCache<String, String> cache = ignite.createCache("NEW_CACHE");
+ GridTestUtils.assertThrows(log, new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ ignite.destroyCache(null);
- cache.put(key, val);
+ return null;
+ }
+ }, IgniteException.class, "Cannot start/stop cache within transaction.");
tx.commit();
}