Skip to content

Commit cf83c37

Browse files
authored
Include doc value skippers in disk usage analyzer (#123692)
1 parent 9f10766 commit cf83c37

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ 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+
}
295+
case RANGE -> {
296+
var skipper = docValuesReader.getSkipper(field);
297+
while (skipper.maxDocID(0) != DocIdSetIterator.NO_MORE_DOCS) {
298+
skipper.advance(skipper.maxDocID(skipper.numLevels() - 1) + 1);
299+
}
300+
}
301+
default -> throw new IllegalStateException("Unknown skipper type [" + field.docValuesSkipIndexType() + "]");
302+
}
292303
stats.addDocValues(field.name, directory.getBytesRead());
293304
}
294305
}

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,21 @@ public void testMixedFields() throws Exception {
405405
}
406406
}
407407

408+
public void testDocValuesFieldWithDocValueSkippers() throws Exception {
409+
try (Directory dir = createNewDirectory()) {
410+
var codecMode = randomFrom(CodecMode.values());
411+
indexRandomly(dir, codecMode, between(100, 1000), doc -> addRandomDocValuesField(doc, true));
412+
final IndexDiskUsageStats stats = IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(dir), () -> {});
413+
logger.info("--> stats {}", stats);
414+
try (Directory perFieldDir = createNewDirectory()) {
415+
rewriteIndexWithPerFieldCodec(dir, codecMode, perFieldDir);
416+
final IndexDiskUsageStats perFieldStats = collectPerFieldStats(perFieldDir);
417+
assertStats(stats, perFieldStats);
418+
assertStats(IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(perFieldDir), () -> {}), perFieldStats);
419+
}
420+
}
421+
}
422+
408423
private static void addFieldsToDoc(Document doc, IndexableField[] fields) {
409424
for (IndexableField field : fields) {
410425
doc.add(field);
@@ -442,23 +457,27 @@ static void indexRandomly(Directory directory, CodecMode codecMode, int numDocs,
442457
}
443458
}
444459

445-
static void addRandomDocValuesField(Document doc) {
460+
static void addRandomDocValuesField(Document doc, boolean indexed) {
446461
if (randomBoolean()) {
447-
doc.add(new NumericDocValuesField("ndv", random().nextInt(1024)));
462+
int val = random().nextInt(1024);
463+
doc.add(indexed ? NumericDocValuesField.indexedField("ndv", val) : new NumericDocValuesField("ndv", val));
448464
}
449-
if (randomBoolean()) {
465+
if (randomBoolean() && indexed == false) {
450466
doc.add(new BinaryDocValuesField("bdv", new BytesRef(randomAlphaOfLength(3))));
451467
}
452468
if (randomBoolean()) {
453-
doc.add(new SortedDocValuesField("sdv", new BytesRef(randomAlphaOfLength(3))));
469+
var value = new BytesRef(randomAlphaOfLength(3));
470+
doc.add(indexed ? SortedDocValuesField.indexedField("sdv", value) : new SortedDocValuesField("sdv", value));
454471
}
455472
int numValues = random().nextInt(5);
456473
for (int i = 0; i < numValues; ++i) {
457-
doc.add(new SortedSetDocValuesField("ssdv", new BytesRef(randomAlphaOfLength(3))));
474+
var value = new BytesRef(randomAlphaOfLength(3));
475+
doc.add(indexed ? SortedSetDocValuesField.indexedField("ssdv", value) : new SortedSetDocValuesField("ssdv", value));
458476
}
459477
numValues = random().nextInt(5);
460478
for (int i = 0; i < numValues; ++i) {
461-
doc.add(new SortedNumericDocValuesField("sndv", random().nextInt(1024)));
479+
int value = random().nextInt(1024);
480+
doc.add(indexed ? SortedNumericDocValuesField.indexedField("sndv", value) : new SortedNumericDocValuesField("sndv", value));
462481
}
463482
}
464483

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

536555
static void addRandomFields(Document doc) {
537556
if (randomBoolean()) {
538-
addRandomDocValuesField(doc);
557+
addRandomDocValuesField(doc, false);
539558
}
540559
if (randomBoolean()) {
541560
addRandomPostings(doc);

0 commit comments

Comments
 (0)