Skip to content

Commit 1acda2d

Browse files
committed
Rely on codec to pass down default lucene postings format
Change PerFieldFormatSupplier to get default postings from current codec being used. This way the default codec for standard index mode isn't tied to Lucene101PostingsFormat specifically. And rename the feature flag that controls when stock Lucene posting format is used. Addressed comment from #126080
1 parent ccc3121 commit 1acda2d

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

server/src/main/java/org/elasticsearch/index/codec/LegacyPerFieldMapperCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class LegacyPerFieldMapperCodec extends Lucene101Codec {
2828

2929
public LegacyPerFieldMapperCodec(Lucene101Codec.Mode compressionMode, MapperService mapperService, BigArrays bigArrays) {
3030
super(compressionMode);
31-
this.formatSupplier = new PerFieldFormatSupplier(mapperService, bigArrays);
31+
this.formatSupplier = new PerFieldFormatSupplier(mapperService, bigArrays, super.postingsFormat());
3232
// If the below assertion fails, it is a sign that Lucene released a new codec. You must create a copy of the current Elasticsearch
3333
// codec that delegates to this new Lucene codec, and make PerFieldMapperCodec extend this new Elasticsearch codec.
3434
assert Codec.forName(Lucene.LATEST_CODEC).getClass() == getClass().getSuperclass()

server/src/main/java/org/elasticsearch/index/codec/PerFieldFormatSupplier.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.lucene.codecs.DocValuesFormat;
1313
import org.apache.lucene.codecs.KnnVectorsFormat;
1414
import org.apache.lucene.codecs.PostingsFormat;
15-
import org.apache.lucene.codecs.lucene101.Lucene101PostingsFormat;
1615
import org.apache.lucene.codecs.lucene90.Lucene90DocValuesFormat;
1716
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat;
1817
import org.elasticsearch.common.util.BigArrays;
@@ -34,32 +33,32 @@
3433
* vectors.
3534
*/
3635
public class PerFieldFormatSupplier {
37-
public static final FeatureFlag USE_LUCENE101_POSTINGS_FORMAT = new FeatureFlag("use_lucene101_postings_format");
36+
public static final FeatureFlag USE_DEFAULT_LUCENE_POSTINGS_FORMAT = new FeatureFlag("use_default_lucene_postings_format");
3837

3938
private static final DocValuesFormat docValuesFormat = new Lucene90DocValuesFormat();
4039
private static final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
4140
private static final ES819TSDBDocValuesFormat tsdbDocValuesFormat = new ES819TSDBDocValuesFormat();
4241
private static final ES812PostingsFormat es812PostingsFormat = new ES812PostingsFormat();
43-
private static final Lucene101PostingsFormat lucene101PostingsFormat = new Lucene101PostingsFormat();
4442
private static final PostingsFormat completionPostingsFormat = PostingsFormat.forName("Completion101");
4543

4644
private final ES87BloomFilterPostingsFormat bloomFilterPostingsFormat;
4745
private final MapperService mapperService;
4846

4947
private final PostingsFormat defaultPostingsFormat;
5048

51-
public PerFieldFormatSupplier(MapperService mapperService, BigArrays bigArrays) {
49+
public PerFieldFormatSupplier(MapperService mapperService, BigArrays bigArrays, PostingsFormat defaultPostingsFormat) {
5250
this.mapperService = mapperService;
5351
this.bloomFilterPostingsFormat = new ES87BloomFilterPostingsFormat(bigArrays, this::internalGetPostingsFormatForField);
5452

5553
if (mapperService != null
56-
&& USE_LUCENE101_POSTINGS_FORMAT.isEnabled()
54+
&& USE_DEFAULT_LUCENE_POSTINGS_FORMAT.isEnabled()
5755
&& mapperService.getIndexSettings().getIndexVersionCreated().onOrAfter(IndexVersions.USE_LUCENE101_POSTINGS_FORMAT)
5856
&& mapperService.getIndexSettings().getMode() == IndexMode.STANDARD) {
59-
defaultPostingsFormat = lucene101PostingsFormat;
57+
assert defaultPostingsFormat.getName().startsWith("Lucene") : "defaultPostingsFormat must be a Lucene codec";
58+
this.defaultPostingsFormat = defaultPostingsFormat;
6059
} else {
6160
// our own posting format using PFOR
62-
defaultPostingsFormat = es812PostingsFormat;
61+
this.defaultPostingsFormat = es812PostingsFormat;
6362
}
6463
}
6564

server/src/main/java/org/elasticsearch/index/codec/PerFieldMapperCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class PerFieldMapperCodec extends Elasticsearch900Lucene101Codec {
3232

3333
public PerFieldMapperCodec(Zstd814StoredFieldsFormat.Mode compressionMode, MapperService mapperService, BigArrays bigArrays) {
3434
super(compressionMode);
35-
this.formatSupplier = new PerFieldFormatSupplier(mapperService, bigArrays);
35+
this.formatSupplier = new PerFieldFormatSupplier(mapperService, bigArrays, this.delegate().postingsFormat());
3636
// If the below assertion fails, it is a sign that Lucene released a new codec. You must create a copy of the current Elasticsearch
3737
// codec that delegates to this new Lucene codec, and make PerFieldMapperCodec extend this new Elasticsearch codec.
3838
assert Codec.forName(Lucene.LATEST_CODEC).getClass() == delegate.getClass()

server/src/test/java/org/elasticsearch/index/codec/PerFieldMapperCodecTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void testUseBloomFilter() throws IOException {
9494
assertThat(perFieldMapperCodec.getPostingsFormatForField("_id"), instanceOf(ES87BloomFilterPostingsFormat.class));
9595
assertThat(perFieldMapperCodec.useBloomFilter("another_field"), is(false));
9696

97-
Class<? extends PostingsFormat> expectedPostingsFormat = PerFieldFormatSupplier.USE_LUCENE101_POSTINGS_FORMAT.isEnabled()
97+
Class<? extends PostingsFormat> expectedPostingsFormat = PerFieldFormatSupplier.USE_DEFAULT_LUCENE_POSTINGS_FORMAT.isEnabled()
9898
&& timeSeries == false ? Lucene101PostingsFormat.class : ES812PostingsFormat.class;
9999
assertThat(perFieldMapperCodec.getPostingsFormatForField("another_field"), instanceOf(expectedPostingsFormat));
100100
}
@@ -110,7 +110,7 @@ public void testUseBloomFilterWithTimestampFieldEnabled() throws IOException {
110110
public void testUseBloomFilterWithTimestampFieldEnabled_noTimeSeriesMode() throws IOException {
111111
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, false, false);
112112
assertThat(perFieldMapperCodec.useBloomFilter("_id"), is(false));
113-
Class<? extends PostingsFormat> expectedPostingsFormat = PerFieldFormatSupplier.USE_LUCENE101_POSTINGS_FORMAT.isEnabled()
113+
Class<? extends PostingsFormat> expectedPostingsFormat = PerFieldFormatSupplier.USE_DEFAULT_LUCENE_POSTINGS_FORMAT.isEnabled()
114114
? Lucene101PostingsFormat.class
115115
: ES812PostingsFormat.class;
116116
assertThat(perFieldMapperCodec.getPostingsFormatForField("_id"), instanceOf(expectedPostingsFormat));
@@ -174,7 +174,7 @@ private PerFieldFormatSupplier createFormatSupplier(boolean timestampField, bool
174174
""";
175175
mapperService.merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
176176
}
177-
return new PerFieldFormatSupplier(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
177+
return new PerFieldFormatSupplier(mapperService, BigArrays.NON_RECYCLING_INSTANCE, new Lucene101PostingsFormat());
178178
}
179179

180180
public void testUseES87TSDBEncodingSettingDisabled() throws IOException {
@@ -214,7 +214,7 @@ private PerFieldFormatSupplier createFormatSupplier(boolean enableES87TSDBCodec,
214214
settings.put(IndexSettings.TIME_SERIES_ES87TSDB_CODEC_ENABLED_SETTING.getKey(), enableES87TSDBCodec);
215215
MapperService mapperService = MapperTestUtils.newMapperService(xContentRegistry(), createTempDir(), settings.build(), "test");
216216
mapperService.merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
217-
return new PerFieldFormatSupplier(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
217+
return new PerFieldFormatSupplier(mapperService, BigArrays.NON_RECYCLING_INSTANCE, new Lucene101PostingsFormat());
218218
}
219219

220220
}

0 commit comments

Comments
 (0)