Skip to content

Commit b9071bb

Browse files
committed
Include doc value skippers in disk usage analyzer
1 parent 46fc7de commit b9071bb

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/diskusage/IndexDiskUsageAnalyzer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,16 @@ void analyzeDocValues(SegmentReader reader, IndexDiskUsageStats stats) throws IO
289289
throw new IllegalStateException("Unknown docValues type [" + dvType + "]");
290290
}
291291
}
292+
switch (field.docValuesSkipIndexType()) {
293+
case NONE -> {}
294+
case RANGE -> {
295+
var skipper = docValuesReader.getSkipper(field);
296+
while(skipper.maxDocID(0) != DocIdSetIterator.NO_MORE_DOCS) {
297+
skipper.advance(skipper.maxDocID(0) + 1);
298+
}
299+
}
300+
default -> throw new IllegalStateException("Unknown skipper type [" + field.docValuesSkipIndexType() + "]");
301+
}
292302
stats.addDocValues(field.name, directory.getBytesRead());
293303
}
294304
}

server/src/test/java/org/elasticsearch/action/admin/indices/diskusage/IndexDiskUsageAnalyzerTests.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.action.admin.indices.diskusage;
1111

12+
import org.apache.lucene.codecs.Codec;
1213
import org.apache.lucene.codecs.DocValuesFormat;
1314
import org.apache.lucene.codecs.KnnVectorsFormat;
1415
import org.apache.lucene.codecs.PostingsFormat;
@@ -67,7 +68,10 @@
6768
import org.apache.lucene.util.FixedBitSet;
6869
import org.elasticsearch.common.lucene.Lucene;
6970
import org.elasticsearch.core.IOUtils;
71+
import org.elasticsearch.index.codec.Elasticsearch900Lucene101Codec;
7072
import org.elasticsearch.index.codec.postings.ES812PostingsFormat;
73+
import org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormat;
74+
import org.elasticsearch.index.codec.zstd.Zstd814StoredFieldsFormat;
7175
import org.elasticsearch.index.shard.ShardId;
7276
import org.elasticsearch.index.store.LuceneFilesExtensions;
7377
import org.elasticsearch.test.ESTestCase;
@@ -405,6 +409,21 @@ public void testMixedFields() throws Exception {
405409
}
406410
}
407411

412+
public void testDocValuesFieldWithDocValueSkippers() throws Exception {
413+
try (Directory dir = createNewDirectory()) {
414+
var codecMode = randomFrom(CodecMode.values());
415+
indexRandomly(dir, codecMode, between(100, 1000), doc -> addRandomDocValuesField(doc, true));
416+
final IndexDiskUsageStats stats = IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(dir), () -> {});
417+
logger.info("--> stats {}", stats);
418+
try (Directory perFieldDir = createNewDirectory()) {
419+
rewriteIndexWithPerFieldCodec(dir, codecMode, perFieldDir);
420+
final IndexDiskUsageStats perFieldStats = collectPerFieldStats(perFieldDir);
421+
assertStats(stats, perFieldStats);
422+
assertStats(IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(perFieldDir), () -> {}), perFieldStats);
423+
}
424+
}
425+
}
426+
408427
private static void addFieldsToDoc(Document doc, IndexableField[] fields) {
409428
for (IndexableField field : fields) {
410429
doc.add(field);
@@ -442,23 +461,27 @@ static void indexRandomly(Directory directory, CodecMode codecMode, int numDocs,
442461
}
443462
}
444463

445-
static void addRandomDocValuesField(Document doc) {
464+
static void addRandomDocValuesField(Document doc, boolean indexed) {
446465
if (randomBoolean()) {
447-
doc.add(new NumericDocValuesField("ndv", random().nextInt(1024)));
466+
int val = random().nextInt(1024);
467+
doc.add(indexed ? NumericDocValuesField.indexedField("ndv", val) : new NumericDocValuesField("ndv", val));
448468
}
449-
if (randomBoolean()) {
469+
if (randomBoolean() && indexed == false) {
450470
doc.add(new BinaryDocValuesField("bdv", new BytesRef(randomAlphaOfLength(3))));
451471
}
452472
if (randomBoolean()) {
453-
doc.add(new SortedDocValuesField("sdv", new BytesRef(randomAlphaOfLength(3))));
473+
var value = new BytesRef(randomAlphaOfLength(3));
474+
doc.add(indexed ? SortedDocValuesField.indexedField("sdv", value) : new SortedDocValuesField("sdv", value));
454475
}
455476
int numValues = random().nextInt(5);
456477
for (int i = 0; i < numValues; ++i) {
457-
doc.add(new SortedSetDocValuesField("ssdv", new BytesRef(randomAlphaOfLength(3))));
478+
var value = new BytesRef(randomAlphaOfLength(3));
479+
doc.add(indexed ? SortedSetDocValuesField.indexedField("ssdv", value) : new SortedSetDocValuesField("ssdv", value));
458480
}
459481
numValues = random().nextInt(5);
460482
for (int i = 0; i < numValues; ++i) {
461-
doc.add(new SortedNumericDocValuesField("sndv", random().nextInt(1024)));
483+
int value = random().nextInt(1024);
484+
doc.add(indexed ? SortedNumericDocValuesField.indexedField("sndv", value) : new SortedNumericDocValuesField("sndv", value));
462485
}
463486
}
464487

@@ -535,7 +558,7 @@ private static float[] randomVector(int dimension) {
535558

536559
static void addRandomFields(Document doc) {
537560
if (randomBoolean()) {
538-
addRandomDocValuesField(doc);
561+
addRandomDocValuesField(doc, false);
539562
}
540563
if (randomBoolean()) {
541564
addRandomPostings(doc);

0 commit comments

Comments
 (0)