add node level field cache size to node stats api

This commit is contained in:
kimchy 2010-12-26 12:18:15 +02:00
parent 5dcba8a38c
commit 4245eb7395
28 changed files with 293 additions and 26 deletions

View File

@ -0,0 +1,53 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common;
/**
* @author kimchy (shay.banon)
*/
public class RamUsage {
private static final String OS_ARCH = System.getProperty("os.arch");
private static final boolean JRE_IS_64BIT;
static {
String x = System.getProperty("sun.arch.data.model");
if (x != null) {
JRE_IS_64BIT = x.indexOf("64") != -1;
} else {
if (OS_ARCH != null && OS_ARCH.indexOf("64") != -1) {
JRE_IS_64BIT = true;
} else {
JRE_IS_64BIT = false;
}
}
}
public final static int NUM_BYTES_SHORT = 2;
public final static int NUM_BYTES_INT = 4;
public final static int NUM_BYTES_LONG = 8;
public final static int NUM_BYTES_FLOAT = 4;
public final static int NUM_BYTES_DOUBLE = 8;
public final static int NUM_BYTES_CHAR = 2;
public final static int NUM_BYTES_OBJECT_HEADER = 8;
public final static int NUM_BYTES_OBJECT_REF = JRE_IS_64BIT ? 8 : 4;
public final static int NUM_BYTES_ARRAY_HEADER = NUM_BYTES_OBJECT_HEADER + NUM_BYTES_INT + NUM_BYTES_OBJECT_REF;
}

View File

@ -41,4 +41,8 @@ public interface FieldDataCache extends IndexComponent, CloseableComponent {
void clear(IndexReader reader); void clear(IndexReader reader);
void clearUnreferenced(); void clearUnreferenced();
long sizeInBytes();
long sizeInBytes(String fieldName);
} }

View File

@ -61,4 +61,12 @@ public class NoneFieldDataCache extends AbstractIndexComponent implements FieldD
@Override public void close() throws ElasticSearchException { @Override public void close() throws ElasticSearchException {
} }
@Override public long sizeInBytes() {
return 0;
}
@Override public long sizeInBytes(String fieldName) {
return 0;
}
} }

View File

@ -70,6 +70,28 @@ public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexC
// nothing to do here... // nothing to do here...
} }
@Override public long sizeInBytes() {
// the overhead of the map is not really relevant...
long sizeInBytes = 0;
for (ConcurrentMap<String, FieldData> map : cache.values()) {
for (FieldData fieldData : map.values()) {
sizeInBytes += fieldData.sizeInBytes();
}
}
return sizeInBytes;
}
@Override public long sizeInBytes(String fieldName) {
long sizeInBytes = 0;
for (ConcurrentMap<String, FieldData> map : cache.values()) {
FieldData fieldData = map.get(fieldName);
if (fieldData != null) {
sizeInBytes += fieldData.sizeInBytes();
}
}
return sizeInBytes;
}
@Override public FieldData cache(FieldDataType type, IndexReader reader, String fieldName) throws IOException { @Override public FieldData cache(FieldDataType type, IndexReader reader, String fieldName) throws IOException {
ConcurrentMap<String, FieldData> fieldDataCache = cache.get(reader.getFieldCacheKey()); ConcurrentMap<String, FieldData> fieldDataCache = cache.get(reader.getFieldCacheKey());
if (fieldDataCache == null) { if (fieldDataCache == null) {

View File

@ -39,6 +39,8 @@ public abstract class FieldData<Doc extends DocFieldData> {
private final String fieldName; private final String fieldName;
private long sizeInBytes = -1;
protected FieldData(String fieldName) { protected FieldData(String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@ -56,6 +58,15 @@ public abstract class FieldData<Doc extends DocFieldData> {
return docFieldData; return docFieldData;
} }
public long sizeInBytes() {
if (sizeInBytes == -1) {
sizeInBytes = computeSizeInBytes();
}
return sizeInBytes;
}
protected abstract long computeSizeInBytes();
protected abstract Doc createFieldData(); protected abstract Doc createFieldData();
/** /**

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.field.data.doubles;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.trove.TDoubleArrayList; import org.elasticsearch.common.trove.TDoubleArrayList;
import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.FieldDataType;
import org.elasticsearch.index.field.data.NumericFieldData; import org.elasticsearch.index.field.data.NumericFieldData;
@ -42,6 +43,10 @@ public abstract class DoubleFieldData extends NumericFieldData<DoubleDocFieldDat
this.values = values; this.values = values;
} }
@Override protected long computeSizeInBytes() {
return RamUsage.NUM_BYTES_DOUBLE * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
abstract public double value(int docId); abstract public double value(int docId);
abstract public double[] values(int docId); abstract public double[] values(int docId);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.doubles; package org.elasticsearch.index.field.data.doubles;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
/** /**
@ -46,6 +47,15 @@ public class MultiValueDoubleFieldData extends DoubleFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
long size = super.computeSizeInBytes();
size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array
for (int[] ordinal : ordinals) {
size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
return size;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return true; return true;
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.doubles; package org.elasticsearch.index.field.data.doubles;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
/** /**
@ -40,6 +41,11 @@ public class SingleValueDoubleFieldData extends DoubleFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
return super.computeSizeInBytes() +
RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return false; return false;
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.field.data.floats;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.trove.TFloatArrayList; import org.elasticsearch.common.trove.TFloatArrayList;
import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.FieldDataType;
import org.elasticsearch.index.field.data.NumericFieldData; import org.elasticsearch.index.field.data.NumericFieldData;
@ -42,6 +43,10 @@ public abstract class FloatFieldData extends NumericFieldData<FloatDocFieldData>
this.values = values; this.values = values;
} }
@Override protected long computeSizeInBytes() {
return RamUsage.NUM_BYTES_FLOAT * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
abstract public float value(int docId); abstract public float value(int docId);
abstract public float[] values(int docId); abstract public float[] values(int docId);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.floats; package org.elasticsearch.index.field.data.floats;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
@ -57,6 +58,15 @@ public class MultiValueFloatFieldData extends FloatFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
long size = super.computeSizeInBytes();
size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array
for (int[] ordinal : ordinals) {
size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
return size;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return true; return true;
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.floats; package org.elasticsearch.index.field.data.floats;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
@ -47,6 +48,11 @@ public class SingleValueFloatFieldData extends FloatFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
return super.computeSizeInBytes() +
RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return false; return false;
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.field.data.ints;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.trove.TIntArrayList; import org.elasticsearch.common.trove.TIntArrayList;
import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.FieldDataType;
import org.elasticsearch.index.field.data.NumericFieldData; import org.elasticsearch.index.field.data.NumericFieldData;
@ -42,6 +43,10 @@ public abstract class IntFieldData extends NumericFieldData<IntDocFieldData> {
this.values = values; this.values = values;
} }
@Override protected long computeSizeInBytes() {
return RamUsage.NUM_BYTES_INT * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
abstract public int value(int docId); abstract public int value(int docId);
abstract public int[] values(int docId); abstract public int[] values(int docId);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.ints; package org.elasticsearch.index.field.data.ints;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
@ -57,6 +58,15 @@ public class MultiValueIntFieldData extends IntFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
long size = super.computeSizeInBytes();
size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array
for (int[] ordinal : ordinals) {
size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
return size;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return true; return true;
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.ints; package org.elasticsearch.index.field.data.ints;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
@ -47,6 +48,11 @@ public class SingleValueIntFieldData extends IntFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
return super.computeSizeInBytes() +
RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return false; return false;
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.field.data.longs;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.joda.time.DateTimeZone; import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.joda.time.MutableDateTime; import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
@ -52,6 +53,10 @@ public abstract class LongFieldData extends NumericFieldData<LongDocFieldData> {
this.values = values; this.values = values;
} }
@Override protected long computeSizeInBytes() {
return RamUsage.NUM_BYTES_LONG * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
abstract public long value(int docId); abstract public long value(int docId);
abstract public long[] values(int docId); abstract public long[] values(int docId);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.longs; package org.elasticsearch.index.field.data.longs;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.joda.time.DateTimeZone; import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.joda.time.MutableDateTime; import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
@ -73,6 +74,15 @@ public class MultiValueLongFieldData extends LongFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
long size = super.computeSizeInBytes();
size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array
for (int[] ordinal : ordinals) {
size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
return size;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return true; return true;
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.longs; package org.elasticsearch.index.field.data.longs;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.joda.time.DateTimeZone; import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.joda.time.MutableDateTime; import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
@ -57,6 +58,11 @@ public class SingleValueLongFieldData extends LongFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
return super.computeSizeInBytes() +
RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return false; return false;
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.shorts; package org.elasticsearch.index.field.data.shorts;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
@ -57,6 +58,15 @@ public class MultiValueShortFieldData extends ShortFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
long size = super.computeSizeInBytes();
size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array
for (int[] ordinal : ordinals) {
size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
return size;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return true; return true;
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.field.data.shorts;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.trove.TShortArrayList; import org.elasticsearch.common.trove.TShortArrayList;
import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.FieldDataType;
import org.elasticsearch.index.field.data.NumericFieldData; import org.elasticsearch.index.field.data.NumericFieldData;
@ -42,6 +43,10 @@ public abstract class ShortFieldData extends NumericFieldData<ShortDocFieldData>
this.values = values; this.values = values;
} }
@Override protected long computeSizeInBytes() {
return RamUsage.NUM_BYTES_SHORT * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
abstract public short value(int docId); abstract public short value(int docId);
abstract public short[] values(int docId); abstract public short[] values(int docId);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.shorts; package org.elasticsearch.index.field.data.shorts;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
@ -47,6 +48,11 @@ public class SingleValueShortFieldData extends ShortFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
return super.computeSizeInBytes() +
RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return false; return false;
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.strings; package org.elasticsearch.index.field.data.strings;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
@ -47,6 +48,15 @@ public class MultiValueStringFieldData extends StringFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
long size = super.computeSizeInBytes();
size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array
for (int[] ordinal : ordinals) {
size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
return size;
}
@Override public boolean multiValued() { @Override public boolean multiValued() {
return true; return true;
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.field.data.strings; package org.elasticsearch.index.field.data.strings;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
@ -41,6 +42,11 @@ public class SingleValueStringFieldData extends StringFieldData {
this.ordinals = ordinals; this.ordinals = ordinals;
} }
@Override protected long computeSizeInBytes() {
return super.computeSizeInBytes() +
RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
int[] ordinals() { int[] ordinals() {
return ordinals; return ordinals;
} }

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.field.data.strings; package org.elasticsearch.index.field.data.strings;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.FieldData;
import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.FieldDataType;
import org.elasticsearch.index.field.data.support.FieldDataLoader; import org.elasticsearch.index.field.data.support.FieldDataLoader;
@ -39,6 +40,14 @@ public abstract class StringFieldData extends FieldData<StringDocFieldData> {
this.values = values; this.values = values;
} }
@Override protected long computeSizeInBytes() {
long size = RamUsage.NUM_BYTES_ARRAY_HEADER;
for (String value : values) {
size += RamUsage.NUM_BYTES_OBJECT_HEADER + value.length() * RamUsage.NUM_BYTES_CHAR + (3 * RamUsage.NUM_BYTES_INT);
}
return size;
}
abstract public String value(int docId); abstract public String value(int docId);
abstract public String[] values(int docId); abstract public String[] values(int docId);

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.mapper.xcontent.geo; package org.elasticsearch.index.mapper.xcontent.geo;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.common.trove.TDoubleArrayList; import org.elasticsearch.common.trove.TDoubleArrayList;
import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.FieldData;
@ -67,6 +68,11 @@ public abstract class GeoPointFieldData extends FieldData<GeoPointDocFieldData>
return super.docFieldData(docId); return super.docFieldData(docId);
} }
@Override protected long computeSizeInBytes() {
return (RamUsage.NUM_BYTES_DOUBLE * lat.length + RamUsage.NUM_BYTES_ARRAY_HEADER) +
(RamUsage.NUM_BYTES_DOUBLE * lon.length + RamUsage.NUM_BYTES_ARRAY_HEADER);
}
@Override public String stringValue(int docId) { @Override public String stringValue(int docId) {
return value(docId).geohash(); return value(docId).geohash();
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.mapper.xcontent.geo; package org.elasticsearch.index.mapper.xcontent.geo;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
import org.elasticsearch.index.search.geo.GeoHashUtils; import org.elasticsearch.index.search.geo.GeoHashUtils;
@ -64,11 +65,20 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
}; };
// order with value 0 indicates no value // order with value 0 indicates no value
private final int[][] order; private final int[][] ordinals;
public MultiValueGeoPointFieldData(String fieldName, int[][] order, double[] lat, double[] lon) { public MultiValueGeoPointFieldData(String fieldName, int[][] ordinals, double[] lat, double[] lon) {
super(fieldName, lat, lon); super(fieldName, lat, lon);
this.order = order; this.ordinals = ordinals;
}
@Override protected long computeSizeInBytes() {
long size = super.computeSizeInBytes();
size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array
for (int[] ordinal : ordinals) {
size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
}
return size;
} }
@Override public boolean multiValued() { @Override public boolean multiValued() {
@ -76,11 +86,11 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public boolean hasValue(int docId) { @Override public boolean hasValue(int docId) {
return order[docId] != null; return ordinals[docId] != null;
} }
@Override public void forEachValueInDoc(int docId, StringValueInDocProc proc) { @Override public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
int[] docOrders = order[docId]; int[] docOrders = ordinals[docId];
if (docOrders == null) { if (docOrders == null) {
return; return;
} }
@ -90,7 +100,7 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public GeoPoint value(int docId) { @Override public GeoPoint value(int docId) {
int[] docOrders = order[docId]; int[] docOrders = ordinals[docId];
if (docOrders == null) { if (docOrders == null) {
return null; return null;
} }
@ -101,7 +111,7 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public GeoPoint[] values(int docId) { @Override public GeoPoint[] values(int docId) {
int[] docOrders = order[docId]; int[] docOrders = ordinals[docId];
if (docOrders == null) { if (docOrders == null) {
return EMPTY_ARRAY; return EMPTY_ARRAY;
} }
@ -123,7 +133,7 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public double latValue(int docId) { @Override public double latValue(int docId) {
int[] docOrders = order[docId]; int[] docOrders = ordinals[docId];
if (docOrders == null) { if (docOrders == null) {
return 0; return 0;
} }
@ -131,7 +141,7 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public double lonValue(int docId) { @Override public double lonValue(int docId) {
int[] docOrders = order[docId]; int[] docOrders = ordinals[docId];
if (docOrders == null) { if (docOrders == null) {
return 0; return 0;
} }
@ -139,7 +149,7 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public double[] latValues(int docId) { @Override public double[] latValues(int docId) {
int[] docOrders = order[docId]; int[] docOrders = ordinals[docId];
if (docOrders == null) { if (docOrders == null) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
} }
@ -156,7 +166,7 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public double[] lonValues(int docId) { @Override public double[] lonValues(int docId) {
int[] docOrders = order[docId]; int[] docOrders = ordinals[docId];
if (docOrders == null) { if (docOrders == null) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.mapper.xcontent.geo; package org.elasticsearch.index.mapper.xcontent.geo;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.field.data.doubles.DoubleFieldData;
import org.elasticsearch.index.search.geo.GeoHashUtils; import org.elasticsearch.index.search.geo.GeoHashUtils;
@ -50,11 +51,16 @@ public class SingleValueGeoPointFieldData extends GeoPointFieldData {
// order with value 0 indicates no value // order with value 0 indicates no value
private final int[] order; private final int[] ordinals;
public SingleValueGeoPointFieldData(String fieldName, int[] order, double[] lat, double[] lon) { public SingleValueGeoPointFieldData(String fieldName, int[] ordinals, double[] lat, double[] lon) {
super(fieldName, lat, lon); super(fieldName, lat, lon);
this.order = order; this.ordinals = ordinals;
}
@Override protected long computeSizeInBytes() {
return super.computeSizeInBytes() +
RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER;
} }
@Override public boolean multiValued() { @Override public boolean multiValued() {
@ -62,11 +68,11 @@ public class SingleValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public boolean hasValue(int docId) { @Override public boolean hasValue(int docId) {
return order[docId] != 0; return ordinals[docId] != 0;
} }
@Override public void forEachValueInDoc(int docId, StringValueInDocProc proc) { @Override public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
int loc = order[docId]; int loc = ordinals[docId];
if (loc == 0) { if (loc == 0) {
return; return;
} }
@ -74,7 +80,7 @@ public class SingleValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public GeoPoint value(int docId) { @Override public GeoPoint value(int docId) {
int loc = order[docId]; int loc = ordinals[docId];
if (loc == 0) { if (loc == 0) {
return null; return null;
} }
@ -84,7 +90,7 @@ public class SingleValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public GeoPoint[] values(int docId) { @Override public GeoPoint[] values(int docId) {
int loc = order[docId]; int loc = ordinals[docId];
if (loc == 0) { if (loc == 0) {
return EMPTY_ARRAY; return EMPTY_ARRAY;
} }
@ -94,15 +100,15 @@ public class SingleValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public double latValue(int docId) { @Override public double latValue(int docId) {
return lat[order[docId]]; return lat[ordinals[docId]];
} }
@Override public double lonValue(int docId) { @Override public double lonValue(int docId) {
return lon[order[docId]]; return lon[ordinals[docId]];
} }
@Override public double[] latValues(int docId) { @Override public double[] latValues(int docId) {
int loc = order[docId]; int loc = ordinals[docId];
if (loc == 0) { if (loc == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
} }
@ -112,7 +118,7 @@ public class SingleValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public double[] lonValues(int docId) { @Override public double[] lonValues(int docId) {
int loc = order[docId]; int loc = ordinals[docId];
if (loc == 0) { if (loc == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
} }

View File

@ -38,11 +38,14 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
private ByteSizeValue storeSize; private ByteSizeValue storeSize;
private ByteSizeValue fieldCacheSize;
IndicesStats() { IndicesStats() {
} }
public IndicesStats(ByteSizeValue storeSize) { public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize) {
this.storeSize = storeSize; this.storeSize = storeSize;
this.fieldCacheSize = fieldCacheSize;
} }
/** /**
@ -59,6 +62,14 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
return storeSize; return storeSize;
} }
public ByteSizeValue fieldCacheSize() {
return this.fieldCacheSize;
}
public ByteSizeValue getFieldCacheSize() {
return this.fieldCacheSize;
}
public static IndicesStats readIndicesStats(StreamInput in) throws IOException { public static IndicesStats readIndicesStats(StreamInput in) throws IOException {
IndicesStats stats = new IndicesStats(); IndicesStats stats = new IndicesStats();
stats.readFrom(in); stats.readFrom(in);
@ -67,16 +78,20 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
@Override public void readFrom(StreamInput in) throws IOException { @Override public void readFrom(StreamInput in) throws IOException {
storeSize = ByteSizeValue.readBytesSizeValue(in); storeSize = ByteSizeValue.readBytesSizeValue(in);
fieldCacheSize = ByteSizeValue.readBytesSizeValue(in);
} }
@Override public void writeTo(StreamOutput out) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException {
storeSize.writeTo(out); storeSize.writeTo(out);
fieldCacheSize.writeTo(out);
} }
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("indices"); builder.startObject("indices");
builder.field("store_size", storeSize.toString()); builder.field("store_size", storeSize.toString());
builder.field("store_size_in_bytes", storeSize.bytes()); builder.field("store_size_in_bytes", storeSize.bytes());
builder.field("field_cache_size", fieldCacheSize.toString());
builder.field("field_cache_size_in_bytes", fieldCacheSize.bytes());
builder.endObject(); builder.endObject();
} }
} }

View File

@ -155,17 +155,19 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
} }
@Override public IndicesStats stats() { @Override public IndicesStats stats() {
long totalSize = 0; long storeTotalSize = 0;
long fieldCacheTotalSize = 0;
for (IndexService indexService : indices.values()) { for (IndexService indexService : indices.values()) {
for (IndexShard indexShard : indexService) { for (IndexShard indexShard : indexService) {
try { try {
totalSize += ((InternalIndexShard) indexShard).store().estimateSize().bytes(); storeTotalSize += ((InternalIndexShard) indexShard).store().estimateSize().bytes();
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
} }
fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes();
} }
return new IndicesStats(new ByteSizeValue(totalSize)); return new IndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize));
} }
/** /**