Skip to content

Commit

Permalink
Field Data: Simplify field data cache settings
Browse files Browse the repository at this point in the history
closes #2843
  • Loading branch information
kimchy committed Apr 2, 2013
1 parent d866321 commit 31d1e6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Expand Up @@ -160,7 +160,9 @@ public <IFD extends IndexFieldData> IFD getForField(FieldMapper.Names fieldNames
}

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)) {
Expand Down
Expand Up @@ -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();
Expand All @@ -62,17 +62,22 @@ public IndicesFieldDataCache(Settings settings) {
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 {
Expand Down

0 comments on commit 31d1e6c

Please sign in to comment.