add close method to field data

This commit is contained in:
Shay Banon 2013-03-04 16:42:29 -08:00
parent cfd8bddde4
commit d609571897
11 changed files with 52 additions and 31 deletions

View File

@ -64,6 +64,11 @@ public interface AtomicFieldData<Script extends ScriptDocValues> {
*/
Script getScriptValues();
/**
* Close the field data.
*/
void close();
interface WithOrdinals<Script extends ScriptDocValues> extends AtomicFieldData<Script> {
/**

View File

@ -121,6 +121,7 @@ public class IndexFieldDataService extends AbstractIndexComponent implements Ind
public void onUnload(Index index, FieldMapper.Names fieldNames, FieldDataType fieldDataType, boolean wasEvicted, @Nullable AtomicFieldData fieldData) {
assert index.equals(this.index);
if (fieldData != null) {
fieldData.close();
memoryUsedInBytes.dec(fieldData.getMemorySizeInBytes());
}
if (wasEvicted) {

View File

@ -21,13 +21,7 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -54,6 +48,11 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
return numDocs;
}
@Override
public void close() {
}
static class Empty extends ByteArrayAtomicFieldData {
Empty() {
@ -611,7 +610,7 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
public LongValues getLongValues() {
return new LongValues(values);
}
@Override
public DoubleValues getDoubleValues() {
return new DoubleValues(values);

View File

@ -50,6 +50,10 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicFieldData.WithOrdi
this.ordinals = ordinals;
}
@Override
public void close() {
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();

View File

@ -44,6 +44,10 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
this.numDocs = numDocs;
}
@Override
public void close() {
}
@Override
public int getNumDocs() {
return numDocs;
@ -508,6 +512,7 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
public LongValues getLongValues() {
return new LongValues(values, set);
}
@Override
public DoubleValues getDoubleValues() {
return new DoubleValues(values, set);

View File

@ -21,13 +21,7 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -49,6 +43,10 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
this.numDocs = numDocs;
}
@Override
public void close() {
}
@Override
public int getNumDocs() {
return numDocs;
@ -147,7 +145,7 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
public StringValues getStringValues() {
return new StringValues.DoubleBased(getDoubleValues());
}
@Override
public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericDouble(getDoubleValues());

View File

@ -47,6 +47,10 @@ public abstract class GeoPointDoubleArrayAtomicFieldData implements AtomicGeoPoi
this.numDocs = numDocs;
}
@Override
public void close() {
}
@Override
public int getNumDocs() {
return numDocs;

View File

@ -43,6 +43,10 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
this.numDocs = numDocs;
}
@Override
public void close() {
}
@Override
public int getNumDocs() {
return numDocs;
@ -156,7 +160,7 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
public DoubleValues getDoubleValues() {
return new DoubleValues(values, ordinals.ordinals());
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final int[] values;

View File

@ -21,13 +21,7 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -50,6 +44,10 @@ public abstract class LongArrayAtomicFieldData implements AtomicNumericFieldData
this.numDocs = numDocs;
}
@Override
public void close() {
}
@Override
public int getNumDocs() {
return numDocs;
@ -158,6 +156,7 @@ public abstract class LongArrayAtomicFieldData implements AtomicNumericFieldData
public LongValues getLongValues() {
return new LongValues(values, ordinals.ordinals());
}
@Override
public DoubleValues getDoubleValues() {
return new DoubleValues(values, ordinals.ordinals());

View File

@ -55,6 +55,10 @@ public class PagedBytesAtomicFieldData implements AtomicFieldData.WithOrdinals<S
this.ordinals = ordinals;
}
@Override
public void close() {
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();

View File

@ -21,13 +21,7 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -49,6 +43,10 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
this.numDocs = numDocs;
}
@Override
public void close() {
}
@Override
public int getNumDocs() {
return numDocs;