Skip to content

Commit 9d07a11

Browse files
authored
IVFVectorsFormat doesn't report off-heap stats at the moment (#130553)
1 parent bb122b4 commit 9d07a11

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

server/src/test/java/org/elasticsearch/index/codec/vectors/IVFVectorsFormatTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import static java.lang.String.format;
3939
import static org.elasticsearch.index.codec.vectors.IVFVectorsFormat.MAX_VECTORS_PER_CLUSTER;
4040
import static org.elasticsearch.index.codec.vectors.IVFVectorsFormat.MIN_VECTORS_PER_CLUSTER;
41+
import static org.hamcrest.Matchers.anEmptyMap;
42+
import static org.hamcrest.Matchers.equalTo;
4143
import static org.hamcrest.Matchers.is;
4244
import static org.hamcrest.Matchers.oneOf;
4345

@@ -83,6 +85,25 @@ protected Codec getCodec() {
8385
return TestUtil.alwaysKnnVectorsFormat(format);
8486
}
8587

88+
@Override
89+
protected void assertOffHeapByteSize(LeafReader r, String fieldName) throws IOException {
90+
var fieldInfo = r.getFieldInfos().fieldInfo(fieldName);
91+
92+
if (r instanceof CodecReader codecReader) {
93+
KnnVectorsReader knnVectorsReader = codecReader.getVectorReader();
94+
if (knnVectorsReader instanceof PerFieldKnnVectorsFormat.FieldsReader fieldsReader) {
95+
knnVectorsReader = fieldsReader.getFieldReader(fieldName);
96+
}
97+
var offHeap = knnVectorsReader.getOffHeapByteSize(fieldInfo);
98+
long totalByteSize = offHeap.values().stream().mapToLong(Long::longValue).sum();
99+
// IVF doesn't report stats at the moment
100+
assertThat(offHeap, anEmptyMap());
101+
assertThat(totalByteSize, equalTo(0L));
102+
} else {
103+
throw new AssertionError("unexpected:" + r.getClass());
104+
}
105+
}
106+
86107
@Override
87108
public void testAdvance() throws Exception {
88109
// TODO re-enable with hierarchical IVF, clustering as it is is flaky

0 commit comments

Comments
 (0)