Skip to content

Commit 955c86f

Browse files
Kenneth McFarlandkeith-turner
authored andcommitted
fixes #939 made transactor cache configurable (#956)
1 parent c6bdbe5 commit 955c86f

4 files changed

Lines changed: 64 additions & 24 deletions

File tree

modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,21 @@ public static int getTxCommitMemory(FluoConfiguration conf) {
104104
return m;
105105
}
106106

107-
public static final String TX_INFO_CACHE_SIZE = FLUO_IMPL_PREFIX + ".tx.failed.cache.size.mb";
108-
public static final long TX_INFO_CACHE_SIZE_DEFAULT = 10_000_000;
107+
public static final String TX_INFO_CACHE_WEIGHT = FLUO_IMPL_PREFIX + ".tx.failed.cache.weight.mb";
108+
public static final long TX_INFO_CACHE_WEIGHT_DEFAULT = 10_000_000;
109109

110110
/**
111-
* Gets the cache size
111+
* Gets the txinfo cache weight
112112
*
113113
* @param conf The FluoConfiguration
114-
* @return The size of the cache value from the property value {@value #TX_INFO_CACHE_SIZE}
115-
* if it is set, else the value of the default value {@value #TX_INFO_CACHE_SIZE_DEFAULT}
114+
* @return The size of the cache value from the property value {@value #TX_INFO_CACHE_WEIGHT}
115+
* if it is set, else the value of the default value {@value #TX_INFO_CACHE_WEIGHT_DEFAULT}
116116
*/
117117

118-
public static long getTxInfoCacheSize(FluoConfiguration conf) {
119-
long size = conf.getLong(TX_INFO_CACHE_SIZE, TX_INFO_CACHE_SIZE_DEFAULT);
118+
public static long getTxInfoCacheWeight(FluoConfiguration conf) {
119+
long size = conf.getLong(TX_INFO_CACHE_WEIGHT, TX_INFO_CACHE_WEIGHT_DEFAULT);
120120
if (size <= 0) {
121-
throw new IllegalArgumentException("Cache size must be positive for " + TX_INFO_CACHE_SIZE);
121+
throw new IllegalArgumentException("Cache size must be positive for " + TX_INFO_CACHE_WEIGHT);
122122
}
123123
return size;
124124
}
@@ -144,22 +144,23 @@ public static long getTxIfoCacheTimeout(FluoConfiguration conf, TimeUnit tu) {
144144
return tu.convert(millis, TimeUnit.MILLISECONDS);
145145
}
146146

147-
public static final String VISIBILITY_CACHE_SIZE = FLUO_IMPL_PREFIX + ".visibility.cache.size.mb";
148-
public static final long VISIBILITY_CACHE_SIZE_DEFAULT = 10_000_000;
147+
public static final String VISIBILITY_CACHE_WEIGHT =
148+
FLUO_IMPL_PREFIX + ".visibility.cache.weight.mb";
149+
public static final long VISIBILITY_CACHE_WEIGHT_DEFAULT = 10_000_000;
149150

150151
/**
151-
* Gets the cache size
152+
* Gets the visibility cache weight
152153
*
153154
* @param conf The FluoConfiguration
154-
* @return The size of the cache value from the property value {@value #VISIBILITY_CACHE_SIZE}
155-
* if it is set, else the value of the default value {@value #VISIBILITY_CACHE_SIZE_DEFAULT}
155+
* @return The size of the cache value from the property value {@value #VISIBILITY_CACHE_WEIGHT}
156+
* if it is set, else the value of the default value {@value #VISIBILITY_CACHE_WEIGHT_DEFAULT}
156157
*/
157158

158-
public static long getVisibilityCacheSize(FluoConfiguration conf) {
159-
long size = conf.getLong(VISIBILITY_CACHE_SIZE, VISIBILITY_CACHE_SIZE_DEFAULT);
159+
public static long getVisibilityCacheWeight(FluoConfiguration conf) {
160+
long size = conf.getLong(VISIBILITY_CACHE_WEIGHT, VISIBILITY_CACHE_WEIGHT_DEFAULT);
160161
if (size <= 0) {
161162
throw new IllegalArgumentException(
162-
"Cache size must be positive for " + VISIBILITY_CACHE_SIZE);
163+
"Cache size must be positive for " + VISIBILITY_CACHE_WEIGHT);
163164
}
164165
return size;
165166
}
@@ -185,6 +186,41 @@ public static long getVisibilityCacheTimeout(FluoConfiguration conf, TimeUnit tu
185186
return tu.convert(millis, TimeUnit.MILLISECONDS);
186187
}
187188

189+
private static final String TRANSACTOR_MAX_CACHE_SIZE =
190+
FLUO_IMPL_PREFIX + ".transactor.cache.max.size";
191+
private static final long TRANSACTOR_MAX_CACHE_SIZE_DEFAULT = 32768; // this equals 2^15
192+
193+
/**
194+
* Gets the specified number of entries the cache can contain, this gets the value
195+
* of {@value #TRANSACTOR_MAX_CACHE_SIZE} if set, the default
196+
* {@value #TRANSACTOR_CACHE_TIMEOUT_DEFAULT} otherwise
197+
*
198+
* @param conf The FluoConfiguartion
199+
* @return The maximum number of entries permitted in this cache
200+
*/
201+
202+
public static long getTransactorMaxCacheSize(FluoConfiguration conf) {
203+
long size = conf.getLong(TRANSACTOR_MAX_CACHE_SIZE, TRANSACTOR_MAX_CACHE_SIZE_DEFAULT);
204+
if (size <= 0) {
205+
throw new IllegalArgumentException(
206+
"Cache size must be positive for " + TRANSACTOR_MAX_CACHE_SIZE);
207+
}
208+
return size;
209+
}
210+
211+
public static final String TRANSACTOR_CACHE_TIMEOUT =
212+
FLUO_IMPL_PREFIX + ".transactor.cache.expireTime.ms";
213+
214+
public static final long TRANSACTOR_CACHE_TIMEOUT_DEFAULT = 24 * 60 * 1000;
215+
216+
public static long getTransactorCacheTimeout(FluoConfiguration conf, TimeUnit tu) {
217+
long millis = conf.getLong(TRANSACTOR_CACHE_TIMEOUT, TRANSACTOR_CACHE_TIMEOUT_DEFAULT);
218+
if (millis <= 0) {
219+
throw new IllegalArgumentException("Timeout must positive for " + TRANSACTOR_CACHE_TIMEOUT);
220+
}
221+
return tu.convert(millis, TimeUnit.MILLISECONDS);
222+
}
223+
188224
public static final String ASYNC_CW_THREADS = FLUO_IMPL_PREFIX + ".async.cw.threads";
189225
public static final int ASYNC_CW_THREADS_DEFAULT = 8;
190226
public static final String ASYNC_CW_LIMIT = FLUO_IMPL_PREFIX + ".async.cw.limit";

modules/core/src/main/java/org/apache/fluo/core/impl/TransactorCache.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.curator.framework.recipes.cache.PathChildrenCache.StartMode;
2828
import org.apache.fluo.accumulo.util.LongUtil;
2929
import org.apache.fluo.accumulo.util.ZookeeperPath;
30+
import org.apache.fluo.api.config.FluoConfiguration;
3031
import org.slf4j.Logger;
3132
import org.slf4j.LoggerFactory;
3233

@@ -47,11 +48,14 @@ public enum TcStatus {
4748
private static final Logger log = LoggerFactory.getLogger(TransactorCache.class);
4849

4950
public TransactorCache(Environment env) {
50-
51-
timeoutCache = CacheBuilder.newBuilder().maximumSize(1 << 15)
52-
.expireAfterAccess(FluoConfigurationImpl.TX_INFO_CACHE_TIMEOUT_DEFAULT,
53-
TimeUnit.MILLISECONDS)
54-
.concurrencyLevel(10).build();
51+
final FluoConfiguration conf = env.getConfiguration();
52+
53+
timeoutCache =
54+
CacheBuilder.newBuilder().maximumSize(FluoConfigurationImpl.getTransactorMaxCacheSize(conf))
55+
.expireAfterAccess(
56+
FluoConfigurationImpl.getTransactorCacheTimeout(conf, TimeUnit.MILLISECONDS),
57+
TimeUnit.MILLISECONDS)
58+
.concurrencyLevel(10).build();
5559

5660
this.env = env;
5761
cache = new PathChildrenCache(env.getSharedResources().getCurator(),

modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public int weigh(PrimaryRowColumn key, TxInfo value) {
4141
cache = CacheBuilder.newBuilder()
4242
.expireAfterAccess(FluoConfigurationImpl.getTxIfoCacheTimeout(conf, TimeUnit.MILLISECONDS),
4343
TimeUnit.MILLISECONDS)
44-
.maximumWeight(FluoConfigurationImpl.getTxInfoCacheSize(conf))
44+
.maximumWeight(FluoConfigurationImpl.getTxInfoCacheWeight(conf))
4545
.weigher(new TxStatusWeigher()).concurrencyLevel(10).build();
4646
this.env = env;
4747
}

modules/core/src/main/java/org/apache/fluo/core/impl/VisibilityCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public int weigh(Bytes key, ColumnVisibility vis) {
5252
.expireAfterAccess(
5353
FluoConfigurationImpl.getVisibilityCacheTimeout(conf, TimeUnit.MILLISECONDS),
5454
TimeUnit.MILLISECONDS)
55-
.maximumWeight(FluoConfigurationImpl.getVisibilityCacheSize(conf)).weigher(new VisWeigher())
56-
.concurrencyLevel(10).build();
55+
.maximumWeight(FluoConfigurationImpl.getVisibilityCacheWeight(conf))
56+
.weigher(new VisWeigher()).concurrencyLevel(10).build();
5757
}
5858

5959
public ColumnVisibility getCV(Column col) {

0 commit comments

Comments
 (0)