keith-turner closed pull request #941: WIP: Fix for FLUO-938
URL: https://github.com/apache/fluo/pull/941
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java
 
b/modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java
index 3e5ee850..febb3183 100644
--- 
a/modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java
+++ 
b/modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java
@@ -15,6 +15,8 @@
 
 package org.apache.fluo.core.impl;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.fluo.api.config.FluoConfiguration;
 
 /**
@@ -102,6 +104,46 @@ public static int getTxCommitMemory(FluoConfiguration 
conf) {
     return m;
   }
 
+  public static final String TX_INFO_CACHE_SIZE = FLUO_IMPL_PREFIX + 
".tx.failed.cache.size.mb";
+  public static final long TX_INFO_CACHE_SIZE_DEFAULT = 10000000;
+
+  /** 
+   * Gets the cache size
+   * 
+   * @param conf The FluoConfiguration
+   * @return The size of the cache value from the property value {@value 
#TX_INFO_CACHE_SIZE}
+   *     if it is set, else the value of the default value {@value 
#TX_INFO_CACHE_SIZE_DEFAULT}
+   */
+
+  public static long getTxInfoCacheSize(FluoConfiguration conf) {
+    long size = conf.getLong(TX_INFO_CACHE_SIZE, TX_INFO_CACHE_SIZE_DEFAULT);
+    if (size <= 0) {
+      throw new IllegalArgumentException("Cache size must be positive for " + 
TX_INFO_CACHE_SIZE);
+    }
+    return size;
+  }
+
+  public static final String TX_INFO_CACHE_TIMEOUT =
+      FLUO_IMPL_PREFIX + ".tx.failed.cache.expireTime.ms";
+  public static final long TX_INFO_CACHE_TIMEOUT_DEFAULT = 24 * 60 * 1000;
+
+  /**
+   * Gets the time before stale entries in the cache are evicted based on age.
+   * This method returns a long representing the time converted from the
+   * TimeUnit passed in.
+   * 
+   * @param conf The FluoConfiguration
+   * @param tu   The TimeUnit desired to represent the cache timeout
+   */
+
+  public static long getTxIfoCacheTimeout(FluoConfiguration conf, TimeUnit tu) 
{
+    long millis = conf.getLong(TX_INFO_CACHE_TIMEOUT, 
TX_INFO_CACHE_TIMEOUT_DEFAULT);
+    if (millis <= 0) {
+      throw new IllegalArgumentException("Timeout must positive for " + 
TX_INFO_CACHE_TIMEOUT);
+    }
+    return tu.convert(millis, TimeUnit.MILLISECONDS);
+  }
+
   public static final String ASYNC_CW_THREADS = FLUO_IMPL_PREFIX + 
".async.cw.threads";
   public static final int ASYNC_CW_THREADS_DEFAULT = 8;
   public static final String ASYNC_CW_LIMIT = FLUO_IMPL_PREFIX + 
".async.cw.limit";
diff --git 
a/modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java 
b/modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java
index ed43be25..ddd49000 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java
@@ -20,6 +20,7 @@
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.Weigher;
+import org.apache.fluo.api.config.FluoConfiguration;
 import org.apache.fluo.api.data.Bytes;
 import org.apache.fluo.api.data.Column;
 
@@ -38,8 +39,12 @@ public int weigh(PrimaryRowColumn key, TxInfo value) {
   private final Environment env;
 
   TxInfoCache(Environment env) {
-    cache = CacheBuilder.newBuilder().expireAfterAccess(CACHE_TIMEOUT_MIN, 
TimeUnit.MINUTES)
-        .maximumWeight(10000000).weigher(new 
TxStatusWeigher()).concurrencyLevel(10).build();
+    final FluoConfiguration conf = env.getConfiguration();
+    cache = CacheBuilder.newBuilder()
+        .expireAfterAccess(FluoConfigurationImpl.getTxIfoCacheTimeout(conf, 
TimeUnit.MILLISECONDS),
+            TimeUnit.MILLISECONDS)
+        .maximumWeight(FluoConfigurationImpl.getTxInfoCacheSize(conf))
+        .weigher(new TxStatusWeigher()).concurrencyLevel(10).build();
     this.env = env;
   }
 
@@ -58,7 +63,6 @@ public TxInfo getTransactionInfo(PrimaryRowColumn key) {
         cache.put(key, txInfo);
       }
     }
-
     return txInfo;
   }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to