ignite-446
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/0e86840b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/0e86840b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/0e86840b Branch: refs/heads/ignite-646 Commit: 0e86840b863ad0c111b3131840ac4556e923df95 Parents: 02b2511 Author: avinogradov <avinogra...@gridgain.com> Authored: Mon Apr 20 18:32:13 2015 +0300 Committer: avinogradov <avinogra...@gridgain.com> Committed: Mon Apr 20 18:32:13 2015 +0300 ---------------------------------------------------------------------- .../dht/atomic/GridNearAtomicUpdateFuture.java | 2 +- .../colocated/GridDhtColocatedLockFuture.java | 2 +- .../distributed/near/GridNearLockFuture.java | 2 +- .../near/GridNearTxPrepareFuture.java | 23 +++- ...gniteTopologyValidatorAbstractCacheTest.java | 125 +++++++++++++++---- ...iteTopologyValidatorAbstractTxCacheTest.java | 45 ++++++- 6 files changed, 162 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e86840b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java index 8ca1314..b6376f6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java @@ -416,7 +416,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object> GridDhtTopologyFuture fut = cctx.topologyVersionFuture(); if (fut.isDone()) { - if (!fut.isCacheTopologyValid(cctx)) { + if (!fut.isCacheTopologyValid(cctx)) { onDone(new IgniteCheckedException("Failed to perform cache operation (cache topology is not valid): " + cctx.name())); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e86840b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java index fdb9505..c6746ba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java @@ -561,7 +561,7 @@ public final class GridDhtColocatedLockFuture<K, V> extends GridCompoundIdentity GridDhtTopologyFuture fut = cctx.topologyVersionFuture(); if (fut.isDone()) { - if (!fut.isCacheTopologyValid(cctx)) { + if (!fut.isCacheTopologyValid(cctx)) { onDone(new IgniteCheckedException("Failed to perform cache operation (cache topology is not valid): " + cctx.name())); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e86840b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java index 39820b6..58b7c4d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java @@ -693,7 +693,7 @@ public final class GridNearLockFuture<K, V> extends GridCompoundIdentityFuture<B GridDhtTopologyFuture fut = cctx.topologyVersionFuture(); if (fut.isDone()) { - if (!fut.isCacheTopologyValid(cctx)) { + if (!fut.isCacheTopologyValid(cctx)) { onDone(new IgniteCheckedException("Failed to perform cache operation (cache topology is not valid): " + cctx.name())); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e86840b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java index 20330f6..f573187 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareFuture.java @@ -341,14 +341,25 @@ public final class GridNearTxPrepareFuture<K, V> extends GridCompoundIdentityFut } if (topFut.isDone()) { - for (GridCacheContext ctx : cctx.cacheContexts()){ - if (!topFut.isCacheTopologyValid(ctx)) { - onDone(new IgniteCheckedException("Failed to perform cache operation (cache topology is not valid): " + - ctx.name())); + StringBuilder invalidCaches = new StringBuilder(); + Boolean cacheInvalid = false; + for (GridCacheContext ctx : cctx.cacheContexts()) { + if (tx.activeCacheIds().contains(ctx.cacheId()) && !topFut.isCacheTopologyValid(ctx)) { + if (cacheInvalid) + invalidCaches.append(", "); - return; + invalidCaches.append(U.maskName(ctx.name())); + + cacheInvalid = true; } - } + } + + if (cacheInvalid) { + onDone(new IgniteCheckedException("Failed to perform cache operation (cache topology is not valid): " + + invalidCaches.toString())); + + return; + } tx.topologyVersion(topFut.topologyVersion()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e86840b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java index 55e3c1b..167c535 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractCacheTest.java @@ -27,12 +27,18 @@ import java.io.*; import java.util.*; /** - * Topology validator test + * Topology validator test. */ public abstract class IgniteTopologyValidatorAbstractCacheTest extends IgniteCacheAbstractTest implements Serializable { - /** key-value used at test */ + /** key-value used at test. */ protected static String KEY_VALUE = "1"; + /** cache name 1. */ + protected static String CACHE_NAME_1 = "cache1"; + + /** cache name 2. */ + protected static String CACHE_NAME_2 = "cache2"; + /** {@inheritDoc} */ @Override protected int gridCount() { return 1; @@ -42,60 +48,133 @@ public abstract class IgniteTopologyValidatorAbstractCacheTest extends IgniteCac @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration iCfg = super.getConfiguration(gridName); + CacheConfiguration cCfg0 = cacheConfiguration(gridName); + + CacheConfiguration cCfg1 = cacheConfiguration(gridName); + cCfg1.setName(CACHE_NAME_1); + + CacheConfiguration cCfg2 = cacheConfiguration(gridName); + cCfg2.setName(CACHE_NAME_2); + + iCfg.setCacheConfiguration(cCfg0, cCfg1, cCfg2); + for (CacheConfiguration cCfg : iCfg.getCacheConfiguration()) { - cCfg.setTopologyValidator(new TopologyValidator() { - @Override public boolean validate(Collection<ClusterNode> nodes) { - return nodes.size() >= 2; - } - }); + if (cCfg.getName() != null) + if (cCfg.getName().equals(CACHE_NAME_1)) + cCfg.setTopologyValidator(new TopologyValidator() { + @Override public boolean validate(Collection<ClusterNode> nodes) { + return nodes.size() == 2; + } + }); + else if (cCfg.getName().equals(CACHE_NAME_2)) + cCfg.setTopologyValidator(new TopologyValidator() { + @Override public boolean validate(Collection<ClusterNode> nodes) { + return nodes.size() >= 2; + } + }); } return iCfg; } /** - * Puts before topology is valid. + * Puts when topology is invalid. + * + * @param cacheName cache name. */ - protected void putBefore(Transaction tx) { + protected void putInvalid(String cacheName) { try { - jcache().put(KEY_VALUE, KEY_VALUE); + assert grid(0).cache(cacheName).get(KEY_VALUE) == null; - if (tx != null) - tx.commit(); + grid(0).cache(cacheName).put(KEY_VALUE, KEY_VALUE); assert false : "topology validation broken"; } catch (IgniteException | CacheException ex) { - assert ex.getCause() instanceof IgniteCheckedException && ex.getCause().getMessage().contains("cache topology is not valid"); + assert ex.getCause() instanceof IgniteCheckedException && + ex.getCause().getMessage().contains("cache topology is not valid"); } } /** * Puts when topology is valid. + * + * @param cacheName cache name. */ - protected void putAfter(Transaction tx) { + protected void putValid(String cacheName) { try { - assert jcache().get(KEY_VALUE) == null; + assert grid(0).cache(cacheName).get(KEY_VALUE) == null; - jcache().put(KEY_VALUE, KEY_VALUE); + grid(0).cache(cacheName).put(KEY_VALUE, KEY_VALUE); - if (tx != null) - tx.commit(); - - assert jcache().get(KEY_VALUE).equals(KEY_VALUE); + assert grid(0).cache(cacheName).get(KEY_VALUE).equals(KEY_VALUE); } catch (IgniteException | CacheException ex) { assert false : "topology validation broken"; } } - /** topology validator test */ + /** + * Commits with error. + * @param tx transaction. + */ + protected void commitFailed(Transaction tx) { + try { + tx.commit(); + } + catch (IgniteException | CacheException ex) { + assert ex.getCause() instanceof IgniteCheckedException && + ex.getCause().getMessage().contains("cache topology is not valid"); + } + } + + /** + * Removes key-value + * + * @param cacheName cache name. + */ + public void remove(String cacheName) { + grid(0).cache(cacheName).remove(KEY_VALUE); + } + + /** + * Asserts that cache doesn't contains key. + * + * @param cacheName + */ + public void assertEmpty(String cacheName) { + assert grid(0).cache(cacheName).get(KEY_VALUE) == null; + } + + /** topology validator test. */ public void testTopologyValidator() throws Exception { - putBefore(null); + putValid(null); + remove(null); + + putInvalid(CACHE_NAME_1); + + putInvalid(CACHE_NAME_2); startGrid(1); - putAfter(null); + putValid(null); + remove(null); + + putValid(CACHE_NAME_1); + remove(CACHE_NAME_1); + + putValid(CACHE_NAME_2); + remove(CACHE_NAME_2); + + startGrid(2); + + putValid(null); + remove(null); + + putInvalid(CACHE_NAME_1); + + putValid(CACHE_NAME_2); + remove(CACHE_NAME_2); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e86840b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractTxCacheTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractTxCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractTxCacheTest.java index eee4d5e..3db22d3 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractTxCacheTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorAbstractTxCacheTest.java @@ -42,23 +42,58 @@ public abstract class IgniteTopologyValidatorAbstractTxCacheTest extends IgniteT @Override public void testTopologyValidator() throws Exception { try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.REPEATABLE_READ)) { - putBefore(tx); + putValid(CACHE_NAME_1); + commitFailed(tx); } try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { - putBefore(tx); + putInvalid(CACHE_NAME_1); } + try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.REPEATABLE_READ)) { + putValid(CACHE_NAME_1); + putValid(null); + putValid(CACHE_NAME_2); + commitFailed(tx); + } + + assertEmpty(null); // rolled back + assertEmpty(CACHE_NAME_1); // rolled back + +// try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { +// putValid(null); +// putInvalid(CACHE_NAME_1); +// } +// +// assertEmpty(null); // rolled back +// assertEmpty(CACHE_NAME_1); // rolled back + + startGrid(1); try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.REPEATABLE_READ)) { - putAfter(tx); + putValid(CACHE_NAME_1); + tx.commit(); + } + + remove(CACHE_NAME_1); + + try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { + putValid(CACHE_NAME_1); + tx.commit(); } - jcache().remove(KEY_VALUE); + remove(CACHE_NAME_1); + + startGrid(2); + + try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.REPEATABLE_READ)) { + putValid(CACHE_NAME_1); + commitFailed(tx); + } try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { - putAfter(tx); + putInvalid(CACHE_NAME_1); } }