Skip to content

Commit 929d79a

Browse files
authored
Fix DocValuesConsumerUtil (#126836)
The compatibleWithOptimizedMerge() method doesn't handle codec readers that are wrapped by our source pruning filter codec reader. This change addresses that. Failing to detect this means that the optimized merge will not kick in.
1 parent add0f24 commit 929d79a

File tree

3 files changed

+82
-53
lines changed

3 files changed

+82
-53
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.index.codec;
11+
12+
import org.apache.lucene.codecs.DocValuesProducer;
13+
import org.apache.lucene.index.BinaryDocValues;
14+
import org.apache.lucene.index.DocValuesSkipper;
15+
import org.apache.lucene.index.FieldInfo;
16+
import org.apache.lucene.index.NumericDocValues;
17+
import org.apache.lucene.index.SortedDocValues;
18+
import org.apache.lucene.index.SortedNumericDocValues;
19+
import org.apache.lucene.index.SortedSetDocValues;
20+
21+
import java.io.IOException;
22+
23+
/**
24+
* Implementation that allows wrapping another {@link DocValuesProducer} and alter behaviour of the wrapped instance.
25+
*/
26+
public abstract class FilterDocValuesProducer extends DocValuesProducer {
27+
private final DocValuesProducer in;
28+
29+
protected FilterDocValuesProducer(DocValuesProducer in) {
30+
this.in = in;
31+
}
32+
33+
@Override
34+
public NumericDocValues getNumeric(FieldInfo field) throws IOException {
35+
return in.getNumeric(field);
36+
}
37+
38+
@Override
39+
public BinaryDocValues getBinary(FieldInfo field) throws IOException {
40+
return in.getBinary(field);
41+
}
42+
43+
@Override
44+
public SortedDocValues getSorted(FieldInfo field) throws IOException {
45+
return in.getSorted(field);
46+
}
47+
48+
@Override
49+
public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException {
50+
return in.getSortedNumeric(field);
51+
}
52+
53+
@Override
54+
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {
55+
return in.getSortedSet(field);
56+
}
57+
58+
@Override
59+
public DocValuesSkipper getSkipper(FieldInfo field) throws IOException {
60+
return in.getSkipper(field);
61+
}
62+
63+
@Override
64+
public void checkIntegrity() throws IOException {
65+
in.checkIntegrity();
66+
}
67+
68+
@Override
69+
public void close() throws IOException {
70+
in.close();
71+
}
72+
73+
public DocValuesProducer getIn() {
74+
return in;
75+
}
76+
}

server/src/main/java/org/elasticsearch/index/codec/tsdb/es819/DocValuesConsumerUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.lucene.codecs.DocValuesProducer;
1313
import org.apache.lucene.index.FieldInfo;
1414
import org.apache.lucene.index.MergeState;
15+
import org.elasticsearch.index.codec.FilterDocValuesProducer;
1516
import org.elasticsearch.index.codec.perfield.XPerFieldDocValuesFormat;
1617

1718
/**
@@ -40,6 +41,10 @@ static MergeStats compatibleWithOptimizedMerge(boolean optimizedMergeEnabled, Me
4041

4142
for (int i = 0; i < mergeState.docValuesProducers.length; i++) {
4243
DocValuesProducer docValuesProducer = mergeState.docValuesProducers[i];
44+
if (docValuesProducer instanceof FilterDocValuesProducer filterDocValuesProducer) {
45+
docValuesProducer = filterDocValuesProducer.getIn();
46+
}
47+
4348
if (docValuesProducer instanceof XPerFieldDocValuesFormat.FieldsReader perFieldReader) {
4449
var wrapped = perFieldReader.getDocValuesProducer(fieldInfo);
4550
if (wrapped instanceof ES819TSDBDocValuesProducer tsdbDocValuesProducer) {

server/src/main/java/org/elasticsearch/index/engine/RecoverySourcePruneMergePolicy.java

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@
1111

1212
import org.apache.lucene.codecs.DocValuesProducer;
1313
import org.apache.lucene.codecs.StoredFieldsReader;
14-
import org.apache.lucene.index.BinaryDocValues;
1514
import org.apache.lucene.index.CodecReader;
16-
import org.apache.lucene.index.DocValuesSkipper;
1715
import org.apache.lucene.index.FieldInfo;
1816
import org.apache.lucene.index.FilterCodecReader;
1917
import org.apache.lucene.index.FilterNumericDocValues;
2018
import org.apache.lucene.index.MergePolicy;
2119
import org.apache.lucene.index.NumericDocValues;
2220
import org.apache.lucene.index.OneMergeWrappingMergePolicy;
23-
import org.apache.lucene.index.SortedDocValues;
24-
import org.apache.lucene.index.SortedNumericDocValues;
25-
import org.apache.lucene.index.SortedSetDocValues;
2621
import org.apache.lucene.index.StoredFieldVisitor;
2722
import org.apache.lucene.search.ConjunctionUtils;
2823
import org.apache.lucene.search.DocIdSetIterator;
@@ -34,6 +29,7 @@
3429
import org.apache.lucene.util.BitSet;
3530
import org.apache.lucene.util.BitSetIterator;
3631
import org.elasticsearch.core.Nullable;
32+
import org.elasticsearch.index.codec.FilterDocValuesProducer;
3733
import org.elasticsearch.index.mapper.IdFieldMapper;
3834
import org.elasticsearch.search.internal.FilterStoredFieldVisitor;
3935

@@ -177,54 +173,6 @@ public CacheHelper getReaderCacheHelper() {
177173
return null;
178174
}
179175

180-
private static class FilterDocValuesProducer extends DocValuesProducer {
181-
private final DocValuesProducer in;
182-
183-
FilterDocValuesProducer(DocValuesProducer in) {
184-
this.in = in;
185-
}
186-
187-
@Override
188-
public NumericDocValues getNumeric(FieldInfo field) throws IOException {
189-
return in.getNumeric(field);
190-
}
191-
192-
@Override
193-
public BinaryDocValues getBinary(FieldInfo field) throws IOException {
194-
return in.getBinary(field);
195-
}
196-
197-
@Override
198-
public SortedDocValues getSorted(FieldInfo field) throws IOException {
199-
return in.getSorted(field);
200-
}
201-
202-
@Override
203-
public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException {
204-
return in.getSortedNumeric(field);
205-
}
206-
207-
@Override
208-
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {
209-
return in.getSortedSet(field);
210-
}
211-
212-
@Override
213-
public DocValuesSkipper getSkipper(FieldInfo field) throws IOException {
214-
return in.getSkipper(field);
215-
}
216-
217-
@Override
218-
public void checkIntegrity() throws IOException {
219-
in.checkIntegrity();
220-
}
221-
222-
@Override
223-
public void close() throws IOException {
224-
in.close();
225-
}
226-
}
227-
228176
private abstract static class FilterStoredFieldsReader extends StoredFieldsReader {
229177

230178
protected final StoredFieldsReader in;

0 commit comments

Comments
 (0)