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(); Script getScriptValues();
/**
* Close the field data.
*/
void close();
interface WithOrdinals<Script extends ScriptDocValues> extends AtomicFieldData<Script> { 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) { public void onUnload(Index index, FieldMapper.Names fieldNames, FieldDataType fieldDataType, boolean wasEvicted, @Nullable AtomicFieldData fieldData) {
assert index.equals(this.index); assert index.equals(this.index);
if (fieldData != null) { if (fieldData != null) {
fieldData.close();
memoryUsedInBytes.dec(fieldData.getMemorySizeInBytes()); memoryUsedInBytes.dec(fieldData.getMemorySizeInBytes());
} }
if (wasEvicted) { if (wasEvicted) {

View File

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

View File

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

View File

@ -44,6 +44,10 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
this.numDocs = numDocs; this.numDocs = numDocs;
} }
@Override
public void close() {
}
@Override @Override
public int getNumDocs() { public int getNumDocs() {
return numDocs; return numDocs;
@ -508,6 +512,7 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values, set); return new LongValues(values, set);
} }
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, set); 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.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage; import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData; import org.elasticsearch.index.fielddata.*;
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.ordinals.Ordinals; import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef; import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef; import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -49,6 +43,10 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
this.numDocs = numDocs; this.numDocs = numDocs;
} }
@Override
public void close() {
}
@Override @Override
public int getNumDocs() { public int getNumDocs() {
return numDocs; return numDocs;
@ -147,7 +145,7 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.DoubleBased(getDoubleValues()); return new StringValues.DoubleBased(getDoubleValues());
} }
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericDouble(getDoubleValues()); return new ScriptDocValues.NumericDouble(getDoubleValues());

View File

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

View File

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

View File

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

View File

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

View File

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