Apache Lucene open-source search software
LUCENE-5443: DocValuesProducer.ramBytesUsed throws ConcurrentModificationException
Shai Ererab1658e5d7c47
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 766cc28daa3..5ebe29b7d57 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -263,6 +263,9 @@ Bug fixesloop. ReferenceManager now throws IllegalStateException if currently managedresources ref count is 0. (Simon Willnauer)+* LUCENE-5443: Lucene45DocValuesProducer.ramBytesUsed() may throw+ ConcurrentModificationException. (Shai Erera, Simon Willnauer)+API Changes* LUCENE-5339: The facet module was simplified/reworked to make thediff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesProducer.javaindex 2316fc5798e..5671bc0222e 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesProducer.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesProducer.java@@ -31,6 +31,7 @@ import java.io.Closeable; // javadocsimport java.io.IOException;import java.util.HashMap;import java.util.Map;+import java.util.concurrent.atomic.AtomicLong;import org.apache.lucene.codecs.CodecUtil;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.IOUtils;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.MonotonicBlockPackedReader;import org.apache.lucene.util.packed.PackedInts;@@ -64,6 +66,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Closprivate final Map<Integer,SortedSetEntry> sortedSets;private final Map<Integer,NumericEntry> ords;private final Map<Integer,NumericEntry> ordIndexes;+ private final AtomicLong ramBytesUsed;private final IndexInput data;private final int maxDoc;private final int version;@@ -116,6 +119,8 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements ClosIOUtils.closeWhileHandlingException(this.data);}}++ ramBytesUsed = new AtomicLong(RamUsageEstimator.shallowSizeOfInstance(getClass()));}private void readSortedField(int fieldNumber, IndexInput meta, FieldInfos infos) throws IOException {@@ -286,14 +291,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos@Overridepublic long ramBytesUsed() {- long sizeInBytes = 0;- for(MonotonicBlockPackedReader monotonicBlockPackedReader: addressInstances.values()) {- sizeInBytes += Integer.SIZE + monotonicBlockPackedReader.ramBytesUsed();- }- for(MonotonicBlockPackedReader monotonicBlockPackedReader: ordIndexInstances.values()) {- sizeInBytes += Integer.SIZE + monotonicBlockPackedReader.ramBytesUsed();- }- return sizeInBytes;+ return ramBytesUsed.get();}LongValues getNumeric(NumericEntry entry) throws IOException {@@ -377,6 +375,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Closdata.seek(bytes.addressesOffset);addrInstance = new MonotonicBlockPackedReader(data, bytes.packedIntsVersion, bytes.blockSize, bytes.count, false);addressInstances.put(field.number, addrInstance);+ ramBytesUsed.addAndGet(addrInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT);}addresses = addrInstance;}@@ -427,6 +426,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos}addrInstance = new MonotonicBlockPackedReader(data, bytes.packedIntsVersion, bytes.blockSize, size, false);addressInstances.put(field.number, addrInstance);+ ramBytesUsed.addAndGet(addrInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT);}addresses = addrInstance;}@@ -498,6 +498,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Closdata.seek(entry.offset);ordIndexInstance = new MonotonicBlockPackedReader(data, entry.packedIntsVersion, entry.blockSize, entry.count, false);ordIndexInstances.put(field.number, ordIndexInstance);+ ramBytesUsed.addAndGet(ordIndexInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT);}ordIndex = ordIndexInstance;}