ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [10/10] incubator-ignite git commit: ignite-937 RandomEvictionPolicy calculates cache size incorrectly
Date Thu, 28 May 2015 10:50:51 GMT
ignite-937 RandomEvictionPolicy calculates cache size incorrectly


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/08816f86
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/08816f86
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/08816f86

Branch: refs/heads/ignite-937
Commit: 08816f869b0b3b9154b04fb65c1edb3177d3b5ed
Parents: b6fc8a9
Author: agura <agura@gridgain.com>
Authored: Wed May 27 16:28:02 2015 +0300
Committer: agura <agura@gridgain.com>
Committed: Thu May 28 13:21:19 2015 +0300

----------------------------------------------------------------------
 .../ignite/cache/eviction/random/RandomEvictionPolicy.java  | 9 +++++----
 .../random/RandomEvictionPolicyCacheSizeSelfTest.java       | 6 ++++++
 2 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/08816f86/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
index c88b31d..df82612 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.cache.eviction.random;
 
 import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.eviction.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -87,13 +88,13 @@ public class RandomEvictionPolicy<K, V> implements EvictionPolicy<K,
V>, RandomE
 
         IgniteCache<K, V> cache = entry.unwrap(IgniteCache.class);
 
-        int size = cache.size();
+        int size = cache.localSize(CachePeekMode.ONHEAP);
 
-        for (int i = max; i < size; i++) {
+        for (int i = max; i < size;) {
             Cache.Entry<K, V> e = cache.randomEntry();
 
-            if (e != null)
-                e.unwrap(EvictableEntry.class).evict();
+            if (e != null && e.unwrap(EvictableEntry.class).evict())
+                i++;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/08816f86/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java
index e9e7228..2a2004e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicyCacheSizeSelfTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.cache.eviction.random;
 
 import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.eviction.random.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.testframework.junits.common.*;
@@ -50,6 +51,7 @@ public class RandomEvictionPolicyCacheSizeSelfTest extends GridCommonAbstractTes
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
         CacheConfiguration ccfg = defaultCacheConfiguration();
+        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
         ccfg.setNearConfiguration(null);
         ccfg.setEvictionPolicy(new RandomEvictionPolicy(PLC_MAX_SIZE));
 
@@ -67,6 +69,10 @@ public class RandomEvictionPolicyCacheSizeSelfTest extends GridCommonAbstractTes
         for (int i = 0; i < KEYS_CNT; i++)
             cache.put(i, i);
 
+        // Ensure that all entries accessed without data races and cache size will correct
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.get(i);
+
         assertEquals(PLC_MAX_SIZE * GRID_CNT, cache.size());
     }
 }


Mime
View raw message