mirror of
https://github.com/apache/lucene.git
synced 2025-03-07 08:49:18 +00:00
Fix ram estimate and its test for PackedInts.NullReader singleton (#13250)
Correct estimate for singleton to return `0` and use custom accumulator in tests to fix assertions. Tried not doing this in #13232 but turns out we need a little complexity here since the singleton is recognized by the `RamUsageTester` in so far that is only counted once if it shows up repeatedly in an array or so. fixes #13249
This commit is contained in:
parent
e2110e0b8e
commit
42f2da5fe2
@ -604,7 +604,9 @@ public class PackedInts {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long ramBytesUsed() {
|
public long ramBytesUsed() {
|
||||||
return RamUsageEstimator.alignObjectSize(
|
return valueCount == PackedLongValues.DEFAULT_PAGE_SIZE
|
||||||
|
? 0
|
||||||
|
: RamUsageEstimator.alignObjectSize(
|
||||||
RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + Integer.BYTES);
|
RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + Integer.BYTES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,15 @@ package org.apache.lucene.util.packed;
|
|||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
|
import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.LongBuffer;
|
import java.nio.LongBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.apache.lucene.store.ByteArrayDataInput;
|
import org.apache.lucene.store.ByteArrayDataInput;
|
||||||
import org.apache.lucene.store.DataInput;
|
import org.apache.lucene.store.DataInput;
|
||||||
@ -966,6 +969,18 @@ public class TestPackedInts extends LuceneTestCase {
|
|||||||
.ramBytesUsed());
|
.ramBytesUsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class IgnoreNullReaderSingletonAccumulator
|
||||||
|
extends RamUsageTester.Accumulator {
|
||||||
|
@Override
|
||||||
|
public long accumulateObject(
|
||||||
|
Object o, long shallowSize, Map<Field, Object> fieldValues, Collection<Object> queue) {
|
||||||
|
if (o == PackedInts.NullReader.forCount(PackedLongValues.DEFAULT_PAGE_SIZE)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return super.accumulateObject(o, shallowSize, fieldValues, queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testPackedLongValues() {
|
public void testPackedLongValues() {
|
||||||
final long[] arr =
|
final long[] arr =
|
||||||
new long[RandomNumbers.randomIntBetween(random(), 1, TEST_NIGHTLY ? 1000000 : 10000)];
|
new long[RandomNumbers.randomIntBetween(random(), 1, TEST_NIGHTLY ? 1000000 : 10000)];
|
||||||
@ -1017,7 +1032,8 @@ public class TestPackedInts extends LuceneTestCase {
|
|||||||
for (int i = 0; i < arr.length; ++i) {
|
for (int i = 0; i < arr.length; ++i) {
|
||||||
buf.add(arr[i]);
|
buf.add(arr[i]);
|
||||||
if (rarely() && !TEST_NIGHTLY) {
|
if (rarely() && !TEST_NIGHTLY) {
|
||||||
final long expectedBytesUsed = RamUsageTester.ramUsed(buf);
|
final long expectedBytesUsed =
|
||||||
|
RamUsageTester.ramUsed(buf, new IgnoreNullReaderSingletonAccumulator());
|
||||||
final long computedBytesUsed = buf.ramBytesUsed();
|
final long computedBytesUsed = buf.ramBytesUsed();
|
||||||
assertEquals(expectedBytesUsed, computedBytesUsed);
|
assertEquals(expectedBytesUsed, computedBytesUsed);
|
||||||
}
|
}
|
||||||
@ -1044,7 +1060,8 @@ public class TestPackedInts extends LuceneTestCase {
|
|||||||
}
|
}
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
|
|
||||||
final long expectedBytesUsed = RamUsageTester.ramUsed(values);
|
final long expectedBytesUsed =
|
||||||
|
RamUsageTester.ramUsed(values, new IgnoreNullReaderSingletonAccumulator());
|
||||||
final long computedBytesUsed = values.ramBytesUsed();
|
final long computedBytesUsed = values.ramBytesUsed();
|
||||||
assertEquals(expectedBytesUsed, computedBytesUsed);
|
assertEquals(expectedBytesUsed, computedBytesUsed);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user