You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nr...@apache.org on 2018/02/06 21:01:26 UTC
[geode] branch develop updated: GEODE-4598: Make
LRUListWithAsyncSorting the default eviction list (#1387)
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 69443da GEODE-4598: Make LRUListWithAsyncSorting the default eviction list (#1387)
69443da is described below
commit 69443dadad91c1fba548c5562267938bfbe53f6a
Author: Nick Reich <nr...@pivotal.io>
AuthorDate: Tue Feb 6 13:01:23 2018 -0800
GEODE-4598: Make LRUListWithAsyncSorting the default eviction list (#1387)
---
.../cache/eviction/EvictionListBuilder.java | 10 ++-
.../cache/eviction/LRUListWithAsyncSorting.java | 1 -
.../geode/internal/lang/SystemPropertyHelper.java | 41 ++++++-----
.../cache/eviction/EvictionListBuilderTest.java | 80 ++++++++++++++++++++++
...UnitTest.java => SystemPropertyHelperTest.java} | 43 +++++++++---
5 files changed, 144 insertions(+), 31 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/eviction/EvictionListBuilder.java b/geode-core/src/main/java/org/apache/geode/internal/cache/eviction/EvictionListBuilder.java
index 4186974..a2f0563 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/eviction/EvictionListBuilder.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/eviction/EvictionListBuilder.java
@@ -14,24 +14,28 @@
*/
package org.apache.geode.internal.cache.eviction;
+import java.util.Optional;
+
import org.apache.geode.internal.lang.SystemPropertyHelper;
public class EvictionListBuilder {
- private final boolean EVICTION_SCAN_ASYNC =
- SystemPropertyHelper.getProductBooleanProperty(SystemPropertyHelper.EVICTION_SCAN_ASYNC);
+ private final boolean evictionScanAsync;
private final EvictionController controller;
public EvictionListBuilder(EvictionController evictionController) {
this.controller = evictionController;
+ Optional<Boolean> asyncScan =
+ SystemPropertyHelper.getProductBooleanProperty(SystemPropertyHelper.EVICTION_SCAN_ASYNC);
+ evictionScanAsync = asyncScan.orElse(true);
}
public EvictionList create() {
if (this.controller.getEvictionAlgorithm().isLIFO()) {
return new LIFOList(this.controller);
} else {
- if (EVICTION_SCAN_ASYNC) {
+ if (evictionScanAsync) {
return new LRUListWithAsyncSorting(this.controller);
} else {
return new LRUListWithSyncSorting(this.controller);
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 3011712..2762208 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
@@ -87,7 +87,6 @@ public class LRUListWithAsyncSorting extends AbstractEvictionList {
LRUListWithAsyncSorting(EvictionController controller) {
this(controller, SINGLETON_EXECUTOR);
- logger.info("Using experimental LRUListWithAsyncSorting");
}
LRUListWithAsyncSorting(EvictionController controller, ExecutorService executor) {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/lang/SystemPropertyHelper.java b/geode-core/src/main/java/org/apache/geode/internal/lang/SystemPropertyHelper.java
index 448ab21..b26ff08 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/lang/SystemPropertyHelper.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/lang/SystemPropertyHelper.java
@@ -16,8 +16,6 @@ package org.apache.geode.internal.lang;
import java.util.Optional;
-import org.apache.geode.annotations.Experimental;
-
/**
* The SystemPropertyHelper class is an helper class for accessing system properties used in geode.
* The method name to get the system property should be the same as the system property name.
@@ -31,22 +29,20 @@ public class SystemPropertyHelper {
/**
- * Setting this to "true" enables a new asynchronous eviction algorithm. For more details see
- * {@link org.apache.geode.internal.cache.eviction.LRUListWithSyncSorting}.
+ * When set to "true" enables asynchronous eviction algorithm (defaults to true). For more details
+ * see {@link org.apache.geode.internal.cache.eviction.LRUListWithAsyncSorting}.
*
* @since Geode 1.4.0
*/
- @Experimental
public static final String EVICTION_SCAN_ASYNC = "EvictionScanAsync";
/**
* This property allows the maximum number of threads used for asynchronous eviction scanning to
* be configured. It defaults to "Math.max((Runtime.getRuntime().availableProcessors() / 4), 1)".
- * For more details see {@link org.apache.geode.internal.cache.eviction.LRUListWithSyncSorting}.
+ * For more details see {@link org.apache.geode.internal.cache.eviction.LRUListWithAsyncSorting}.
*
* @since Geode 1.4.0
*/
- @Experimental
public static final String EVICTION_SCAN_MAX_THREADS = "EvictionScanMaxThreads";
/**
@@ -54,11 +50,10 @@ public class SystemPropertyHelper {
* started. If the number of entries that have been recently used since the previous scan divided
* by total number of entries exceeds the threshold then a scan is started. The default threshold
* is 25. If the threshold is less than 0 or greater than 100 then the default threshold is used.
- * For more details see {@link org.apache.geode.internal.cache.eviction.LRUListWithSyncSorting}.
+ * For more details see {@link org.apache.geode.internal.cache.eviction.LRUListWithAsyncSorting}.
*
* @since Geode 1.4.0
*/
- @Experimental
public static final String EVICTION_SCAN_THRESHOLD_PERCENT = "EvictionScanThresholdPercent";
public static final String EVICTION_SEARCH_MAX_ENTRIES = "lru.maxSearchEntries";
@@ -68,14 +63,11 @@ public class SystemPropertyHelper {
* will check and prefer "geode." setting first, then try to check "gemfire." setting.
*
* @param name system property name set in Geode
- * @return a boolean value of the system property
+ * @return an Optional containing the Boolean value of the system property
*/
- public static boolean getProductBooleanProperty(String name) {
- String property = System.getProperty(GEODE_PREFIX + name);
- if (property != null) {
- return Boolean.getBoolean(GEODE_PREFIX + name);
- }
- return Boolean.getBoolean(GEMFIRE_PREFIX + name);
+ public static Optional<Boolean> getProductBooleanProperty(String name) {
+ String property = getProperty(name);
+ return property != null ? Optional.of(Boolean.parseBoolean(property)) : Optional.empty();
}
public static Optional<Integer> getProductIntegerProperty(String name) {
@@ -91,6 +83,19 @@ public class SystemPropertyHelper {
}
}
+ private static String getProperty(String name) {
+ String property = getGeodeProperty(name);
+ return property != null ? property : getGemfireProperty(name);
+ }
+
+ private static String getGeodeProperty(String name) {
+ return System.getProperty(GEODE_PREFIX + name);
+ }
+
+ private static String getGemfireProperty(String name) {
+ return System.getProperty(GEMFIRE_PREFIX + name);
+ }
+
/**
* As of Geode 1.4.0, a region set operation will be in a transaction even if it is the first
* operation in the transaction.
@@ -103,7 +108,7 @@ public class SystemPropertyHelper {
* @since Geode 1.4.0
*/
public static boolean restoreSetOperationTransactionBehavior() {
- return getProductBooleanProperty("restoreSetOperationTransactionBehavior");
+ return getProductBooleanProperty("restoreSetOperationTransactionBehavior").orElse(false);
}
/**
@@ -116,6 +121,6 @@ public class SystemPropertyHelper {
* @since Geode 1.4.0
*/
public static boolean restoreIdleExpirationBehavior() {
- return getProductBooleanProperty("restoreIdleExpirationBehavior");
+ return getProductBooleanProperty("restoreIdleExpirationBehavior").orElse(false);
}
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/EvictionListBuilderTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/EvictionListBuilderTest.java
new file mode 100644
index 0000000..7def3f6
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/eviction/EvictionListBuilderTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.eviction;
+
+import static org.apache.geode.internal.lang.SystemPropertyHelper.EVICTION_SCAN_ASYNC;
+import static org.assertj.core.api.Assertions.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.ClearSystemProperties;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.EvictionAlgorithm;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class EvictionListBuilderTest {
+ private static final String EVICTION_PROPERTY_NAME = "geode." + EVICTION_SCAN_ASYNC;
+
+ @Rule
+ public ClearSystemProperties clearProperties = new ClearSystemProperties(EVICTION_PROPERTY_NAME);
+
+ private EvictionListBuilder builder;
+ private EvictionController controller;
+ private EvictionAlgorithm algorithm;
+
+ @Before
+ public void setup() {
+ controller = mock(EvictionController.class);
+ builder = new EvictionListBuilder(controller);
+ algorithm = EvictionAlgorithm.LRU_ENTRY;
+ when(controller.getEvictionAlgorithm()).thenReturn(algorithm);
+ }
+
+ @Test
+ public void createsLIFOListWhenAlgorithmIsLifo() {
+ EvictionAlgorithm lifoAlgorithm = EvictionAlgorithm.LIFO_ENTRY;
+ when(controller.getEvictionAlgorithm()).thenReturn(lifoAlgorithm);
+
+ assertThat(builder.create()).isInstanceOf(LIFOList.class);
+ }
+
+ @Test
+ public void createsAsyncLruByDefault() {
+
+ assertThat(builder.create()).isInstanceOf(LRUListWithAsyncSorting.class);
+ }
+
+ @Test
+ public void createsAsyncLruWhenSystemConfiguredToUseIt() {
+ System.setProperty(EVICTION_PROPERTY_NAME, "true");
+ builder = new EvictionListBuilder(controller);
+
+ assertThat(builder.create()).isInstanceOf(LRUListWithAsyncSorting.class);
+ }
+
+ @Test
+ public void createdSyncLruWhenSystemConfiguredToUseIt() {
+ System.setProperty(EVICTION_PROPERTY_NAME, "false");
+ builder = new EvictionListBuilder(controller);
+
+ assertThat(builder.create()).isInstanceOf(LRUListWithSyncSorting.class);
+
+ }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/lang/SystemPropertyHelperJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/lang/SystemPropertyHelperTest.java
similarity index 65%
rename from geode-core/src/test/java/org/apache/geode/internal/lang/SystemPropertyHelperJUnitTest.java
rename to geode-core/src/test/java/org/apache/geode/internal/lang/SystemPropertyHelperTest.java
index 71df1db..dc3e8ce 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/lang/SystemPropertyHelperJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/lang/SystemPropertyHelperTest.java
@@ -15,8 +15,6 @@
package org.apache.geode.internal.lang;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -24,24 +22,24 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
-public class SystemPropertyHelperJUnitTest {
+public class SystemPropertyHelperTest {
private String restoreSetOperationTransactionBehavior = "restoreSetOperationTransactionBehavior";
@Test
public void testRestoreSetOperationTransactionBehaviorDefaultToFalse() {
- assertFalse(SystemPropertyHelper.restoreSetOperationTransactionBehavior());
+ assertThat(SystemPropertyHelper.restoreSetOperationTransactionBehavior()).isFalse();
}
@Test
public void testRestoreSetOperationTransactionBehaviorSystemProperty() {
String gemfirePrefixProperty = "gemfire." + restoreSetOperationTransactionBehavior;
System.setProperty(gemfirePrefixProperty, "true");
- assertTrue(SystemPropertyHelper.restoreSetOperationTransactionBehavior());
+ assertThat(SystemPropertyHelper.restoreSetOperationTransactionBehavior()).isTrue();
System.clearProperty(gemfirePrefixProperty);
String geodePrefixProperty = "geode." + restoreSetOperationTransactionBehavior;
System.setProperty(geodePrefixProperty, "true");
- assertTrue(SystemPropertyHelper.restoreSetOperationTransactionBehavior());
+ assertThat(SystemPropertyHelper.restoreSetOperationTransactionBehavior()).isTrue();
System.clearProperty(geodePrefixProperty);
}
@@ -51,7 +49,7 @@ public class SystemPropertyHelperJUnitTest {
String geodePrefixProperty = "geode." + restoreSetOperationTransactionBehavior;
System.setProperty(geodePrefixProperty, "false");
System.setProperty(gemfirePrefixProperty, "true");
- assertFalse(SystemPropertyHelper.restoreSetOperationTransactionBehavior());
+ assertThat(SystemPropertyHelper.restoreSetOperationTransactionBehavior()).isFalse();
System.clearProperty(geodePrefixProperty);
System.clearProperty(gemfirePrefixProperty);
}
@@ -78,8 +76,35 @@ public class SystemPropertyHelperJUnitTest {
}
@Test
- public void getIntegerPropertyReturnsNullIfPropertiesMissing() {
- String testProperty = "testIntegerProperty";
+ public void getIntegerPropertyReturnsEmptyOptionalIfPropertiesMissing() {
+ String testProperty = "notSetProperty";
assertThat(SystemPropertyHelper.getProductIntegerProperty(testProperty).isPresent()).isFalse();
}
+
+ @Test
+ public void getBooleanPropertyReturnsEmptyOptionalIfProperiesMissing() {
+ String testProperty = "notSetProperty";
+ assertThat(SystemPropertyHelper.getProductBooleanProperty(testProperty).isPresent()).isFalse();
+ }
+
+ @Test
+ public void getBooleanPropertyPrefersGeodePrefix() {
+ String testProperty = "testBooleanProperty";
+ String gemfirePrefixProperty = "gemfire." + testProperty;
+ String geodePrefixProperty = "geode." + testProperty;
+ System.setProperty(geodePrefixProperty, "true");
+ System.setProperty(gemfirePrefixProperty, "false");
+ assertThat(SystemPropertyHelper.getProductBooleanProperty(testProperty).get()).isTrue();
+ System.clearProperty(geodePrefixProperty);
+ System.clearProperty(gemfirePrefixProperty);
+ }
+
+ @Test
+ public void getBooleanPropertyReturnsGemfirePrefixIfGeodeMissing() {
+ String testProperty = "testBooleanProperty";
+ String gemfirePrefixProperty = "gemfire." + testProperty;
+ System.setProperty(gemfirePrefixProperty, "true");
+ assertThat(SystemPropertyHelper.getProductBooleanProperty(testProperty).get()).isTrue();
+ System.clearProperty(gemfirePrefixProperty);
+ }
}
--
To stop receiving notification emails like this one, please contact
nreich@apache.org.