This is an automated email from the ASF dual-hosted git repository.

nreich pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 45312b9  GEODE-4621: Schedule scans only if list is above max eviction 
attempt… (#1408)
45312b9 is described below

commit 45312b9a06805875f6cf816d40729a0430d7f4ff
Author: Nick Reich <nre...@pivotal.io>
AuthorDate: Wed Feb 7 18:08:06 2018 -0800

    GEODE-4621: Schedule scans only if list is above max eviction attempt… 
(#1408)
    
    
      * The number of eviction attempts can now be configured at list creation
        to enable testability.
---
 .../cache/eviction/LRUListWithAsyncSorting.java    | 14 +++++---
 .../geode/internal/cache/OplogJUnitTest.java       |  2 --
 .../eviction/LRUListWithAsyncSortingTest.java      | 40 +++++++++++++++-------
 .../eviction/TestLRUListWithAsyncSorting.java      |  2 +-
 4 files changed, 38 insertions(+), 20 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/cache/eviction/LRUListWithAsyncSorting.java
 
b/geode-core/src/main/java/org/apache/geode/internal/cache/eviction/LRUListWithAsyncSorting.java
index 2762208..bc15355 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/cache/eviction/LRUListWithAsyncSorting.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/cache/eviction/LRUListWithAsyncSorting.java
@@ -55,11 +55,12 @@ public class LRUListWithAsyncSorting extends 
AbstractEvictionList {
 
   private static final int DEFAULT_EVICTION_SCAN_THRESHOLD_PERCENT = 25;
 
-  private static final int MAX_EVICTION_ATTEMPTS = 10;
+  private static final int DEFAULT_MAX_EVICTION_ATTEMPTS = 10;
 
   private final AtomicInteger recentlyUsedCounter = new AtomicInteger();
 
   private final double scanThreshold;
+  private final int maxEvictionAttempts;
 
   private Future<?> currentScan;
 
@@ -86,13 +87,15 @@ public class LRUListWithAsyncSorting extends 
AbstractEvictionList {
   }
 
   LRUListWithAsyncSorting(EvictionController controller) {
-    this(controller, SINGLETON_EXECUTOR);
+    this(controller, SINGLETON_EXECUTOR, DEFAULT_MAX_EVICTION_ATTEMPTS);
   }
 
-  LRUListWithAsyncSorting(EvictionController controller, ExecutorService 
executor) {
+  LRUListWithAsyncSorting(EvictionController controller, ExecutorService 
executor,
+      int maxEvictionAttempts) {
     super(controller);
     this.scanThreshold = calculateScanThreshold();
     this.executor = executor;
+    this.maxEvictionAttempts = maxEvictionAttempts;
   }
 
   private double calculateScanThreshold() {
@@ -136,7 +139,7 @@ public class LRUListWithAsyncSorting extends 
AbstractEvictionList {
         continue;
       }
 
-      if (evictionNode.isRecentlyUsed() && evictionAttempts < 
MAX_EVICTION_ATTEMPTS) {
+      if (evictionNode.isRecentlyUsed() && evictionAttempts < 
maxEvictionAttempts) {
         evictionAttempts++;
         evictionNode.unsetRecentlyUsed();
         appendEntry(evictionNode);
@@ -212,7 +215,8 @@ public class LRUListWithAsyncSorting extends 
AbstractEvictionList {
   }
 
   private boolean hasThresholdBeenMet(int recentlyUsedCount) {
-    return size() > 0 && (double) recentlyUsedCount / size() >= 
this.scanThreshold;
+    return size() >= maxEvictionAttempts
+        && (double) recentlyUsedCount / size() >= this.scanThreshold;
   }
 
   private synchronized EvictionNode moveToTailAndGetNext(EvictionNode 
evictionNode) {
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/OplogJUnitTest.java 
b/geode-core/src/test/java/org/apache/geode/internal/cache/OplogJUnitTest.java
index 912cfbc..b259277 100755
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/OplogJUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/OplogJUnitTest.java
@@ -58,7 +58,6 @@ import org.apache.geode.internal.cache.Oplog.OPLOG_TYPE;
 import org.apache.geode.internal.cache.entries.AbstractDiskLRURegionEntry;
 import org.apache.geode.internal.cache.entries.DiskEntry;
 import org.apache.geode.test.dunit.ThreadUtils;
-import org.apache.geode.test.junit.categories.FlakyTest;
 import org.apache.geode.test.junit.categories.IntegrationTest;
 
 /**
@@ -1132,7 +1131,6 @@ public class OplogJUnitTest extends DiskRegionTestingBase 
{
    * An entry which is evicted to disk will have the flag already written to 
disk, appropriately set
    *
    */
-  @Category(FlakyTest.class)
   @Test
   public void testEntryAlreadyWrittenIsCorrectlyUnmarkedForOverflowOnly() 
throws Exception {
     diskProps.setPersistBackup(false);
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/LRUListWithAsyncSortingTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/LRUListWithAsyncSortingTest.java
index 6d849b1..c5f4fe4 100644
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/LRUListWithAsyncSortingTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/LRUListWithAsyncSortingTest.java
@@ -62,7 +62,7 @@ public class LRUListWithAsyncSortingTest {
 
   @Test
   public void scansOnlyWhenOverThreshold() throws Exception {
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 1);
     for (int i = 0; i < 5; i++) {
       list.appendEntry(mock(EvictionNode.class));
     }
@@ -76,7 +76,7 @@ public class LRUListWithAsyncSortingTest {
 
   @Test
   public void clearResetsRecentlyUsedCounter() throws Exception {
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 1);
     list.incrementRecentlyUsed();
     assertThat(list.getRecentlyUsedCount()).isEqualTo(1);
 
@@ -86,7 +86,7 @@ public class LRUListWithAsyncSortingTest {
 
   @Test
   public void doesNotRunScanOnEmptyList() throws Exception {
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 1);
     list.incrementRecentlyUsed();
     verifyNoMoreInteractions(executor);
   }
@@ -95,7 +95,7 @@ public class LRUListWithAsyncSortingTest {
   public void usesSystemPropertyThresholdIfSpecified() throws Exception {
     System.setProperty("geode." + 
SystemPropertyHelper.EVICTION_SCAN_THRESHOLD_PERCENT, "55");
     try {
-      LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor);
+      LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 1);
 
       list.appendEntry(mock(EvictionNode.class));
       list.appendEntry(mock(EvictionNode.class));
@@ -111,14 +111,14 @@ public class LRUListWithAsyncSortingTest {
 
   @Test
   public void evictingFromEmptyListTest() throws Exception {
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 1);
     assertThat(list.getEvictableEntry()).isNull();
     assertThat(list.size()).isZero();
   }
 
   @Test
   public void evictingFromNonEmptyListTest() throws Exception {
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 1);
     EvictionNode node = mock(EvictableEntry.class);
     list.appendEntry(node);
     assertThat(list.size()).isEqualTo(1);
@@ -131,7 +131,7 @@ public class LRUListWithAsyncSortingTest {
 
   @Test
   public void doesNotEvictNodeInTransaction() throws Exception {
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 1);
     EvictionNode nodeInTransaction = mock(EvictableEntry.class, 
"nodeInTransaction");
     when(nodeInTransaction.isInUseByTransaction()).thenReturn(true);
     EvictionNode nodeNotInTransaction = mock(EvictableEntry.class, 
"nodeNotInTransaction");
@@ -149,7 +149,7 @@ public class LRUListWithAsyncSortingTest {
 
   @Test
   public void doesNotEvictNodeThatIsEvicted() throws Exception {
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 1);
 
     EvictionNode evictedNode = mock(EvictableEntry.class);
     when(evictedNode.isEvicted()).thenReturn(true);
@@ -170,7 +170,7 @@ public class LRUListWithAsyncSortingTest {
   @Test
   public void scanUnsetsRecentlyUsedOnNode() throws Exception {
     ExecutorService realExecutor = Executors.newSingleThreadExecutor();
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
realExecutor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
realExecutor, 1);
 
     EvictionNode recentlyUsedNode = mock(EvictableEntry.class);
     when(recentlyUsedNode.previous()).thenReturn(list.head);
@@ -189,7 +189,7 @@ public class LRUListWithAsyncSortingTest {
   @Test
   public void scanEndsOnlyUpToSize() throws Exception {
     ExecutorService realExecutor = Executors.newSingleThreadExecutor();
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
realExecutor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
realExecutor, 1);
 
     EvictionNode recentlyUsedNode = mock(EvictableEntry.class);
     when(recentlyUsedNode.previous()).thenReturn(list.head);
@@ -208,7 +208,7 @@ public class LRUListWithAsyncSortingTest {
   @Test
   public void scanMovesRecentlyUsedNodeToTail() throws Exception {
     ExecutorService realExecutor = Executors.newSingleThreadExecutor();
-    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
realExecutor);
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
realExecutor, 1);
 
     EvictionNode recentlyUsedNode = mock(EvictableEntry.class, "first");
     EvictionNode secondNode = mock(EvictableEntry.class, "second");
@@ -239,7 +239,7 @@ public class LRUListWithAsyncSortingTest {
   @Test
   public void startScanIfEvictableEntryIsRecentlyUsed() throws Exception {
     List<EvictionNode> nodes = new ArrayList<>();
-    LRUListWithAsyncSorting lruEvictionList = new 
LRUListWithAsyncSorting(controller, executor);
+    LRUListWithAsyncSorting lruEvictionList = new 
LRUListWithAsyncSorting(controller, executor, 1);
     IntStream.range(0, 11).forEach(i -> {
       EvictionNode node = new LRUTestEntry(i);
       nodes.add(node);
@@ -250,4 +250,20 @@ public class LRUListWithAsyncSortingTest {
     assertThat(lruEvictionList.getEvictableEntry().isRecentlyUsed()).isTrue();
     verify(executor).submit(any(Runnable.class));
   }
+
+  @Test
+  public void scanNotStartedIfSizeBelowMaxEvictionAttempts() {
+    LRUListWithAsyncSorting list = new LRUListWithAsyncSorting(controller, 
executor, 2);
+
+    EvictionNode recentlyUsedNode = mock(EvictableEntry.class, "first");
+    EvictionNode secondNode = mock(EvictableEntry.class, "second");
+
+    list.appendEntry(recentlyUsedNode);
+    list.incrementRecentlyUsed();
+    verifyNoMoreInteractions(executor);
+
+    list.appendEntry(secondNode);
+    list.incrementRecentlyUsed();
+    verify(executor).submit(any(Runnable.class));
+  }
 }
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/TestLRUListWithAsyncSorting.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/TestLRUListWithAsyncSorting.java
index c6e27f5..1c7a08b 100644
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/TestLRUListWithAsyncSorting.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/TestLRUListWithAsyncSorting.java
@@ -25,6 +25,6 @@ import 
org.apache.geode.internal.cache.LRUClearWithDiskRegionOpRegressionTest;
 public class TestLRUListWithAsyncSorting extends LRUListWithAsyncSorting {
 
   public TestLRUListWithAsyncSorting(EvictionController controller) {
-    super(controller, Executors.newSingleThreadExecutor());
+    super(controller, Executors.newSingleThreadExecutor(), 1);
   }
 }

-- 
To stop receiving notification emails like this one, please contact
nre...@apache.org.

Reply via email to