# ignite-506 Changed NearCacheEntry.valid to check topology version instead of primaryNodeId
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4ba0ddaf Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4ba0ddaf Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4ba0ddaf Branch: refs/heads/ignite-45-ipc-debug Commit: 4ba0ddaf3fcbf63ab2fd9e9df4bd3f6bacd12971 Parents: 214109f Author: sboikov <sboi...@gridgain.com> Authored: Tue Mar 24 15:01:25 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Tue Mar 24 15:01:25 2015 +0300 ---------------------------------------------------------------------- .../distributed/near/GridNearCacheEntry.java | 59 ++++++++++---------- .../dht/GridCacheAtomicNearCacheSelfTest.java | 17 +++++- .../ignite/testsuites/IgniteCacheTestSuite.java | 2 + 3 files changed, 48 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0ddaf/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 3d8a188..278251d 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 @@ -42,8 +42,8 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { /** */ private static final int NEAR_SIZE_OVERHEAD = 36; - /** ID of primary node from which this entry was last read. */ - private volatile UUID primaryNodeId; + /** Topology version at the moment when value was initialized from primary node. */ + private volatile long topVer = -1L; /** DHT version which caused the last update. */ @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") @@ -93,27 +93,18 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { @Override public boolean valid(AffinityTopologyVersion topVer) { assert topVer.topologyVersion() > 0 : "Topology version is invalid: " + topVer; - UUID primaryNodeId = this.primaryNodeId; + long topVer0 = this.topVer; - if (primaryNodeId == null) + if (topVer0 < 0) return false; - if (cctx.discovery().node(primaryNodeId) == null) { - this.primaryNodeId = null; + if (topVer.topologyVersion() != topVer0) { + this.topVer = -1L; return false; } - // Make sure that primary node is alive before returning this value. - ClusterNode primary = cctx.affinity().primary(key(), topVer); - - if (primary != null && primary.id().equals(primaryNodeId)) - return true; - - // Primary node changed. - this.primaryNodeId = null; - - return false; + return true; } /** @@ -196,7 +187,7 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { synchronized (this) { checkObsolete(); - this.primaryNodeId = primaryNodeId; + primaryNode(primaryNodeId); if (!F.eq(this.dhtVer, dhtVer)) { value(val); @@ -244,7 +235,7 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { ttlAndExpireTimeExtras((int) ttl, expireTime); - this.primaryNodeId = primaryNodeId; + primaryNode(primaryNodeId); } } } @@ -278,18 +269,11 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { } } - /** - * @return ID of primary node from which this value was loaded. - */ - UUID nodeId() { - return primaryNodeId; - } - /** {@inheritDoc} */ @Override protected void recordNodeId(UUID primaryNodeId) { assert Thread.holdsLock(this); - this.primaryNodeId = primaryNodeId; + primaryNode(primaryNodeId); } /** @@ -363,7 +347,7 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { boolean hasVal = hasValueUnlocked(); if (isNew() || !valid || expVer == null || expVer.equals(this.dhtVer)) { - this.primaryNodeId = primaryNodeId; + primaryNode(primaryNodeId); // Change entry only if dht version has changed. if (!dhtVer.equals(dhtVersion())) { @@ -601,10 +585,29 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry { /** {@inheritDoc} */ @Override protected void onInvalidate() { - primaryNodeId = null; + topVer = -1L; dhtVer = null; } + /** + * @param nodeId Primary node ID. + */ + private void primaryNode(UUID nodeId) { + assert nodeId != null; + + AffinityTopologyVersion topVer = cctx.discovery().topologyVersionEx(); + + ClusterNode primary = cctx.affinity().primary(part, topVer); + + if (primary == null || !nodeId.equals(primary.id())) { + this.topVer = -1L; + + return; + } + + this.topVer = topVer.topologyVersion(); + } + /** {@inheritDoc} */ @Override public synchronized String toString() { return S.toString(GridNearCacheEntry.class, this, "super", super.toString()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0ddaf/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java index ae49338..67f391f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java @@ -698,12 +698,18 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { GridCacheEntryEx nearEntry = near.peekEx(key); + boolean expectDht = near.affinity().isPrimaryOrBackup(ignite.cluster().localNode(), key); + if (expectNear) { assertNotNull("No near entry for: " + key + ", grid: " + ignite.name(), nearEntry); assertEquals("Unexpected value for grid: " + ignite.name(), val, CU.value(nearEntry.info().value(), near.context(), false)); + + assertEquals("Unexpected value for grid: " + ignite.name(), + val, + ignite.cache(near.name()).localPeek(key, CachePeekMode.ONHEAP)); } else assertNull("Unexpected near entry: " + nearEntry + ", grid: " + ignite.name(), nearEntry); @@ -712,8 +718,6 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { GridDhtCacheEntry dhtEntry = (GridDhtCacheEntry)dht.peekEx(key); - boolean expectDht = near.affinity().isPrimaryOrBackup(ignite.cluster().localNode(), key); - if (expectDht) { assertNotNull("No dht entry for: " + key + ", grid: " + ignite.name(), dhtEntry); @@ -727,9 +731,18 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { assertEquals("Unexpected value for grid: " + ignite.name(), val, CU.value(dhtEntry.info().value(), dht.context(), false)); + + assertEquals("Unexpected value for grid: " + ignite.name(), + val, + ignite.cache(near.name()).localPeek(key, CachePeekMode.ONHEAP)); } else assertNull("Unexpected dht entry: " + dhtEntry + ", grid: " + ignite.name(), dhtEntry); + + if (!expectNear && !expectDht) { + assertNull("Unexpected peek value for grid: " + ignite.name(), + ignite.cache(near.name()).localPeek(key, CachePeekMode.ONHEAP)); + } } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0ddaf/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index 3600fd0..2476484 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -120,6 +120,8 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTestSuite(IgniteCacheAtomicStopBusySelfTest.class); // suite.addTestSuite(IgniteCacheTransactionalStopBusySelfTest.class); TODO Ignite-257. suite.addTestSuite(GridCacheAtomicNearCacheSelfTest.class); + suite.addTestSuite(CacheAtomicNearUpdateTopologyChangeTest.class); + suite.addTestSuite(CacheTxNearUpdateTopologyChangeTest.class); suite.addTestSuite(GridCacheStorePutxSelfTest.class); suite.addTestSuite(GridCacheOffHeapMultiThreadedUpdateSelfTest.class); suite.addTestSuite(GridCacheOffHeapAtomicMultiThreadedUpdateSelfTest.class);