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:31 UTC
[3/4] incubator-ignite git commit: #sberb-28: add exception in
start/stop cache if lock exist.
#sberb-28: add exception in start/stop cache if lock 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/beba2074
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/beba2074
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/beba2074
Branch: refs/heads/sberb-28
Commit: beba207454ac124f02945e7447a6993cce56e951
Parents: 4f18b6c
Author: ivasilinets <iv...@gridgain.com>
Authored: Thu Jun 11 13:24:42 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Thu Jun 11 13:24:42 2015 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheMvccManager.java | 7 +++++
.../processors/cache/GridCacheProcessor.java | 3 +++
.../cache/StartCacheInTransactionSelfTest.java | 27 +++++++++++++++++---
3 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/beba2074/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
index c528e08..bd48f5e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMvccManager.java
@@ -572,6 +572,13 @@ public class GridCacheMvccManager extends GridCacheSharedManagerAdapter {
}
/**
+ * @return True if any locks acquired.
+ */
+ public boolean hasLocks() {
+ return !locked.isEmpty() || !nearLocked.isEmpty();
+ }
+
+ /**
* This method has poor performance, so use with care. It is currently only used by {@code DGC}.
*
* @return Remote candidates.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/beba2074/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 17e6ec0..6c320ae 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
@@ -2961,6 +2961,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
private void checkEmptyTransactions() throws IgniteException {
if (transactions().tx() != null)
throw new IgniteException("Cannot start/stop cache within transaction.");
+
+ if (ctx.cache().context().mvcc().hasLocks())
+ throw new IgniteException("Cannot start/stop cache within lock.");
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/beba2074/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 e2be184..7518a62 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
@@ -25,6 +25,7 @@ import org.apache.ignite.testframework.junits.common.*;
import org.apache.ignite.transactions.*;
import java.util.concurrent.*;
+import java.util.concurrent.locks.*;
/**
* Check starting cache in transaction.
@@ -69,9 +70,7 @@ public class StartCacheInTransactionSelfTest extends GridCommonAbstractTest {
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
- IgniteCache<String, String> cache = ignite.createCache("NEW_CACHE");
-
- cache.put(key, val);
+ ignite.createCache("NEW_CACHE");
return null;
}
@@ -105,4 +104,26 @@ public class StartCacheInTransactionSelfTest extends GridCommonAbstractTest {
tx.commit();
}
}
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLockCache() throws Exception {
+ final Ignite ignite = grid(0);
+
+ final String key = "key";
+
+ Lock lock = ignite.cache(null).lock(key);
+
+ lock.lock();
+ GridTestUtils.assertThrows(log, new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ ignite.createCache("NEW_CACHE");
+
+ return null;
+ }
+ }, IgniteException.class, "Cannot start/stop cache within lock.");
+
+ lock.unlock();
+ }
}