Skip to content

Commit

Permalink
fixes #950 Make VisibilityCache customizable (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth McFarland authored and keith-turner committed Oct 24, 2017
1 parent d9fc391 commit 9e87f47
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static int getTxCommitMemory(FluoConfiguration conf) {
}

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;
public static final long TX_INFO_CACHE_SIZE_DEFAULT = 10_000_000;

/**
* Gets the cache size
Expand Down Expand Up @@ -144,6 +144,47 @@ public static long getTxIfoCacheTimeout(FluoConfiguration conf, TimeUnit tu) {
return tu.convert(millis, TimeUnit.MILLISECONDS);
}

public static final String VISIBILITY_CACHE_SIZE = FLUO_IMPL_PREFIX + ".visibility.cache.size.mb";
public static final long VISIBILITY_CACHE_SIZE_DEFAULT = 10_000_000;

/**
* Gets the cache size
*
* @param conf The FluoConfiguration
* @return The size of the cache value from the property value {@value #VISIBILITY_CACHE_SIZE}
* if it is set, else the value of the default value {@value #VISIBILITY_CACHE_SIZE_DEFAULT}
*/

public static long getVisibilityCacheSize(FluoConfiguration conf) {
long size = conf.getLong(VISIBILITY_CACHE_SIZE, VISIBILITY_CACHE_SIZE_DEFAULT);
if (size <= 0) {
throw new IllegalArgumentException(
"Cache size must be positive for " + VISIBILITY_CACHE_SIZE);
}
return size;
}

public static final String VISIBILITY_CACHE_TIMEOUT =
FLUO_IMPL_PREFIX + ".visibility.cache.expireTime.ms";
public static final long VISIBILITY_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 getVisibilityCacheTimeout(FluoConfiguration conf, TimeUnit tu) {
long millis = conf.getLong(VISIBILITY_CACHE_TIMEOUT, VISIBILITY_CACHE_TIMEOUT_DEFAULT);
if (millis <= 0) {
throw new IllegalArgumentException("Timeout must positive for " + VISIBILITY_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 @@ -82,7 +82,7 @@ public SharedResources(Environment env) throws TableNotFoundException {
.setAuthorizations(env.getAuthorizations()).setMaxWriteThreads(numCWThreads));

txInfoCache = new TxInfoCache(env);
visCache = new VisibilityCache();
visCache = new VisibilityCache(env.getConfiguration());
metricRegistry = new MetricRegistry();

int commitThreads = env.getConfiguration().getInt(FluoConfigurationImpl.ASYNC_COMMIT_THREADS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.Weigher;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.apache.fluo.api.config.FluoConfiguration;
import org.apache.fluo.api.data.Bytes;
import org.apache.fluo.api.data.Column;
import org.apache.fluo.core.util.ByteUtil;

/**
* PArsing Column visibilities can be expensive. This class provides a cache of parsed visibility
* Parsing Column visibilities can be expensive. This class provides a cache of parsed visibility
* objects.
*/

Expand All @@ -46,11 +47,11 @@ public int weigh(Bytes key, ColumnVisibility vis) {

private final Cache<Bytes, ColumnVisibility> visCache;

VisibilityCache() {
VisibilityCache(FluoConfiguration conf) {
visCache = CacheBuilder.newBuilder()
.expireAfterAccess(FluoConfigurationImpl.TX_INFO_CACHE_TIMEOUT_DEFAULT,
.expireAfterAccess(FluoConfigurationImpl.getVisibilityCacheTimeout(conf, TimeUnit.MILLISECONDS),
TimeUnit.MILLISECONDS)
.maximumWeight(FluoConfigurationImpl.TX_INFO_CACHE_SIZE_DEFAULT).weigher(new VisWeigher())
.maximumWeight(FluoConfigurationImpl.getVisibilityCacheSize(conf)).weigher(new VisWeigher())
.concurrencyLevel(10).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.apache.fluo.core.impl;

import org.apache.fluo.api.config.FluoConfiguration;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -25,7 +26,7 @@ public class VisibilityCacheTest {

@Test
public void testVisibilityCacheConstructor() {
VisibilityCache cache = new VisibilityCache();
VisibilityCache cache = new VisibilityCache(new FluoConfiguration());
Assert.assertNotNull("VisibilityCache failed to instantiate.", cache);
cache = null;
}
Expand Down

0 comments on commit 9e87f47

Please sign in to comment.