You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2017/08/31 00:49:25 UTC
[2/3] geode git commit: added doWithNowSet
added doWithNowSet
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/87621249
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/87621249
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/87621249
Branch: refs/heads/feature/GEODE-3543
Commit: 87621249ce706363caa9d2b6732b33b9bc42fc11
Parents: 127ddfe
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Wed Aug 30 16:55:17 2017 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Wed Aug 30 16:55:17 2017 -0700
----------------------------------------------------------------------
.../apache/geode/internal/cache/ExpiryTask.java | 50 +++++++++-----------
.../geode/internal/cache/LocalRegion.java | 12 ++---
.../apache/geode/cache30/RegionTestCase.java | 2 +-
3 files changed, 29 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/87621249/geode-core/src/main/java/org/apache/geode/internal/cache/ExpiryTask.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ExpiryTask.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ExpiryTask.java
index 226f02e..129688f 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ExpiryTask.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/ExpiryTask.java
@@ -456,39 +456,21 @@ public abstract class ExpiryTask extends SystemTimer.SystemTimerTask {
private static final ThreadLocal<Long> now = new ThreadLocal<Long>();
/**
- * To reduce the number of times we need to call System.currentTimeMillis you can call this method
- * to set a thread local. Make sure and call {@link #clearNow()} in a finally block after calling
- * this method.
+ * To reduce the number of times we need to call calculateNow, you can call this method
+ * to set now in a thread local. When the run returns the thread local is cleared.
*/
- public static void setNow(LocalRegion lr) {
+ static void doWithNowSet(LocalRegion lr, Runnable runnable) {
now.set(calculateNow(lr.getCache()));
- }
-
- public long calculateNow() {
- return calculateNow(getLocalRegion().getCache());
- }
- public static long calculateNow(InternalCache cache) {
- if (cache != null) {
- // Use cache.cacheTimeMillis here. See bug 52267.
- InternalDistributedSystem ids = cache.getInternalDistributedSystem();
- if (ids != null) {
- return ids.getClock().cacheTimeMillis();
- }
+ try {
+ runnable.run();
+ } finally {
+ now.remove();
}
- return 0L;
}
/**
- * Call this method after a thread has called {@link #setNow()} once you are done calling code
- * that may call {@link #getNow(LocalRegion)}.
- */
- public static void clearNow() {
- now.remove();
- }
-
- /**
- * Returns the current time in milliseconds. If the current thread has called {@link #setNow(LocalRegion)}
- * then that time is return.
+ * Returns the current time in milliseconds. If the current thread has set the now thread local
+ * then that time is return. Otherwise now is calculated and returned.
*
* @return the current time in milliseconds
*/
@@ -503,6 +485,20 @@ public abstract class ExpiryTask extends SystemTimer.SystemTimerTask {
return result;
}
+ public long calculateNow() {
+ return calculateNow(getLocalRegion().getCache());
+ }
+ public static long calculateNow(InternalCache cache) {
+ if (cache != null) {
+ // Use cache.cacheTimeMillis here. See bug 52267.
+ InternalDistributedSystem ids = cache.getInternalDistributedSystem();
+ if (ids != null) {
+ return ids.getClock().cacheTimeMillis();
+ }
+ }
+ return 0L;
+ }
+
// Should only be set by unit tests
public static ExpiryTaskListener expiryTaskListener;
http://git-wip-us.apache.org/repos/asf/geode/blob/87621249/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index 9a3e425..47ce7e0 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -7746,19 +7746,17 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
if (!isInitialized()) {
return; // don't schedule expiration until region is initialized (bug
}
+ if (!isEntryExpiryPossible()) {
+ return;
+ }
// OK to ignore transaction since Expiry only done non-tran
Iterator<RegionEntry> it = this.entries.regionEntries().iterator();
if (it.hasNext()) {
- try {
- if (isEntryExpiryPossible()) {
- ExpiryTask.setNow(this);
- }
+ ExpiryTask.doWithNowSet(this, () -> {
while (it.hasNext()) {
addExpiryTask(it.next());
}
- } finally {
- ExpiryTask.clearNow();
- }
+ });
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/87621249/geode-core/src/test/java/org/apache/geode/cache30/RegionTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/RegionTestCase.java b/geode-core/src/test/java/org/apache/geode/cache30/RegionTestCase.java
index 525c793..f086125 100644
--- a/geode-core/src/test/java/org/apache/geode/cache30/RegionTestCase.java
+++ b/geode-core/src/test/java/org/apache/geode/cache30/RegionTestCase.java
@@ -3480,7 +3480,7 @@ public abstract class RegionTestCase extends JUnit4CacheTestCase {
// ignore
}
Date ttlTime = new Date(et.getTTLExpirationTime());
- Date getNow = new Date(ExpiryTask.calculateNow(getCache()));
+ Date getNow = new Date(et.calculateNow());
Date scheduleETime = new Date(et.scheduledExecutionTime());
getCache().getLogger()
.info(callback + " now: " + getCurrentTimeStamp(now) + " ttl:" + getCurrentTimeStamp(ttl)