From 66d63055df170453c21add6e82d2605c1f47daff Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 5 Jan 2011 22:37:15 +0200 Subject: [PATCH] Add to node stats the number of times field cache was evicted due to memory constraints, closes #603. --- .../index/cache/field/data/FieldDataCache.java | 2 ++ .../field/data/none/NoneFieldDataCache.java | 4 ++++ .../data/resident/ResidentFieldDataCache.java | 4 ++++ .../field/data/soft/SoftFieldDataCache.java | 17 +++++++++++++++-- .../field/data/weak/WeakFieldDataCache.java | 17 +++++++++++++++-- .../org/elasticsearch/indices/IndicesStats.java | 16 +++++++++++++++- .../indices/InternalIndicesService.java | 4 +++- 7 files changed, 58 insertions(+), 6 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java index 9ac8faf4ec2..4495c51902f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java @@ -42,6 +42,8 @@ public interface FieldDataCache extends IndexComponent, CloseableComponent { void clearUnreferenced(); + long evictions(); + long sizeInBytes(); long sizeInBytes(String fieldName); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java index bda7a12fd25..75942420bbc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java @@ -69,4 +69,8 @@ public class NoneFieldDataCache extends AbstractIndexComponent implements FieldD @Override public long sizeInBytes(String fieldName) { return 0; } + + @Override public long evictions() { + return 0; + } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java index b0c6bc13828..8add27dfcee 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java @@ -45,4 +45,8 @@ public class ResidentFieldDataCache extends AbstractConcurrentMapFieldDataCache @Override public String type() { return "resident"; } + + @Override public long evictions() { + return 0; + } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java index fb45a638161..7f6ec971d4d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.cache.field.data.soft; +import org.elasticsearch.common.collect.MapEvictionListener; import org.elasticsearch.common.collect.MapMaker; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -27,22 +28,34 @@ import org.elasticsearch.index.cache.field.data.support.AbstractConcurrentMapFie import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.settings.IndexSettings; +import javax.annotation.Nullable; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; /** * @author kimchy (shay.banon) */ -public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache { +public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache implements MapEvictionListener { + + private final AtomicLong evictions = new AtomicLong(); @Inject public SoftFieldDataCache(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); } @Override protected ConcurrentMap buildFieldDataMap() { - return new MapMaker().softValues().makeMap(); + return new MapMaker().softValues().evictionListener(this).makeMap(); + } + + @Override public long evictions() { + return evictions.get(); } @Override public String type() { return "soft"; } + + @Override public void onEviction(@Nullable String s, @Nullable FieldData fieldData) { + evictions.incrementAndGet(); + } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java index 48362426476..5fe63111fd3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.cache.field.data.weak; +import org.elasticsearch.common.collect.MapEvictionListener; import org.elasticsearch.common.collect.MapMaker; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -27,22 +28,34 @@ import org.elasticsearch.index.cache.field.data.support.AbstractConcurrentMapFie import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.settings.IndexSettings; +import javax.annotation.Nullable; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; /** * @author kimchy (shay.banon) */ -public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache { +public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache implements MapEvictionListener { + + private final AtomicLong evictions = new AtomicLong(); @Inject public WeakFieldDataCache(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); } @Override protected ConcurrentMap buildFieldDataMap() { - return new MapMaker().weakValues().makeMap(); + return new MapMaker().weakValues().evictionListener(this).makeMap(); } @Override public String type() { return "weak"; } + + @Override public long evictions() { + return evictions.get(); + } + + @Override public void onEviction(@Nullable String s, @Nullable FieldData fieldData) { + evictions.incrementAndGet(); + } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesStats.java index 5fbb3d49c33..0ce76cfd0e8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesStats.java @@ -43,13 +43,17 @@ public class IndicesStats implements Streamable, Serializable, ToXContent { private ByteSizeValue filterCacheSize; + private long fieldCacheEvictions; + IndicesStats() { } - public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize) { + public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize, + long fieldCacheEvictions) { this.storeSize = storeSize; this.fieldCacheSize = fieldCacheSize; this.filterCacheSize = filterCacheSize; + this.fieldCacheEvictions = fieldCacheEvictions; } /** @@ -82,6 +86,14 @@ public class IndicesStats implements Streamable, Serializable, ToXContent { return this.filterCacheSize; } + public long fieldCacheEvictions() { + return this.fieldCacheEvictions; + } + + public long getFieldCacheEvictions() { + return fieldCacheEvictions(); + } + public static IndicesStats readIndicesStats(StreamInput in) throws IOException { IndicesStats stats = new IndicesStats(); stats.readFrom(in); @@ -104,6 +116,7 @@ public class IndicesStats implements Streamable, Serializable, ToXContent { builder.startObject(Fields.INDICES); builder.field(Fields.STORE_SIZE, storeSize.toString()); builder.field(Fields.STORE_SIZE_IN_BYTES, storeSize.bytes()); + builder.field(Fields.FIELD_CACHE_EVICTIONS, fieldCacheEvictions); builder.field(Fields.FIELD_CACHE_SIZE, fieldCacheSize.toString()); builder.field(Fields.FIELD_CACHE_SIZE_IN_BYTES, fieldCacheSize.bytes()); builder.field(Fields.FILTER_CACHE_SIZE, filterCacheSize.toString()); @@ -117,6 +130,7 @@ public class IndicesStats implements Streamable, Serializable, ToXContent { static final XContentBuilderString STORE_SIZE_IN_BYTES = new XContentBuilderString("store_size_in_bytes"); static final XContentBuilderString FIELD_CACHE_SIZE = new XContentBuilderString("field_cache_size"); static final XContentBuilderString FIELD_CACHE_SIZE_IN_BYTES = new XContentBuilderString("field_cache_size_in_bytes"); + static final XContentBuilderString FIELD_CACHE_EVICTIONS = new XContentBuilderString("field_cache_evictions"); static final XContentBuilderString FILTER_CACHE_SIZE = new XContentBuilderString("filter_cache_size"); static final XContentBuilderString FILTER_CACHE_SIZE_IN_BYTES = new XContentBuilderString("filter_cache_size_in_bytes"); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java index 6e3ae07af59..4dd3152c368 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java @@ -156,6 +156,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent