Skip to content

Commit c03b95e

Browse files
committed
add filter_cache_size to node stats
1 parent c66a1c2 commit c03b95e

File tree

14 files changed

+118
-15
lines changed

14 files changed

+118
-15
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.common.lucene.docset;
2121

2222
import org.apache.lucene.search.DocIdSetIterator;
23+
import org.elasticsearch.common.RamUsage;
2324

2425
import java.io.IOException;
2526

@@ -44,6 +45,10 @@ public AllDocSet(int maxDoc) {
4445
return doc < maxDoc;
4546
}
4647

48+
@Override public long sizeInBytes() {
49+
return RamUsage.NUM_BYTES_INT;
50+
}
51+
4752
@Override public DocIdSetIterator iterator() throws IOException {
4853
return new AllDocIdSetIterator(maxDoc);
4954
}

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public AndDocSet(List<DocSet> sets) {
5555
// return true;
5656
}
5757

58+
@Override public long sizeInBytes() {
59+
long sizeInBytes = 0;
60+
for (DocSet set : sets) {
61+
sizeInBytes += set.sizeInBytes();
62+
}
63+
return sizeInBytes;
64+
}
65+
5866
@Override public DocIdSetIterator iterator() throws IOException {
5967
return new AndDocIdSetIterator();
6068
}

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ public abstract class DocSet extends DocIdSet {
4141
@Override public boolean isCacheable() {
4242
return true;
4343
}
44+
45+
@Override public long sizeInBytes() {
46+
return 0;
47+
}
4448
};
4549

4650
public abstract boolean get(int doc) throws IOException;
51+
52+
public abstract long sizeInBytes();
4753
}

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/GetDocSet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ protected GetDocSet(int maxDoc) {
3434
this.maxDoc = maxDoc;
3535
}
3636

37+
@Override public long sizeInBytes() {
38+
return 0;
39+
}
40+
3741
@Override public DocIdSetIterator iterator() throws IOException {
3842
return new DocIdSetIterator() {
3943
private int doc = -1;

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public NotDocSet(DocSet set, int max) {
4444
return !set.get(doc);
4545
}
4646

47+
@Override public long sizeInBytes() {
48+
return set.sizeInBytes();
49+
}
50+
4751
// This seems like overhead compared to testing with get and iterating over docs
4852
// @Override public DocIdSetIterator iterator() throws IOException {
4953
// return new NotDocIdSetIterator();

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.lucene.search.DocIdSetIterator;
2323
import org.apache.lucene.util.OpenBitSet;
2424
import org.apache.lucene.util.OpenBitSetDISI;
25+
import org.elasticsearch.common.RamUsage;
2526

2627
import java.io.IOException;
2728

@@ -59,4 +60,8 @@ public OpenBitSet set() {
5960
@Override public DocIdSetIterator iterator() throws IOException {
6061
return set.iterator();
6162
}
63+
64+
@Override public long sizeInBytes() {
65+
return set.getBits().length * RamUsage.NUM_BYTES_LONG + RamUsage.NUM_BYTES_ARRAY_HEADER + RamUsage.NUM_BYTES_INT /* wlen */;
66+
}
6267
}

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,30 @@ public OrDocSet(List<DocSet> sets) {
3737
}
3838

3939
@Override public boolean get(int doc) throws IOException {
40+
for (DocSet s : sets) {
41+
if (s.get(doc)) return true;
42+
}
43+
return false;
44+
}
45+
46+
@Override public boolean isCacheable() {
4047
// not cacheable, the reason is that by default, when constructing the filter, it is not cacheable,
4148
// so if someone wants it to be cacheable, we might as well construct a cached version of the result
4249
return false;
43-
// for (DocSet s : sets) {
44-
// if (s.get(doc)) return true;
50+
// for (DocSet set : sets) {
51+
// if (!set.isCacheable()) {
52+
// return false;
53+
// }
4554
// }
46-
// return false;
55+
// return true;
4756
}
4857

49-
@Override public boolean isCacheable() {
58+
@Override public long sizeInBytes() {
59+
long sizeInBytes = 0;
5060
for (DocSet set : sets) {
51-
if (!set.isCacheable()) {
52-
return false;
53-
}
61+
sizeInBytes += set.sizeInBytes();
5462
}
55-
return true;
63+
return sizeInBytes;
5664
}
5765

5866
@Override public DocIdSetIterator iterator() throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ public interface FilterCache extends IndexComponent, CloseableComponent {
4545
* Clears unreferenced filters.
4646
*/
4747
void clearUnreferenced();
48+
49+
long sizeInBytes();
4850
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ public class NoneFilterCache extends AbstractIndexComponent implements FilterCac
6969
@Override public void clearUnreferenced() {
7070
// nothing to do here
7171
}
72+
73+
@Override public long sizeInBytes() {
74+
return 0;
75+
}
7276
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/support/AbstractConcurrentMapFilterCache.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ protected AbstractConcurrentMapFilterCache(Index index, @IndexSettings Settings
8888
// }
8989
}
9090

91+
@Override public long sizeInBytes() {
92+
long sizeInBytes = 0;
93+
for (ConcurrentMap<Filter, DocSet> map : cache.values()) {
94+
for (DocSet docSet : map.values()) {
95+
sizeInBytes += docSet.sizeInBytes();
96+
}
97+
}
98+
return sizeInBytes;
99+
}
100+
91101
@Override public Filter cache(Filter filterToCache) {
92102
if (isCached(filterToCache)) {
93103
return filterToCache;

modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/support/AbstractDoubleConcurrentMapFilterCache.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ protected AbstractDoubleConcurrentMapFilterCache(Index index, @IndexSettings Set
7979
@Override public void clearUnreferenced() {
8080
}
8181

82+
@Override public long sizeInBytes() {
83+
long sizeInBytes = 0;
84+
for (ConcurrentMap<Filter, DocSet> map : cache.values()) {
85+
for (DocSet docSet : map.values()) {
86+
sizeInBytes += docSet.sizeInBytes();
87+
}
88+
}
89+
for (ConcurrentMap<Filter, DocSet> map : weakCache.values()) {
90+
for (DocSet docSet : map.values()) {
91+
sizeInBytes += docSet.sizeInBytes();
92+
}
93+
}
94+
return sizeInBytes;
95+
}
96+
8297
@Override public Filter cache(Filter filterToCache) {
8398
if (isCached(filterToCache)) {
8499
return filterToCache;

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/ScriptFilterParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ public ScriptDocSet(IndexReader reader, SearchScript searchScript) {
164164
this.searchScript = searchScript;
165165
}
166166

167+
@Override public long sizeInBytes() {
168+
return 0;
169+
}
170+
167171
@Override public boolean isCacheable() {
168172
// not cacheable for several reasons:
169173
// 1. The script service is shared and holds the current reader executing against, and it

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

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.common.unit.ByteSizeValue;
2626
import org.elasticsearch.common.xcontent.ToXContent;
2727
import org.elasticsearch.common.xcontent.XContentBuilder;
28+
import org.elasticsearch.common.xcontent.XContentBuilderString;
2829

2930
import java.io.IOException;
3031
import java.io.Serializable;
@@ -40,12 +41,15 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
4041

4142
private ByteSizeValue fieldCacheSize;
4243

44+
private ByteSizeValue filterCacheSize;
45+
4346
IndicesStats() {
4447
}
4548

46-
public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize) {
49+
public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize) {
4750
this.storeSize = storeSize;
4851
this.fieldCacheSize = fieldCacheSize;
52+
this.filterCacheSize = filterCacheSize;
4953
}
5054

5155
/**
@@ -70,6 +74,14 @@ public ByteSizeValue getFieldCacheSize() {
7074
return this.fieldCacheSize;
7175
}
7276

77+
public ByteSizeValue filterCacheSize() {
78+
return this.filterCacheSize;
79+
}
80+
81+
public ByteSizeValue getFilterCacheSize() {
82+
return this.filterCacheSize;
83+
}
84+
7385
public static IndicesStats readIndicesStats(StreamInput in) throws IOException {
7486
IndicesStats stats = new IndicesStats();
7587
stats.readFrom(in);
@@ -79,19 +91,33 @@ public static IndicesStats readIndicesStats(StreamInput in) throws IOException {
7991
@Override public void readFrom(StreamInput in) throws IOException {
8092
storeSize = ByteSizeValue.readBytesSizeValue(in);
8193
fieldCacheSize = ByteSizeValue.readBytesSizeValue(in);
94+
filterCacheSize = ByteSizeValue.readBytesSizeValue(in);
8295
}
8396

8497
@Override public void writeTo(StreamOutput out) throws IOException {
8598
storeSize.writeTo(out);
8699
fieldCacheSize.writeTo(out);
100+
filterCacheSize.writeTo(out);
87101
}
88102

89103
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
90-
builder.startObject("indices");
91-
builder.field("store_size", storeSize.toString());
92-
builder.field("store_size_in_bytes", storeSize.bytes());
93-
builder.field("field_cache_size", fieldCacheSize.toString());
94-
builder.field("field_cache_size_in_bytes", fieldCacheSize.bytes());
104+
builder.startObject(Fields.INDICES);
105+
builder.field(Fields.STORE_SIZE, storeSize.toString());
106+
builder.field(Fields.STORE_SIZE_IN_BYTES, storeSize.bytes());
107+
builder.field(Fields.FIELD_CACHE_SIZE, fieldCacheSize.toString());
108+
builder.field(Fields.FIELD_CACHE_SIZE_IN_BYTES, fieldCacheSize.bytes());
109+
builder.field(Fields.FILTER_CACHE_SIZE, filterCacheSize.toString());
110+
builder.field(Fields.FILTER_CACHE_SIZE_IN_BYTES, filterCacheSize.bytes());
95111
builder.endObject();
96112
}
113+
114+
static final class Fields {
115+
static final XContentBuilderString INDICES = new XContentBuilderString("indices");
116+
static final XContentBuilderString STORE_SIZE = new XContentBuilderString("store_size");
117+
static final XContentBuilderString STORE_SIZE_IN_BYTES = new XContentBuilderString("store_size_in_bytes");
118+
static final XContentBuilderString FIELD_CACHE_SIZE = new XContentBuilderString("field_cache_size");
119+
static final XContentBuilderString FIELD_CACHE_SIZE_IN_BYTES = new XContentBuilderString("field_cache_size_in_bytes");
120+
static final XContentBuilderString FILTER_CACHE_SIZE = new XContentBuilderString("filter_cache_size");
121+
static final XContentBuilderString FILTER_CACHE_SIZE_IN_BYTES = new XContentBuilderString("filter_cache_size_in_bytes");
122+
}
97123
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
157157
@Override public IndicesStats stats() {
158158
long storeTotalSize = 0;
159159
long fieldCacheTotalSize = 0;
160+
long filterCacheTotalSize = 0;
160161
for (IndexService indexService : indices.values()) {
161162
for (IndexShard indexShard : indexService) {
162163
try {
@@ -166,8 +167,9 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
166167
}
167168
}
168169
fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes();
170+
filterCacheTotalSize += indexService.cache().filter().sizeInBytes();
169171
}
170-
return new IndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize));
172+
return new IndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize));
171173
}
172174

173175
/**

0 commit comments

Comments
 (0)