Skip to content

Commit 943990e

Browse files
authored
Add OffHeapBytesSizes for Stats (#138433)
* added in off heaps bytes sizes for stats endpoints
1 parent eb20ffa commit 943990e

File tree

11 files changed

+192
-52
lines changed

11 files changed

+192
-52
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/220_dense_vector_node_index_stats.yml

Lines changed: 148 additions & 1 deletion
Large diffs are not rendered by default.

server/src/main/java/org/elasticsearch/index/codec/vectors/diskbbq/ES920DiskBBQVectorsReader.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.simdvec.ESVectorUtil;
2828

2929
import java.io.IOException;
30-
import java.util.Map;
3130

3231
import static org.apache.lucene.codecs.lucene102.Lucene102BinaryQuantizedVectorsFormat.QUERY_BITS;
3332
import static org.apache.lucene.index.VectorSimilarityFunction.COSINE;
@@ -394,11 +393,6 @@ public PostingVisitor getPostingVisitor(FieldInfo fieldInfo, IndexInput indexInp
394393
return new MemorySegmentPostingsVisitor(target, indexInput, entry, fieldInfo, acceptDocs);
395394
}
396395

397-
@Override
398-
public Map<String, Long> getOffHeapByteSize(FieldInfo fieldInfo) {
399-
return Map.of();
400-
}
401-
402396
private static class MemorySegmentPostingsVisitor implements PostingVisitor {
403397
final long quantizedByteLength;
404398
final IndexInput indexInput;

server/src/main/java/org/elasticsearch/index/codec/vectors/diskbbq/IVFVectorsReader.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import java.util.Map;
4343

4444
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsReader.SIMILARITY_FUNCTIONS;
45+
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.CENTROID_EXTENSION;
46+
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.CLUSTER_EXTENSION;
4547
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.DYNAMIC_VISIT_RATIO;
4648
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.VERSION_DIRECT_IO;
4749

@@ -87,20 +89,8 @@ protected IVFVectorsReader(SegmentReadState state, GenericFlatVectorReaders.Load
8789
} finally {
8890
CodecUtil.checkFooter(ivfMeta, priorE);
8991
}
90-
ivfCentroids = openDataInput(
91-
state,
92-
versionMeta,
93-
ES920DiskBBQVectorsFormat.CENTROID_EXTENSION,
94-
ES920DiskBBQVectorsFormat.NAME,
95-
state.context
96-
);
97-
ivfClusters = openDataInput(
98-
state,
99-
versionMeta,
100-
ES920DiskBBQVectorsFormat.CLUSTER_EXTENSION,
101-
ES920DiskBBQVectorsFormat.NAME,
102-
state.context
103-
);
92+
ivfCentroids = openDataInput(state, versionMeta, CENTROID_EXTENSION, ES920DiskBBQVectorsFormat.NAME, state.context);
93+
ivfClusters = openDataInput(state, versionMeta, CLUSTER_EXTENSION, ES920DiskBBQVectorsFormat.NAME, state.context);
10494
success = true;
10595
} finally {
10696
if (success == false) {
@@ -388,12 +378,9 @@ public Map<String, Long> getOffHeapByteSize(FieldInfo fieldInfo) {
388378
assert fieldInfo.getVectorEncoding() == VectorEncoding.BYTE;
389379
return raw;
390380
}
391-
return raw; // for now just return the size of raw
392381

393-
// TODO: determine desired off off-heap requirements
394-
// var centroids = Map.of(EXTENSION, fe.xxxLength());
395-
// var clusters = Map.of(EXTENSION, fe.yyyLength());
396-
// return KnnVectorsReader.mergeOffHeapByteSizeMaps(raw, centroids, clusters);
382+
var centroidsClusters = Map.of(CENTROID_EXTENSION, fe.centroidLength, CLUSTER_EXTENSION, fe.postingListLength);
383+
return KnnVectorsReader.mergeOffHeapByteSizeMaps(raw, centroidsClusters);
397384
}
398385

399386
@Override

server/src/main/java/org/elasticsearch/index/codec/vectors/diskbbq/next/ESNextDiskBBQVectorsReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ public PostingVisitor getPostingVisitor(FieldInfo fieldInfo, IndexInput indexInp
541541

542542
@Override
543543
public Map<String, Long> getOffHeapByteSize(FieldInfo fieldInfo) {
544-
return Map.of();
544+
// TODO: override if adding new files
545+
return super.getOffHeapByteSize(fieldInfo);
545546
}
546547

547548
private static class MemorySegmentPostingsVisitor implements PostingVisitor {

server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class MapperFeatures implements FeatureSpecification {
6363
static final NodeFeature BASE64_DENSE_VECTORS = new NodeFeature("mapper.base64_dense_vectors");
6464
public static final NodeFeature GENERIC_VECTOR_FORMAT = new NodeFeature("mapper.vectors.generic_vector_format");
6565
public static final NodeFeature FIX_DENSE_VECTOR_WRONG_FIELDS = new NodeFeature("mapper.fix_dense_vector_wrong_fields");
66+
static final NodeFeature BBQ_DISK_STATS_SUPPORT = new NodeFeature("mapper.bbq_disk_stats_support");
6667

6768
@Override
6869
public Set<NodeFeature> getTestFeatures() {
@@ -106,7 +107,8 @@ public Set<NodeFeature> getTestFeatures() {
106107
INDEX_MAPPING_IGNORE_DYNAMIC_BEYOND_FIELD_NAME_LIMIT,
107108
EXCLUDE_VECTORS_DOCVALUE_BUGFIX,
108109
BASE64_DENSE_VECTORS,
109-
FIX_DENSE_VECTOR_WRONG_FIELDS
110+
FIX_DENSE_VECTOR_WRONG_FIELDS,
111+
BBQ_DISK_STATS_SUPPORT
110112
);
111113
if (ES93GenericFlatVectorsFormat.GENERIC_VECTOR_FORMAT.isEnabled()) {
112114
features = new HashSet<>(features);

server/src/main/java/org/elasticsearch/index/shard/DenseVectorStats.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public Map<String, Map<String, Long>> offHeapStats() {
112112

113113
private Map<String, Long> getTotalsByCategory() {
114114
if (offHeapStats == null) {
115-
return Map.of("veb", 0L, "vec", 0L, "veq", 0L, "vex", 0L);
115+
return Map.of("veb", 0L, "vec", 0L, "veq", 0L, "vex", 0L, "cenivf", 0L, "clivf", 0L);
116116
} else {
117117
return offHeapStats.entrySet()
118118
.stream()
@@ -140,6 +140,8 @@ private void toXContentWithFields(XContentBuilder builder, Params params) throws
140140
builder.humanReadableField("total_vec_size_bytes", "total_vec_size", ofBytes(totals.getOrDefault("vec", 0L)));
141141
builder.humanReadableField("total_veq_size_bytes", "total_veq_size", ofBytes(totals.getOrDefault("veq", 0L)));
142142
builder.humanReadableField("total_vex_size_bytes", "total_vex_size", ofBytes(totals.getOrDefault("vex", 0L)));
143+
builder.humanReadableField("total_cenivf_size_bytes", "total_cenivf_size", ofBytes(totals.getOrDefault("cenivf", 0L)));
144+
builder.humanReadableField("total_clivf_size_bytes", "total_clivf_size", ofBytes(totals.getOrDefault("clivf", 0L)));
143145
if (params.paramAsBoolean(INCLUDE_PER_FIELD_STATS, false) && offHeapStats != null && offHeapStats.size() > 0) {
144146
toXContentWithPerFieldStats(builder);
145147
}

server/src/test/java/org/elasticsearch/index/codec/vectors/diskbbq/ES920DiskBBQBFloat16VectorsFormatTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.MIN_CENTROIDS_PER_PARENT_CLUSTER;
3232
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.MIN_VECTORS_PER_CLUSTER;
33-
import static org.hamcrest.Matchers.anEmptyMap;
3433
import static org.hamcrest.Matchers.equalTo;
3534

3635
public class ES920DiskBBQBFloat16VectorsFormatTests extends BaseBFloat16KnnVectorsFormatTestCase {
@@ -102,9 +101,8 @@ protected void assertOffHeapByteSize(LeafReader r, String fieldName) throws IOEx
102101
}
103102
var offHeap = knnVectorsReader.getOffHeapByteSize(fieldInfo);
104103
long totalByteSize = offHeap.values().stream().mapToLong(Long::longValue).sum();
105-
// IVF doesn't report stats at the moment
106-
assertThat(offHeap, anEmptyMap());
107-
assertThat(totalByteSize, equalTo(0L));
104+
assertThat(offHeap.size(), equalTo(3));
105+
assertThat(totalByteSize, equalTo(offHeap.values().stream().mapToLong(Long::longValue).sum()));
108106
} else {
109107
throw new AssertionError("unexpected:" + r.getClass());
110108
}

server/src/test/java/org/elasticsearch/index/codec/vectors/diskbbq/ES920DiskBBQVectorsFormatTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.MAX_VECTORS_PER_CLUSTER;
5050
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.MIN_CENTROIDS_PER_PARENT_CLUSTER;
5151
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.MIN_VECTORS_PER_CLUSTER;
52-
import static org.hamcrest.Matchers.anEmptyMap;
5352
import static org.hamcrest.Matchers.equalTo;
5453
import static org.hamcrest.Matchers.hasToString;
5554

@@ -122,9 +121,8 @@ protected void assertOffHeapByteSize(LeafReader r, String fieldName) throws IOEx
122121
}
123122
var offHeap = knnVectorsReader.getOffHeapByteSize(fieldInfo);
124123
long totalByteSize = offHeap.values().stream().mapToLong(Long::longValue).sum();
125-
// IVF doesn't report stats at the moment
126-
assertThat(offHeap, anEmptyMap());
127-
assertThat(totalByteSize, equalTo(0L));
124+
assertThat(offHeap.size(), equalTo(3));
125+
assertThat(totalByteSize, equalTo(offHeap.values().stream().mapToLong(Long::longValue).sum()));
128126
} else {
129127
throw new AssertionError("unexpected:" + r.getClass());
130128
}
@@ -164,7 +162,7 @@ public void testSimpleOffHeapSize() throws IOException {
164162
}
165163
var fieldInfo = r.getFieldInfos().fieldInfo("f");
166164
var offHeap = knnVectorsReader.getOffHeapByteSize(fieldInfo);
167-
assertEquals(0, offHeap.size());
165+
assertEquals(3, offHeap.size());
168166
}
169167
}
170168
}

server/src/test/java/org/elasticsearch/index/codec/vectors/diskbbq/next/ESNextDiskBBQBFloat16VectorsFormatTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.MIN_CENTROIDS_PER_PARENT_CLUSTER;
3333
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.MIN_VECTORS_PER_CLUSTER;
34-
import static org.hamcrest.Matchers.anEmptyMap;
3534
import static org.hamcrest.Matchers.equalTo;
3635

3736
public class ESNextDiskBBQBFloat16VectorsFormatTests extends BaseBFloat16KnnVectorsFormatTestCase {
@@ -108,9 +107,8 @@ protected void assertOffHeapByteSize(LeafReader r, String fieldName) throws IOEx
108107
}
109108
var offHeap = knnVectorsReader.getOffHeapByteSize(fieldInfo);
110109
long totalByteSize = offHeap.values().stream().mapToLong(Long::longValue).sum();
111-
// IVF doesn't report stats at the moment
112-
assertThat(offHeap, anEmptyMap());
113-
assertThat(totalByteSize, equalTo(0L));
110+
assertThat(offHeap.size(), equalTo(3));
111+
assertThat(totalByteSize, equalTo(offHeap.values().stream().mapToLong(Long::longValue).sum()));
114112
} else {
115113
throw new AssertionError("unexpected:" + r.getClass());
116114
}

server/src/test/java/org/elasticsearch/index/codec/vectors/diskbbq/next/ESNextDiskBBQVectorsFormatTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import static org.elasticsearch.index.codec.vectors.diskbbq.next.ESNextDiskBBQVectorsFormat.MAX_VECTORS_PER_CLUSTER;
5454
import static org.elasticsearch.index.codec.vectors.diskbbq.next.ESNextDiskBBQVectorsFormat.MIN_CENTROIDS_PER_PARENT_CLUSTER;
5555
import static org.elasticsearch.index.codec.vectors.diskbbq.next.ESNextDiskBBQVectorsFormat.MIN_VECTORS_PER_CLUSTER;
56-
import static org.hamcrest.Matchers.anEmptyMap;
5756
import static org.hamcrest.Matchers.equalTo;
5857
import static org.hamcrest.Matchers.is;
5958
import static org.hamcrest.Matchers.oneOf;
@@ -127,9 +126,8 @@ protected void assertOffHeapByteSize(LeafReader r, String fieldName) throws IOEx
127126
}
128127
var offHeap = knnVectorsReader.getOffHeapByteSize(fieldInfo);
129128
long totalByteSize = offHeap.values().stream().mapToLong(Long::longValue).sum();
130-
// IVF doesn't report stats at the moment
131-
assertThat(offHeap, anEmptyMap());
132-
assertThat(totalByteSize, equalTo(0L));
129+
assertThat(offHeap.size(), equalTo(3));
130+
assertThat(totalByteSize, equalTo(offHeap.values().stream().mapToLong(Long::longValue).sum()));
133131
} else {
134132
throw new AssertionError("unexpected:" + r.getClass());
135133
}
@@ -177,7 +175,7 @@ public void testSimpleOffHeapSize() throws IOException {
177175
}
178176
var fieldInfo = r.getFieldInfos().fieldInfo("f");
179177
var offHeap = knnVectorsReader.getOffHeapByteSize(fieldInfo);
180-
assertEquals(0, offHeap.size());
178+
assertEquals(3, offHeap.size());
181179
}
182180
}
183181
}

0 commit comments

Comments
 (0)