Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3E050188FD for ; Sat, 6 Jun 2015 00:30:05 +0000 (UTC) Received: (qmail 44471 invoked by uid 500); 6 Jun 2015 00:30:05 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 44442 invoked by uid 500); 6 Jun 2015 00:30:05 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 44433 invoked by uid 99); 6 Jun 2015 00:30:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Jun 2015 00:30:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 06 Jun 2015 00:27:52 +0000 Received: (qmail 43363 invoked by uid 99); 6 Jun 2015 00:29:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Jun 2015 00:29:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CC92AE10A7; Sat, 6 Jun 2015 00:29:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vkulichenko@apache.org To: commits@ignite.incubator.apache.org Date: Sat, 06 Jun 2015 00:29:41 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [4/5] incubator-ignite git commit: IGNITE-941 - Read-only mode for transactional cache X-Virus-Checked: Checked by ClamAV on apache.org 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-sprint-5 Commit: b4d19159a76559152435946d1fff421679712599 Parents: b58c892 Author: Valentin Kulichenko Authored: Thu Jun 4 18:08:35 2015 -0700 Committer: Valentin Kulichenko 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.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(); } }