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/08 09:12:26 UTC
[4/7] incubator-ignite git commit: IGNITE-941 - Read-only mode for
transactional cache
IGNITE-941 - Read-only mode for transactional cache
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/b4d19159
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/b4d19159
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/b4d19159
Branch: refs/heads/ignite-883_1
Commit: b4d19159a76559152435946d1fff421679712599
Parents: b58c892
Author: Valentin Kulichenko <vk...@gridgain.com>
Authored: Thu Jun 4 18:08:35 2015 -0700
Committer: Valentin Kulichenko <vk...@gridgain.com>
Committed: Thu Jun 4 18:08:35 2015 -0700
----------------------------------------------------------------------
.../apache/ignite/internal/IgniteKernal.java | 2 +
.../ignite/internal/IgniteNodeAttributes.java | 5 +-
.../processors/cache/GridCacheProcessor.java | 2 +-
.../transactions/IgniteTxLocalAdapter.java | 29 +++++++--
.../IgniteTxRollbackCheckedException.java | 9 +++
...acheReadOnlyTransactionalClientSelfTest.java | 68 +++++++++++++++-----
6 files changed, 94 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b4d19159/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index a0d97c7..9bc6cce 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -1168,6 +1168,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
add(ATTR_CLIENT_MODE, cfg.isClientMode());
+ add(ATTR_CONSISTENCY_CHECK_SKIPPED, getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK));
+
// Build a string from JVM arguments, because parameters with spaces are split.
SB jvmArgs = new SB(512);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b4d19159/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java
index 98cc3a7..928db5e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java
@@ -126,9 +126,12 @@ public final class IgniteNodeAttributes {
/** Security subject for authenticated node. */
public static final String ATTR_SECURITY_SUBJECT = ATTR_PREFIX + ".security.subject";
- /** Cache interceptors. */
+ /** Client mode flag. */
public static final String ATTR_CLIENT_MODE = ATTR_PREFIX + ".cache.client";
+ /** Configuration consistency check disabled flag. */
+ public static final String ATTR_CONSISTENCY_CHECK_SKIPPED = ATTR_PREFIX + ".consistency.check.skipped";
+
/**
* Enforces singleton.
*/
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b4d19159/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 bbd5fe9..871cd77 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
@@ -674,7 +674,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
for (ClusterNode n : ctx.discovery().remoteNodes()) {
- if (Boolean.valueOf(n.<String>attribute(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)))
+ if (n.attribute(ATTR_CONSISTENCY_CHECK_SKIPPED))
continue;
checkTransactionConfiguration(n);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b4d19159/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
index 4063be2..8b5eaec 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
@@ -2535,6 +2535,19 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
}
/**
+ * @param cacheCtx Cache context.
+ * @throws IgniteCheckedException If updates are not allowed.
+ */
+ private void checkUpdatesAllowed(GridCacheContext cacheCtx) throws IgniteCheckedException {
+ if (!cacheCtx.updatesAllowed()) {
+ throw new IgniteTxRollbackCheckedException(new CacheException(
+ "Updates are not allowed for transactional cache: " + cacheCtx.name() + ". Configure " +
+ "persistence store on client or use remote closure execution to start transactions " +
+ "from server nodes."));
+ }
+ }
+
+ /**
* Internal method for all put and transform operations. Only one of {@code map}, {@code transformMap}
* maps must be non-null.
*
@@ -2561,8 +2574,12 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
) {
assert filter == null || invokeMap == null;
- if (!cacheCtx.updatesAllowed())
- throw new CacheException("Updates are not allowed for cache: " + cacheCtx.name());
+ try {
+ checkUpdatesAllowed(cacheCtx);
+ }
+ catch (IgniteCheckedException e) {
+ return new GridFinishedFuture(e);
+ }
cacheCtx.checkSecurity(SecurityPermission.CACHE_PUT);
@@ -2784,8 +2801,12 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
@Nullable GridCacheEntryEx cached,
final boolean retval,
@Nullable final CacheEntryPredicate[] filter) {
- if (!cacheCtx.updatesAllowed())
- throw new CacheException("Updates are not allowed for cache: " + cacheCtx.name());
+ try {
+ checkUpdatesAllowed(cacheCtx);
+ }
+ catch (IgniteCheckedException e) {
+ return new GridFinishedFuture(e);
+ }
cacheCtx.checkSecurity(SecurityPermission.CACHE_REMOVE);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b4d19159/modules/core/src/main/java/org/apache/ignite/internal/transactions/IgniteTxRollbackCheckedException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/transactions/IgniteTxRollbackCheckedException.java b/modules/core/src/main/java/org/apache/ignite/internal/transactions/IgniteTxRollbackCheckedException.java
index 1d1e022..f8ee265 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/transactions/IgniteTxRollbackCheckedException.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/transactions/IgniteTxRollbackCheckedException.java
@@ -36,6 +36,15 @@ public class IgniteTxRollbackCheckedException extends IgniteCheckedException {
}
/**
+ * Creates new exception with given nested exception.
+ *
+ * @param cause Nested exception.
+ */
+ public IgniteTxRollbackCheckedException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
* Creates new rollback exception with given error message and optional nested exception.
*
* @param msg Error message.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b4d19159/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadOnlyTransactionalClientSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadOnlyTransactionalClientSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadOnlyTransactionalClientSelfTest.java
index e2a1def..f2c38e1 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadOnlyTransactionalClientSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadOnlyTransactionalClientSelfTest.java
@@ -31,6 +31,8 @@ import javax.cache.*;
import javax.cache.configuration.*;
import javax.cache.processor.*;
+import static org.apache.ignite.IgniteSystemProperties.*;
+
/**
* Tests for read-only transactional cache client.
*/
@@ -39,6 +41,9 @@ public class CacheReadOnlyTransactionalClientSelfTest extends GridCommonAbstract
private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
/** */
+ private static final String CACHE_NAME = "test-cache";
+
+ /** */
private boolean client;
/** */
@@ -55,6 +60,7 @@ public class CacheReadOnlyTransactionalClientSelfTest extends GridCommonAbstract
CacheConfiguration cc = new CacheConfiguration();
+ cc.setName(CACHE_NAME);
cc.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cc.setCacheStoreFactory(factory);
@@ -100,7 +106,7 @@ public class CacheReadOnlyTransactionalClientSelfTest extends GridCommonAbstract
Ignite ignite = startGrid();
- IgniteCache cache = ignite.cache(null);
+ IgniteCache cache = ignite.cache(CACHE_NAME);
cache.get(0);
cache.getAll(F.asSet(0, 1));
@@ -140,6 +146,25 @@ public class CacheReadOnlyTransactionalClientSelfTest extends GridCommonAbstract
/**
* @throws Exception If failed.
*/
+ public void testDisabledConsistencyCheck() throws Exception {
+ client = false;
+ nearEnabled = false;
+ factory = new Factory2();
+
+ System.setProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK, "true");
+
+ startGrid("client-1");
+
+ factory = new Factory1();
+
+ System.clearProperty(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK);
+
+ startGrid("client-2");
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
public void testNoStoreNearDisabled() throws Exception {
nearEnabled = false;
@@ -164,7 +189,7 @@ public class CacheReadOnlyTransactionalClientSelfTest extends GridCommonAbstract
Ignite ignite = startGrid();
- IgniteCache cache = ignite.cache(null);
+ IgniteCache cache = ignite.cache(CACHE_NAME);
cache.get(0);
cache.getAll(F.asSet(0, 1));
@@ -173,91 +198,104 @@ public class CacheReadOnlyTransactionalClientSelfTest extends GridCommonAbstract
cache.getAndPut(0, 0);
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.getAndPutIfAbsent(0, 0);
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.getAndRemove(0);
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.getAndReplace(0, 0);
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.put(0, 0);
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.putAll(F.asMap(0, 0, 1, 1));
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.putIfAbsent(0, 0);
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.remove(0);
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.remove(0, 0);
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.removeAll(F.asSet(0, 1));
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.removeAll();
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.invoke(0, new EP());
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
try {
cache.invokeAll(F.asSet(0, 1), new EP());
}
catch (CacheException e) {
- assertEquals("Updates are not allowed for cache: null", e.getMessage());
+ assert e.getMessage().startsWith("Updates are not allowed for transactional cache: " + CACHE_NAME + ".") :
+ e.getMessage();
}
}