LUCENE-5443: DocValuesProducer.ramBytesUsed throws ConcurrentModificationException

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1567954 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2014-02-13 15:45:02 +00:00
parent 6d9228fc83
commit b1658e5d7c
2 changed files with 12 additions and 8 deletions

View File

@ -263,6 +263,9 @@ Bug fixes
loop. ReferenceManager now throws IllegalStateException if currently managed loop. ReferenceManager now throws IllegalStateException if currently managed
resources ref count is 0. (Simon Willnauer) resources ref count is 0. (Simon Willnauer)
* LUCENE-5443: Lucene45DocValuesProducer.ramBytesUsed() may throw
ConcurrentModificationException. (Shai Erera, Simon Willnauer)
API Changes API Changes
* LUCENE-5339: The facet module was simplified/reworked to make the * LUCENE-5339: The facet module was simplified/reworked to make the

View File

@ -31,6 +31,7 @@ import java.io.Closeable; // javadocs
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesProducer; import org.apache.lucene.codecs.DocValuesProducer;
@ -53,6 +54,7 @@ import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LongValues; import org.apache.lucene.util.LongValues;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.packed.BlockPackedReader; import org.apache.lucene.util.packed.BlockPackedReader;
import org.apache.lucene.util.packed.MonotonicBlockPackedReader; import org.apache.lucene.util.packed.MonotonicBlockPackedReader;
import org.apache.lucene.util.packed.PackedInts; import org.apache.lucene.util.packed.PackedInts;
@ -64,6 +66,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
private final Map<Integer,SortedSetEntry> sortedSets; private final Map<Integer,SortedSetEntry> sortedSets;
private final Map<Integer,NumericEntry> ords; private final Map<Integer,NumericEntry> ords;
private final Map<Integer,NumericEntry> ordIndexes; private final Map<Integer,NumericEntry> ordIndexes;
private final AtomicLong ramBytesUsed;
private final IndexInput data; private final IndexInput data;
private final int maxDoc; private final int maxDoc;
private final int version; private final int version;
@ -116,6 +119,8 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
IOUtils.closeWhileHandlingException(this.data); IOUtils.closeWhileHandlingException(this.data);
} }
} }
ramBytesUsed = new AtomicLong(RamUsageEstimator.shallowSizeOfInstance(getClass()));
} }
private void readSortedField(int fieldNumber, IndexInput meta, FieldInfos infos) throws IOException { private void readSortedField(int fieldNumber, IndexInput meta, FieldInfos infos) throws IOException {
@ -286,14 +291,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
@Override @Override
public long ramBytesUsed() { public long ramBytesUsed() {
long sizeInBytes = 0; return ramBytesUsed.get();
for(MonotonicBlockPackedReader monotonicBlockPackedReader: addressInstances.values()) {
sizeInBytes += Integer.SIZE + monotonicBlockPackedReader.ramBytesUsed();
}
for(MonotonicBlockPackedReader monotonicBlockPackedReader: ordIndexInstances.values()) {
sizeInBytes += Integer.SIZE + monotonicBlockPackedReader.ramBytesUsed();
}
return sizeInBytes;
} }
LongValues getNumeric(NumericEntry entry) throws IOException { LongValues getNumeric(NumericEntry entry) throws IOException {
@ -377,6 +375,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
data.seek(bytes.addressesOffset); data.seek(bytes.addressesOffset);
addrInstance = new MonotonicBlockPackedReader(data, bytes.packedIntsVersion, bytes.blockSize, bytes.count, false); addrInstance = new MonotonicBlockPackedReader(data, bytes.packedIntsVersion, bytes.blockSize, bytes.count, false);
addressInstances.put(field.number, addrInstance); addressInstances.put(field.number, addrInstance);
ramBytesUsed.addAndGet(addrInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT);
} }
addresses = addrInstance; addresses = addrInstance;
} }
@ -427,6 +426,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
} }
addrInstance = new MonotonicBlockPackedReader(data, bytes.packedIntsVersion, bytes.blockSize, size, false); addrInstance = new MonotonicBlockPackedReader(data, bytes.packedIntsVersion, bytes.blockSize, size, false);
addressInstances.put(field.number, addrInstance); addressInstances.put(field.number, addrInstance);
ramBytesUsed.addAndGet(addrInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT);
} }
addresses = addrInstance; addresses = addrInstance;
} }
@ -498,6 +498,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
data.seek(entry.offset); data.seek(entry.offset);
ordIndexInstance = new MonotonicBlockPackedReader(data, entry.packedIntsVersion, entry.blockSize, entry.count, false); ordIndexInstance = new MonotonicBlockPackedReader(data, entry.packedIntsVersion, entry.blockSize, entry.count, false);
ordIndexInstances.put(field.number, ordIndexInstance); ordIndexInstances.put(field.number, ordIndexInstance);
ramBytesUsed.addAndGet(ordIndexInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT);
} }
ordIndex = ordIndexInstance; ordIndex = ordIndexInstance;
} }