You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/04/06 15:43:47 UTC
[2/2] incubator-ignite git commit: ignite-396 Batch eviction support
added to CacheFifoEvictionPolicy
ignite-396 Batch eviction support added to CacheFifoEvictionPolicy
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/25ac71b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/25ac71b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/25ac71b3
Branch: refs/heads/ignite-396
Commit: 25ac71b321dffdfab43432e0baf6a4c7f7b48e24
Parents: b41c066
Author: Andrey Gura <ag...@gridgain.com>
Authored: Mon Apr 6 16:42:42 2015 +0300
Committer: Andrey Gura <ag...@gridgain.com>
Committed: Mon Apr 6 16:42:42 2015 +0300
----------------------------------------------------------------------
.../cache/eviction/fifo/FifoEvictionPolicy.java | 10 +++++--
.../eviction/GridCacheEvictionAbstractTest.java | 5 +++-
...ridCacheFifoBatchEvictionPolicySelfTest.java | 30 ++++++++++++++------
3 files changed, 32 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25ac71b3/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java
index a938bf7..2fbc642 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java
@@ -191,9 +191,9 @@ public class FifoEvictionPolicy<K, V> implements EvictionPolicy<K, V>, FifoEvict
int startSize = queue.sizex();
- // // Shrink only if queue is full.
- if (startSize > max) {
- for (int i = 0; i < startSize && queue.sizex() > (max - batchSize + 1); i++) {
+ // Shrink only if queue is full.
+ if (startSize >= max + batchSize) {
+ for (int i = max; i < startSize && queue.sizex() > max; i++) {
EvictableEntry<K, V> entry = queue.poll();
if (entry == null)
@@ -211,11 +211,15 @@ public class FifoEvictionPolicy<K, V> implements EvictionPolicy<K, V>, FifoEvict
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(max);
+
+ out.writeInt(batchSize);
}
/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
max = in.readInt();
+
+ batchSize = in.readInt();
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25ac71b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java
index 2081bfd..e0dab7d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java
@@ -63,6 +63,9 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
/** Evict near sync. */
protected boolean evictNearSync = true;
+ /** Policy batch size. */
+ protected int plcBatchSize = 0;
+
/** Policy max. */
protected int plcMax = 10;
@@ -338,7 +341,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
int actual = colocated(i).size();
assertTrue("Cache size is greater then policy size [expected=" + endSize + ", actual=" + actual + ']',
- actual <= endSize);
+ actual <= endSize + plcBatchSize);
}
checkPolicies(endPlcSize);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/25ac71b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java
index a3c4610..7a9f4f4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java
@@ -24,7 +24,7 @@ import org.apache.ignite.internal.processors.cache.eviction.*;
import java.util.*;
-import static org.apache.ignite.cache.CacheMode.LOCAL;
+import static org.apache.ignite.cache.CacheMode.*;
/**
* FIFO batch eviction test.
@@ -46,7 +46,8 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
FifoEvictionPolicy<String, String> p = policy();
- p.setMaxSize(4);
+ p.setMaxSize(3);
+
p.setBatchSize(2);
p.onEntryAccessed(false, e1);
@@ -166,7 +167,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
p.setMaxSize(max);
p.setBatchSize(batchSize);
- int cnt = 11;
+ int cnt = max + batchSize;
for (int i = 0; i < cnt; i++)
p.onEntryAccessed(false, new MockEntry(Integer.toString(i), Integer.toString(i)));
@@ -191,8 +192,11 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
int max = 10;
+ int batchSize = 2;
+
p.setMaxSize(max);
- p.setBatchSize(2);
+
+ p.setBatchSize(batchSize);
Random rand = new Random();
@@ -222,7 +226,8 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
int curSize = p.getCurrentSize();
- assert curSize <= max : "curSize <= max [curSize=" + curSize + ", max=" + max + ']';
+ assert curSize < max + batchSize :
+ "curSize < max + batchSize [curSize=" + curSize + ", max=" + max + ", batchSize=" + batchSize + ']';
}
finally {
stopAllGrids();
@@ -312,7 +317,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
}
// Batch evicted.
- assert min >= plcMax - 1 : "Min cache size is too small: " + min;
+ assert min >= plcMax : "Min cache size is too small: " + min;
info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
info("Current cache size " + cache.size());
@@ -340,7 +345,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
info("Current cache key size " + cache.size());
// Batch evicted.
- assert min >= plcMax - 1 : "Min cache size is too small: " + min;
+ assert min >= plcMax : "Min cache size is too small: " + min;
}
finally {
stopAllGrids();
@@ -348,13 +353,20 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
}
/** {@inheritDoc} */
+ @Override public void testPartitionedNearDisabled() throws Exception {
+ plcBatchSize = 2;
+
+ super.testPartitionedNearDisabled();
+ }
+
+ /** {@inheritDoc} */
@Override protected FifoEvictionPolicy<String, String> createPolicy(int plcMax) {
return new FifoEvictionPolicy<>(10, 2);
}
/** {@inheritDoc} */
@Override protected FifoEvictionPolicy<String, String> createNearPolicy(int nearMax) {
- return new FifoEvictionPolicy<>(nearMax);
+ return new FifoEvictionPolicy<>(nearMax, 2);
}
/** {@inheritDoc} */
@@ -367,7 +379,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
/** {@inheritDoc} */
@Override protected void checkPolicies(int plcMax) {
for (int i = 0; i < gridCnt; i++)
- assert policy(i).queue().size() <= plcMax;
+ assert policy(i).queue().size() <= plcMax + policy(i).getBatchSize();
}
}