fixes #938 made tx info cache configurable (#941)
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 3e5ee85..febb318 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 @@
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 ed43be2..ddd4900 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 @@
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 @@
cache.put(key, txInfo);
}
}
-
return txInfo;
}
}