Field Data: Simplify field data cache settings

closes #2843
This commit is contained in:
Shay Banon 2013-04-02 12:44:39 +02:00
parent d866321c55
commit 31d1e6cfe7
2 changed files with 12 additions and 5 deletions

View File

@ -160,7 +160,9 @@ public class IndexFieldDataService extends AbstractIndexComponent implements Ind
}
IndexFieldDataCache cache;
String cacheType = type.getSettings().get("cache", indexSettings.get("index.fielddata.cache", "resident"));
// we default to node level cache, which in turn defaults to be unbounded
// this means changing the node level settings is simple, just set the bounds there
String cacheType = type.getSettings().get("cache", indexSettings.get("index.fielddata.cache", "node"));
if ("resident".equals(cacheType)) {
cache = new IndexFieldDataCache.Resident(index, fieldNames, type, this);
} else if ("soft".equals(cacheType)) {

View File

@ -53,7 +53,7 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL
@Inject
public IndicesFieldDataCache(Settings settings) {
super(settings);
this.size = componentSettings.get("size", "40%");
this.size = componentSettings.get("size", "-1");
this.expire = componentSettings.getAsTime("expire", null);
computeSizeInBytes();
buildCache();
@ -62,17 +62,22 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL
private void buildCache() {
CacheBuilder<Key, AtomicFieldData> cacheBuilder = CacheBuilder.newBuilder()
.removalListener(this);
cacheBuilder.maximumWeight(sizeInBytes).weigher(new FieldDataWeigher());
if (sizeInBytes > 0) {
cacheBuilder.maximumWeight(sizeInBytes).weigher(new FieldDataWeigher());
}
// defaults to 4, but this is a busy map for all indices, increase it a bit
cacheBuilder.concurrencyLevel(16);
if (expire != null) {
if (expire != null && expire.millis() > 0) {
cacheBuilder.expireAfterAccess(expire.millis(), TimeUnit.MILLISECONDS);
}
logger.debug("using size [{}] [{}], expire [{}]", size, new ByteSizeValue(sizeInBytes), expire);
cache = cacheBuilder.build();
}
private void computeSizeInBytes() {
if (size.endsWith("%")) {
if (size.equals("-1")) {
sizeInBytes = -1;
} else if (size.endsWith("%")) {
double percent = Double.parseDouble(size.substring(0, size.length() - 1));
sizeInBytes = (long) ((percent / 100) * JvmInfo.jvmInfo().getMem().getHeapMax().bytes());
} else {