# sprint-2 Changed NearCacheEntry.valid() to check if primary node changed
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/905b67b6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/905b67b6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/905b67b6 Branch: refs/heads/ignite-release-test-no-mod Commit: 905b67b6e1a9c5a1d55da7383835c4aaf7b0f0d0 Parents: 2fa0c9d Author: sboikov <sboi...@gridgain.com> Authored: Wed Mar 25 10:53:29 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Wed Mar 25 10:53:29 2015 +0300 ---------------------------------------------------------------------- .../distributed/near/GridNearCacheEntry.java | 42 +++++++++++++++++++- ...cheNearUpdateTopologyChangeAbstractTest.java | 9 +++++ 2 files changed, 50 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/905b67b6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java index 529d756..1d0add9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java @@ -93,7 +93,47 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { @Override public boolean valid(AffinityTopologyVersion topVer) { assert topVer.topologyVersion() > 0 : "Topology version is invalid: " + topVer; - return this.topVer == topVer.topologyVersion(); + long topVer0 = this.topVer; + + if (topVer0 == topVer.topologyVersion()) + return true; + + if (topVer0 == -1L || topVer.topologyVersion() < topVer0) + return false; + + try { + ClusterNode primary = null; + + for (long ver = topVer0; ver <= topVer.topologyVersion(); ver++) { + ClusterNode primary0 = cctx.affinity().primary(part, new AffinityTopologyVersion(ver)); + + if (primary0 == null) { + this.topVer = -1L; + + return false; + } + + if (primary == null) + primary = primary0; + else { + if (!primary.equals(primary0)) { + this.topVer = -1L; + + return false; + } + } + } + + this.topVer = topVer.topologyVersion(); + + return true; + } + catch (IllegalStateException ignore) { + // Do not have affinity history. + this.topVer = -1L; + + return false; + } } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/905b67b6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java index 5adde52..809f5f0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java @@ -28,6 +28,7 @@ import org.apache.ignite.testframework.*; import java.util.*; import static org.apache.ignite.cache.CacheMode.*; +import static org.apache.ignite.cache.CachePeekMode.*; /** * @@ -70,6 +71,8 @@ public abstract class CacheNearUpdateTopologyChangeAbstractTest extends IgniteCa assertEquals((Object)1, nearCache.get(key)); + assertEquals((Object)1, nearCache.localPeek(key, ONHEAP)); + boolean gotNewPrimary = false; List<Ignite> newNodes = new ArrayList<>(); @@ -102,6 +105,8 @@ public abstract class CacheNearUpdateTopologyChangeAbstractTest extends IgniteCa break; } + else + assertEquals((Object)1, nearCache.localPeek(key, ONHEAP)); } assertTrue(gotNewPrimary); @@ -124,6 +129,10 @@ public abstract class CacheNearUpdateTopologyChangeAbstractTest extends IgniteCa assertTrue(aff.isPrimary(primaryIgnite.cluster().localNode(), key)); + assertFalse(aff.isPrimaryOrBackup(nearCache.unwrap(Ignite.class).cluster().localNode(), key)); + assertEquals((Object)2, nearCache.get(key)); + + assertEquals((Object)2, nearCache.localPeek(key, ONHEAP)); } }