Skip to content

Commit 67a8e0a

Browse files
committed
Add to node stats the number of times field cache was evicted due to memory constraints, closes elastic#603.
1 parent bad0b1f commit 67a8e0a

File tree

7 files changed

+58
-6
lines changed

7 files changed

+58
-6
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public interface FieldDataCache extends IndexComponent, CloseableComponent {
4242

4343
void clearUnreferenced();
4444

45+
long evictions();
46+
4547
long sizeInBytes();
4648

4749
long sizeInBytes(String fieldName);

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ public class NoneFieldDataCache extends AbstractIndexComponent implements FieldD
6969
@Override public long sizeInBytes(String fieldName) {
7070
return 0;
7171
}
72+
73+
@Override public long evictions() {
74+
return 0;
75+
}
7276
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@ public class ResidentFieldDataCache extends AbstractConcurrentMapFieldDataCache
4545
@Override public String type() {
4646
return "resident";
4747
}
48+
49+
@Override public long evictions() {
50+
return 0;
51+
}
4852
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.index.cache.field.data.soft;
2121

22+
import org.elasticsearch.common.collect.MapEvictionListener;
2223
import org.elasticsearch.common.collect.MapMaker;
2324
import org.elasticsearch.common.inject.Inject;
2425
import org.elasticsearch.common.settings.Settings;
@@ -27,22 +28,34 @@
2728
import org.elasticsearch.index.field.data.FieldData;
2829
import org.elasticsearch.index.settings.IndexSettings;
2930

31+
import javax.annotation.Nullable;
3032
import java.util.concurrent.ConcurrentMap;
33+
import java.util.concurrent.atomic.AtomicLong;
3134

3235
/**
3336
* @author kimchy (shay.banon)
3437
*/
35-
public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache {
38+
public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache implements MapEvictionListener<String, FieldData> {
39+
40+
private final AtomicLong evictions = new AtomicLong();
3641

3742
@Inject public SoftFieldDataCache(Index index, @IndexSettings Settings indexSettings) {
3843
super(index, indexSettings);
3944
}
4045

4146
@Override protected ConcurrentMap<String, FieldData> buildFieldDataMap() {
42-
return new MapMaker().softValues().makeMap();
47+
return new MapMaker().softValues().evictionListener(this).makeMap();
48+
}
49+
50+
@Override public long evictions() {
51+
return evictions.get();
4352
}
4453

4554
@Override public String type() {
4655
return "soft";
4756
}
57+
58+
@Override public void onEviction(@Nullable String s, @Nullable FieldData fieldData) {
59+
evictions.incrementAndGet();
60+
}
4861
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/field/data/weak/WeakFieldDataCache.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.index.cache.field.data.weak;
2121

22+
import org.elasticsearch.common.collect.MapEvictionListener;
2223
import org.elasticsearch.common.collect.MapMaker;
2324
import org.elasticsearch.common.inject.Inject;
2425
import org.elasticsearch.common.settings.Settings;
@@ -27,22 +28,34 @@
2728
import org.elasticsearch.index.field.data.FieldData;
2829
import org.elasticsearch.index.settings.IndexSettings;
2930

31+
import javax.annotation.Nullable;
3032
import java.util.concurrent.ConcurrentMap;
33+
import java.util.concurrent.atomic.AtomicLong;
3134

3235
/**
3336
* @author kimchy (shay.banon)
3437
*/
35-
public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache {
38+
public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache implements MapEvictionListener<String, FieldData> {
39+
40+
private final AtomicLong evictions = new AtomicLong();
3641

3742
@Inject public WeakFieldDataCache(Index index, @IndexSettings Settings indexSettings) {
3843
super(index, indexSettings);
3944
}
4045

4146
@Override protected ConcurrentMap<String, FieldData> buildFieldDataMap() {
42-
return new MapMaker().weakValues().makeMap();
47+
return new MapMaker().weakValues().evictionListener(this).makeMap();
4348
}
4449

4550
@Override public String type() {
4651
return "weak";
4752
}
53+
54+
@Override public long evictions() {
55+
return evictions.get();
56+
}
57+
58+
@Override public void onEviction(@Nullable String s, @Nullable FieldData fieldData) {
59+
evictions.incrementAndGet();
60+
}
4861
}

modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesStats.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
4343

4444
private ByteSizeValue filterCacheSize;
4545

46+
private long fieldCacheEvictions;
47+
4648
IndicesStats() {
4749
}
4850

49-
public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize) {
51+
public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize,
52+
long fieldCacheEvictions) {
5053
this.storeSize = storeSize;
5154
this.fieldCacheSize = fieldCacheSize;
5255
this.filterCacheSize = filterCacheSize;
56+
this.fieldCacheEvictions = fieldCacheEvictions;
5357
}
5458

5559
/**
@@ -82,6 +86,14 @@ public ByteSizeValue getFilterCacheSize() {
8286
return this.filterCacheSize;
8387
}
8488

89+
public long fieldCacheEvictions() {
90+
return this.fieldCacheEvictions;
91+
}
92+
93+
public long getFieldCacheEvictions() {
94+
return fieldCacheEvictions();
95+
}
96+
8597
public static IndicesStats readIndicesStats(StreamInput in) throws IOException {
8698
IndicesStats stats = new IndicesStats();
8799
stats.readFrom(in);
@@ -104,6 +116,7 @@ public static IndicesStats readIndicesStats(StreamInput in) throws IOException {
104116
builder.startObject(Fields.INDICES);
105117
builder.field(Fields.STORE_SIZE, storeSize.toString());
106118
builder.field(Fields.STORE_SIZE_IN_BYTES, storeSize.bytes());
119+
builder.field(Fields.FIELD_CACHE_EVICTIONS, fieldCacheEvictions);
107120
builder.field(Fields.FIELD_CACHE_SIZE, fieldCacheSize.toString());
108121
builder.field(Fields.FIELD_CACHE_SIZE_IN_BYTES, fieldCacheSize.bytes());
109122
builder.field(Fields.FILTER_CACHE_SIZE, filterCacheSize.toString());
@@ -117,6 +130,7 @@ static final class Fields {
117130
static final XContentBuilderString STORE_SIZE_IN_BYTES = new XContentBuilderString("store_size_in_bytes");
118131
static final XContentBuilderString FIELD_CACHE_SIZE = new XContentBuilderString("field_cache_size");
119132
static final XContentBuilderString FIELD_CACHE_SIZE_IN_BYTES = new XContentBuilderString("field_cache_size_in_bytes");
133+
static final XContentBuilderString FIELD_CACHE_EVICTIONS = new XContentBuilderString("field_cache_evictions");
120134
static final XContentBuilderString FILTER_CACHE_SIZE = new XContentBuilderString("filter_cache_size");
121135
static final XContentBuilderString FILTER_CACHE_SIZE_IN_BYTES = new XContentBuilderString("filter_cache_size_in_bytes");
122136
}

modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
156156

157157
@Override public IndicesStats stats() {
158158
long storeTotalSize = 0;
159+
long fieldCacheEvictions = 0;
159160
long fieldCacheTotalSize = 0;
160161
long filterCacheTotalSize = 0;
161162
for (IndexService indexService : indices.values()) {
@@ -166,10 +167,11 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
166167
// ignore
167168
}
168169
}
170+
fieldCacheEvictions += indexService.cache().fieldData().evictions();
169171
fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes();
170172
filterCacheTotalSize += indexService.cache().filter().sizeInBytes();
171173
}
172-
return new IndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize));
174+
return new IndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize), fieldCacheEvictions);
173175
}
174176

175177
/**

0 commit comments

Comments
 (0)