Permalink
Browse files

fixes #938 made tx info cache configurable (#941)

  • Loading branch information...
kpm1985 authored and keith-turner committed Oct 12, 2017
1 parent c737df6 commit 650f044b7db16e732cfbf32f484f05ec34837df8
@@ -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";
@@ -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;
}
}

0 comments on commit 650f044

Please sign in to comment.