Skip to content

Commit

Permalink
fixes #938 made tx info cache configurable (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth authored and keith-turner committed Oct 19, 2017
1 parent c737df6 commit 650f044
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package org.apache.fluo.core.impl;

import java.util.concurrent.TimeUnit;

import org.apache.fluo.api.config.FluoConfiguration;

/**
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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.