mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
add evictions stats to field data
This commit is contained in:
parent
e9ba98913b
commit
e01879a698
@ -34,17 +34,20 @@ import java.io.IOException;
|
|||||||
public class FieldDataStats implements Streamable, ToXContent {
|
public class FieldDataStats implements Streamable, ToXContent {
|
||||||
|
|
||||||
long memorySize;
|
long memorySize;
|
||||||
|
long evictions;
|
||||||
|
|
||||||
public FieldDataStats() {
|
public FieldDataStats() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldDataStats(long memorySize) {
|
public FieldDataStats(long memorySize, long evictions) {
|
||||||
this.memorySize = memorySize;
|
this.memorySize = memorySize;
|
||||||
|
this.evictions = evictions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(FieldDataStats stats) {
|
public void add(FieldDataStats stats) {
|
||||||
this.memorySize += stats.memorySize;
|
this.memorySize += stats.memorySize;
|
||||||
|
this.evictions += stats.evictions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMemorySizeInBytes() {
|
public long getMemorySizeInBytes() {
|
||||||
@ -55,6 +58,10 @@ public class FieldDataStats implements Streamable, ToXContent {
|
|||||||
return new ByteSizeValue(memorySize);
|
return new ByteSizeValue(memorySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getEvictions() {
|
||||||
|
return this.evictions;
|
||||||
|
}
|
||||||
|
|
||||||
public static FieldDataStats readFieldDataStats(StreamInput in) throws IOException {
|
public static FieldDataStats readFieldDataStats(StreamInput in) throws IOException {
|
||||||
FieldDataStats stats = new FieldDataStats();
|
FieldDataStats stats = new FieldDataStats();
|
||||||
stats.readFrom(in);
|
stats.readFrom(in);
|
||||||
@ -64,11 +71,13 @@ public class FieldDataStats implements Streamable, ToXContent {
|
|||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
memorySize = in.readVLong();
|
memorySize = in.readVLong();
|
||||||
|
evictions = in.readVLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVLong(memorySize);
|
out.writeVLong(memorySize);
|
||||||
|
out.writeVLong(evictions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -76,6 +85,7 @@ public class FieldDataStats implements Streamable, ToXContent {
|
|||||||
builder.startObject(Fields.FIELD_DATA);
|
builder.startObject(Fields.FIELD_DATA);
|
||||||
builder.field(Fields.MEMORY_SIZE, memorySize);
|
builder.field(Fields.MEMORY_SIZE, memorySize);
|
||||||
builder.field(Fields.MEMORY_SIZE_IN_BYTES, getMemorySize().toString());
|
builder.field(Fields.MEMORY_SIZE_IN_BYTES, getMemorySize().toString());
|
||||||
|
builder.field(Fields.EVICTIONS, getEvictions());
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
@ -84,5 +94,6 @@ public class FieldDataStats implements Streamable, ToXContent {
|
|||||||
static final XContentBuilderString FIELD_DATA = new XContentBuilderString("field_data");
|
static final XContentBuilderString FIELD_DATA = new XContentBuilderString("field_data");
|
||||||
static final XContentBuilderString MEMORY_SIZE = new XContentBuilderString("memory_size");
|
static final XContentBuilderString MEMORY_SIZE = new XContentBuilderString("memory_size");
|
||||||
static final XContentBuilderString MEMORY_SIZE_IN_BYTES = new XContentBuilderString("memory_size_in_bytes");
|
static final XContentBuilderString MEMORY_SIZE_IN_BYTES = new XContentBuilderString("memory_size_in_bytes");
|
||||||
|
static final XContentBuilderString EVICTIONS = new XContentBuilderString("evictions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import com.google.common.cache.RemovalNotification;
|
|||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.SegmentReader;
|
import org.apache.lucene.index.SegmentReader;
|
||||||
import org.elasticsearch.common.Nullable;
|
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ public interface IndexFieldDataCache {
|
|||||||
|
|
||||||
void onLoad(Index index, FieldMapper.Names fieldNames, FieldDataType fieldDataType, AtomicFieldData fieldData);
|
void onLoad(Index index, FieldMapper.Names fieldNames, FieldDataType fieldDataType, AtomicFieldData fieldData);
|
||||||
|
|
||||||
void onUnload(Index index, FieldMapper.Names fieldNames, FieldDataType fieldDataType, @Nullable AtomicFieldData fieldData);
|
void onUnload(Index index, FieldMapper.Names fieldNames, FieldDataType fieldDataType, RemovalNotification<Object, AtomicFieldData> notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +72,7 @@ public interface IndexFieldDataCache {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoval(RemovalNotification<Object, AtomicFieldData> notification) {
|
public void onRemoval(RemovalNotification<Object, AtomicFieldData> notification) {
|
||||||
listener.onUnload(index, fieldNames, fieldDataType, notification.getValue());
|
listener.onUnload(index, fieldNames, fieldDataType, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
package org.elasticsearch.index.fielddata;
|
package org.elasticsearch.index.fielddata;
|
||||||
|
|
||||||
|
import com.google.common.cache.RemovalNotification;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.Nullable;
|
|
||||||
import org.elasticsearch.common.collect.MapBuilder;
|
import org.elasticsearch.common.collect.MapBuilder;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
import org.elasticsearch.common.collect.Tuple;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
@ -73,6 +73,7 @@ public class IndexFieldDataService extends AbstractIndexComponent implements Ind
|
|||||||
private final ConcurrentMap<String, IndexFieldData> loadedFieldData = ConcurrentCollections.newConcurrentMap();
|
private final ConcurrentMap<String, IndexFieldData> loadedFieldData = ConcurrentCollections.newConcurrentMap();
|
||||||
|
|
||||||
private final CounterMetric memoryUsedInBytes = new CounterMetric();
|
private final CounterMetric memoryUsedInBytes = new CounterMetric();
|
||||||
|
private final CounterMetric evictions = new CounterMetric();
|
||||||
|
|
||||||
public IndexFieldDataService(Index index) {
|
public IndexFieldDataService(Index index) {
|
||||||
this(index, ImmutableSettings.Builder.EMPTY_SETTINGS);
|
this(index, ImmutableSettings.Builder.EMPTY_SETTINGS);
|
||||||
@ -114,15 +115,18 @@ public class IndexFieldDataService extends AbstractIndexComponent implements Ind
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUnload(Index index, FieldMapper.Names fieldNames, FieldDataType fieldDataType, @Nullable AtomicFieldData fieldData) {
|
public void onUnload(Index index, FieldMapper.Names fieldNames, FieldDataType fieldDataType, RemovalNotification<Object, AtomicFieldData> notification) {
|
||||||
assert index.equals(this.index);
|
assert index.equals(this.index);
|
||||||
if (fieldData != null) {
|
if (notification.getValue() != null) {
|
||||||
memoryUsedInBytes.dec(fieldData.getMemorySizeInBytes());
|
memoryUsedInBytes.dec(notification.getValue().getMemorySizeInBytes());
|
||||||
|
}
|
||||||
|
if (notification.wasEvicted()) {
|
||||||
|
evictions.inc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldDataStats stats() {
|
public FieldDataStats stats() {
|
||||||
return new FieldDataStats(memoryUsedInBytes.count());
|
return new FieldDataStats(memoryUsedInBytes.count(), evictions.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
public <IFD extends IndexFieldData> IFD getForField(FieldMapper mapper) {
|
public <IFD extends IndexFieldData> IFD getForField(FieldMapper mapper) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user